* Removing the Dbg_Level, InitLog, SetLogFileNames and CloseLog

defines. These were just aliases, no reason to keep them.
* Changed the comments of the include files that expose the UPnP API
to use only C89 comments and no C99 comments.



git-svn-id: https://pupnp.svn.sourceforge.net/svnroot/pupnp/trunk@198 119443c7-1b9e-41f8-b6fc-b9c35fce742c
This commit is contained in:
Marcelo Roberto Jimenez
2007-05-25 15:02:12 +00:00
parent 80517f26a6
commit 9bc187d4c6
17 changed files with 711 additions and 713 deletions

View File

@@ -1,33 +1,33 @@
///////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2000-2003 Intel Corporation
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
// * Neither name of Intel Corporation nor the names of its contributors
// may be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
///////////////////////////////////////////////////////////////////////////
/*******************************************************************************
*
* Copyright (c) 2000-2003 Intel Corporation
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* * Neither name of Intel Corporation nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
******************************************************************************/
#ifndef THREADPOOL_H
#define THREADPOOL_H
@@ -36,17 +36,17 @@
extern "C" {
#endif
//Size of job free list
/* Size of job free list */
#define JOBFREELISTSIZE 100
#define INFINITE_THREADS -1
#define EMAXTHREADS (-8 & 1<<29)
//Invalid Policy
/* Invalid Policy */
#define INVALID_POLICY (-9 & 1<<29)
//Invalid JOB Id
/* Invalid JOB Id */
#define INVALID_JOB_ID (-2 & 1<<29)
typedef enum duration {SHORT_TERM,PERSISTENT} Duration;
@@ -55,27 +55,27 @@ typedef enum priority {LOW_PRIORITY,
MED_PRIORITY,
HIGH_PRIORITY} ThreadPriority;
#define DEFAULT_PRIORITY MED_PRIORITY //default priority used by TPJobInit
#define DEFAULT_MIN_THREADS 1 //default minimum used by TPAttrInit
#define DEFAULT_MAX_THREADS 10 //default max used by TPAttrInit
#define DEFAULT_JOBS_PER_THREAD 10 //default jobs per thread used by TPAttrInit
#define DEFAULT_STARVATION_TIME 500 //default starvation time used by TPAttrInit
#define DEFAULT_IDLE_TIME 10 * 1000 //default idle time used by TPAttrInit
#define DEFAULT_FREE_ROUTINE NULL //default free routine used TPJobInit
#define DEFAULT_MAX_JOBS_TOTAL 100 //default max jobs used TPAttrInit
#define DEFAULT_PRIORITY MED_PRIORITY /* default priority used by TPJobInit */
#define DEFAULT_MIN_THREADS 1 /* default minimum used by TPAttrInit */
#define DEFAULT_MAX_THREADS 10 /* default max used by TPAttrInit */
#define DEFAULT_JOBS_PER_THREAD 10 /* default jobs per thread used by TPAttrInit */
#define DEFAULT_STARVATION_TIME 500 /* default starvation time used by TPAttrInit */
#define DEFAULT_IDLE_TIME 10 * 1000 /* default idle time used by TPAttrInit */
#define DEFAULT_FREE_ROUTINE NULL /* default free routine used TPJobInit */
#define DEFAULT_MAX_JOBS_TOTAL 100 /* default max jobs used TPAttrInit */
#define STATS 1 //always include stats because code change is minimal
#define STATS 1 /* always include stats because code change is minimal */
//Statistics
#ifdef WIN32 // todo: check why STATSONLY fails during compilation
#undef STATS
/* Statistics */
#ifdef WIN32 /* TODO: check why STATSONLY fails during compilation */
#undef STATS
#endif
#ifdef STATS
#define STATSONLY(x) x
#define STATSONLY(x) x
#else
#define STATSONLY(x)
#define STATSONLY(x)
#endif
#ifdef _DEBUG
@@ -92,7 +92,7 @@ typedef enum priority {LOW_PRIORITY,
#define EXPORT
typedef int PolicyType;
#define DEFAULT_POLICY SCHED_OTHER
#define DEFAULT_SCHED_PARAM 0 //default priority
#define DEFAULT_SCHED_PARAM 0 /* default priority */
/****************************************************************************
* Name: free_routine
@@ -111,25 +111,25 @@ typedef void (*free_routine)(void *arg);
*****************************************************************************/
typedef struct THREADPOOLATTR
{
int minThreads; // minThreads, ThreadPool will always maintain at least
// this many threads
int minThreads; /* minThreads, ThreadPool will always maintain at least
this many threads */
int maxThreads; // maxThreads, ThreadPool will never have more than this
// number of threads
int maxThreads; /* maxThreads, ThreadPool will never have more than this
number of threads */
int maxIdleTime; // maxIdleTime (in milliseconds)
// this is the maximum time a thread will remain idle
// before dying
int maxIdleTime; /* maxIdleTime (in milliseconds)
this is the maximum time a thread will remain idle
before dying */
int jobsPerThread; // jobs per thread to maintain
int jobsPerThread; /* jobs per thread to maintain */
int maxJobsTotal; // maximum number of jobs that can be queued totally.
int maxJobsTotal; /* maximum number of jobs that can be queued totally. */
int starvationTime; // the time a low priority or med priority
// job waits before getting bumped
// up a priority (in milliseconds)
int starvationTime; /* the time a low priority or med priority
job waits before getting bumped
up a priority (in milliseconds) */
PolicyType schedPolicy; // scheduling policy to use
PolicyType schedPolicy; /* scheduling policy to use */
} ThreadPoolAttr;
@@ -141,12 +141,12 @@ typedef struct THREADPOOLATTR
*****************************************************************************/
typedef struct THREADPOOLJOB
{
start_routine func; //function
void *arg; //arg
free_routine free_func; //free function
struct timeb requestTime; //time of request
int priority; //priority of request
int jobId; //id
start_routine func;
void *arg;
free_routine free_func;
struct timeb requestTime;
int priority;
int jobId;
} ThreadPoolJob;
/****************************************************************************
@@ -156,32 +156,32 @@ typedef struct THREADPOOLJOB
* Structure to hold statistics
*****************************************************************************/
STATSONLY(
#ifdef STATS
typedef struct TPOOLSTATS
{
double totalTimeHQ; //total time spent by all jobs in high priority Q
int totalJobsHQ; //total jobs in HQ run so far
double avgWaitHQ; //average wait in HQ
double totalTimeMQ; //total time spent by all jobs in med priority Q
int totalJobsMQ; //total jobs in MQ run so far
double avgWaitMQ; //average wait in MQ
double totalTimeLQ; //total time spent by all jobs in low priority Q
int totalJobsLQ; //total jobs in LQ run so far
double avgWaitLQ; //average wait in LQ
double totalWorkTime; //total time spent working for all threads
double totalIdleTime; //total time spent idle for all threads
int workerThreads; //number of current workerThreads
int idleThreads; //number of current idle threads
int persistentThreads; //number of persistent threads
int totalThreads; //total number of current threads
int maxThreads; //max threads so far
int currentJobsHQ; // current jobs in Q
int currentJobsLQ; //current jobs in Q
int currentJobsMQ; //current jobs in Q
double totalTimeHQ;
int totalJobsHQ;
double avgWaitHQ;
double totalTimeMQ;
int totalJobsMQ;
double avgWaitMQ;
double totalTimeLQ;
int totalJobsLQ;
double avgWaitLQ;
double totalWorkTime;
double totalIdleTime;
int workerThreads;
int idleThreads;
int persistentThreads;
int totalThreads;
int maxThreads;
int currentJobsHQ;
int currentJobsLQ;
int currentJobsMQ;
}ThreadPoolStats;
)
#endif
/****************************************************************************
@@ -206,24 +206,26 @@ typedef struct TPOOLSTATS
typedef struct THREADPOOL
{
ithread_mutex_t mutex; //mutex to protect job qs
ithread_cond_t condition; //condition variable to signal Q
ithread_cond_t start_and_shutdown; //condition variable for start
//and stop
int lastJobId; //ids for jobs
int shutdown; //whether or not we are shutting down
int totalThreads; //total number of threads
int persistentThreads; //number of persistent threads
FreeList jobFreeList; //free list of jobs
LinkedList lowJobQ; //low priority job Q
LinkedList medJobQ; //med priority job Q
LinkedList highJobQ; //high priority job Q
ThreadPoolJob *persistentJob; //persistent job
ithread_mutex_t mutex; /* mutex to protect job qs */
ithread_cond_t condition; /* condition variable to signal Q */
ithread_cond_t start_and_shutdown; /* condition variable for start
and stop */
int lastJobId; /* ids for jobs */
int shutdown; /* whether or not we are shutting down */
int totalThreads; /* total number of threads */
int persistentThreads; /* number of persistent threads */
FreeList jobFreeList; /* free list of jobs */
LinkedList lowJobQ; /* low priority job Q */
LinkedList medJobQ; /* med priority job Q */
LinkedList highJobQ; /* high priority job Q */
ThreadPoolJob *persistentJob; /* persistent job */
ThreadPoolAttr attr; //thread pool attributes
ThreadPoolAttr attr; /* thread pool attributes */
//statistics
STATSONLY(ThreadPoolStats stats;)
#ifdef STATS
/* statistics */
ThreadPoolStats stats;
#endif
} ThreadPool;
@@ -541,12 +543,15 @@ int TPAttrSetMaxJobsTotal(ThreadPoolAttr *attr, int maxJobsTotal);
* Returns:
* Always returns 0.
*****************************************************************************/
STATSONLY( EXPORT int ThreadPoolGetStats(ThreadPool *tp, ThreadPoolStats *stats););
#ifdef STATS
EXPORT int ThreadPoolGetStats(ThreadPool *tp, ThreadPoolStats *stats);
STATSONLY(EXPORT void ThreadPoolPrintStats(ThreadPoolStats *stats););
EXPORT void ThreadPoolPrintStats(ThreadPoolStats *stats);
#endif
#ifdef __cplusplus
}
#endif
#endif //ThreadPool
#endif /* ThreadPool */