Removed STATSONLY() macro from ThreadPool.{c,h}.
Removed time() usage from ThreadPool.c. Fixed STATS = 0 compilation. git-svn-id: https://pupnp.svn.sourceforge.net/svnroot/pupnp/trunk@271 119443c7-1b9e-41f8-b6fc-b9c35fce742c
This commit is contained in:
@@ -2,6 +2,11 @@
|
|||||||
Version 1.6.3
|
Version 1.6.3
|
||||||
*******************************************************************************
|
*******************************************************************************
|
||||||
|
|
||||||
|
2007-12-17 Marcelo Jimenez <mroberto(at)users.sourceforge.net>
|
||||||
|
* Removed STATSONLY() macro from ThreadPool.{c,h}.
|
||||||
|
* Removed time() usage from ThreadPool.c.
|
||||||
|
* Fixed STATS = 0 compilation.
|
||||||
|
|
||||||
2007-12-16 Marcelo Jimenez <mroberto(at)users.sourceforge.net>
|
2007-12-16 Marcelo Jimenez <mroberto(at)users.sourceforge.net>
|
||||||
* Library was not compiling on FreeBSD 7. Code now no longer uses
|
* Library was not compiling on FreeBSD 7. Code now no longer uses
|
||||||
ftime(), using gettimeofday() instead. Thanks to Josh Carroll.
|
ftime(), using gettimeofday() instead. Thanks to Josh Carroll.
|
||||||
|
@@ -32,6 +32,12 @@
|
|||||||
#ifndef THREADPOOL_H
|
#ifndef THREADPOOL_H
|
||||||
#define THREADPOOL_H
|
#define THREADPOOL_H
|
||||||
|
|
||||||
|
#ifdef UPNP_USE_MSVCPP
|
||||||
|
#define UPNP_INLINE
|
||||||
|
#else
|
||||||
|
#define UPNP_INLINE inline
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
@@ -64,19 +70,9 @@ typedef enum priority {LOW_PRIORITY,
|
|||||||
#define DEFAULT_FREE_ROUTINE NULL /* default free routine used TPJobInit */
|
#define DEFAULT_FREE_ROUTINE NULL /* default free routine used TPJobInit */
|
||||||
#define DEFAULT_MAX_JOBS_TOTAL 100 /* default max jobs used TPAttrInit */
|
#define DEFAULT_MAX_JOBS_TOTAL 100 /* default max jobs used TPAttrInit */
|
||||||
|
|
||||||
#define STATS 1 /* always include stats because code change is minimal */
|
|
||||||
|
|
||||||
|
|
||||||
/* Statistics */
|
/* Statistics */
|
||||||
#ifdef WIN32 /* TODO: check why STATSONLY fails during compilation */
|
/* always include stats because code change is minimal */
|
||||||
#undef STATS
|
#define STATS 1
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef STATS
|
|
||||||
#define STATSONLY(x) x
|
|
||||||
#else
|
|
||||||
#define STATSONLY(x)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
#define DEBUG 1
|
#define DEBUG 1
|
||||||
@@ -88,7 +84,9 @@ typedef enum priority {LOW_PRIORITY,
|
|||||||
|
|
||||||
#include "ithread.h"
|
#include "ithread.h"
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
#define EXPORT
|
#define EXPORT
|
||||||
|
|
||||||
typedef int PolicyType;
|
typedef int PolicyType;
|
||||||
#define DEFAULT_POLICY SCHED_OTHER
|
#define DEFAULT_POLICY SCHED_OTHER
|
||||||
#define DEFAULT_SCHED_PARAM 0 /* default priority */
|
#define DEFAULT_SCHED_PARAM 0 /* default priority */
|
||||||
@@ -110,26 +108,28 @@ typedef void (*free_routine)(void *arg);
|
|||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
typedef struct THREADPOOLATTR
|
typedef struct THREADPOOLATTR
|
||||||
{
|
{
|
||||||
int minThreads; /* minThreads, ThreadPool will always maintain at least
|
/* minThreads, ThreadPool will always maintain at least this many threads */
|
||||||
this many threads */
|
int minThreads;
|
||||||
|
|
||||||
int maxThreads; /* maxThreads, ThreadPool will never have more than this
|
/* maxThreads, ThreadPool will never have more than this number of threads */
|
||||||
number of threads */
|
int maxThreads;
|
||||||
|
|
||||||
int maxIdleTime; /* maxIdleTime (in milliseconds)
|
/* maxIdleTime (in milliseconds) this is the maximum time a thread will
|
||||||
this is the maximum time a thread will remain idle
|
* remain idle before dying */
|
||||||
before dying */
|
int maxIdleTime;
|
||||||
|
|
||||||
int jobsPerThread; /* jobs per thread to maintain */
|
/* jobs per thread to maintain */
|
||||||
|
int jobsPerThread;
|
||||||
|
|
||||||
int maxJobsTotal; /* maximum number of jobs that can be queued totally. */
|
/* maximum number of jobs that can be queued totally. */
|
||||||
|
int maxJobsTotal;
|
||||||
|
|
||||||
int starvationTime; /* the time a low priority or med priority
|
/* the time a low priority or med priority job waits before getting bumped
|
||||||
job waits before getting bumped
|
* up a priority (in milliseconds) */
|
||||||
up a priority (in milliseconds) */
|
int starvationTime;
|
||||||
|
|
||||||
PolicyType schedPolicy; /* scheduling policy to use */
|
|
||||||
|
|
||||||
|
/* scheduling policy to use */
|
||||||
|
PolicyType schedPolicy;
|
||||||
} ThreadPoolAttr;
|
} ThreadPoolAttr;
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
@@ -140,12 +140,12 @@ typedef struct THREADPOOLATTR
|
|||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
typedef struct THREADPOOLJOB
|
typedef struct THREADPOOLJOB
|
||||||
{
|
{
|
||||||
start_routine func;
|
start_routine func;
|
||||||
void *arg;
|
void *arg;
|
||||||
free_routine free_func;
|
free_routine free_func;
|
||||||
struct timeval requestTime;
|
struct timeval requestTime;
|
||||||
int priority;
|
int priority;
|
||||||
int jobId;
|
int jobId;
|
||||||
} ThreadPoolJob;
|
} ThreadPoolJob;
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
@@ -155,32 +155,28 @@ typedef struct THREADPOOLJOB
|
|||||||
* Structure to hold statistics
|
* Structure to hold statistics
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
|
|
||||||
#ifdef STATS
|
|
||||||
|
|
||||||
typedef struct TPOOLSTATS
|
typedef struct TPOOLSTATS
|
||||||
{
|
{
|
||||||
double totalTimeHQ;
|
double totalTimeHQ;
|
||||||
int totalJobsHQ;
|
int totalJobsHQ;
|
||||||
double avgWaitHQ;
|
double avgWaitHQ;
|
||||||
double totalTimeMQ;
|
double totalTimeMQ;
|
||||||
int totalJobsMQ;
|
int totalJobsMQ;
|
||||||
double avgWaitMQ;
|
double avgWaitMQ;
|
||||||
double totalTimeLQ;
|
double totalTimeLQ;
|
||||||
int totalJobsLQ;
|
int totalJobsLQ;
|
||||||
double avgWaitLQ;
|
double avgWaitLQ;
|
||||||
double totalWorkTime;
|
double totalWorkTime;
|
||||||
double totalIdleTime;
|
double totalIdleTime;
|
||||||
int workerThreads;
|
int workerThreads;
|
||||||
int idleThreads;
|
int idleThreads;
|
||||||
int persistentThreads;
|
int persistentThreads;
|
||||||
int totalThreads;
|
int totalThreads;
|
||||||
int maxThreads;
|
int maxThreads;
|
||||||
int currentJobsHQ;
|
int currentJobsHQ;
|
||||||
int currentJobsLQ;
|
int currentJobsLQ;
|
||||||
int currentJobsMQ;
|
int currentJobsMQ;
|
||||||
}ThreadPoolStats;
|
} ThreadPoolStats;
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
@@ -205,27 +201,24 @@ typedef struct TPOOLSTATS
|
|||||||
|
|
||||||
typedef struct THREADPOOL
|
typedef struct THREADPOOL
|
||||||
{
|
{
|
||||||
ithread_mutex_t mutex; /* mutex to protect job qs */
|
ithread_mutex_t mutex; /* mutex to protect job qs */
|
||||||
ithread_cond_t condition; /* condition variable to signal Q */
|
ithread_cond_t condition; /* condition variable to signal Q */
|
||||||
ithread_cond_t start_and_shutdown; /* condition variable for start
|
ithread_cond_t start_and_shutdown; /* condition variable for start
|
||||||
and stop */
|
and stop */
|
||||||
int lastJobId; /* ids for jobs */
|
int lastJobId; /* ids for jobs */
|
||||||
int shutdown; /* whether or not we are shutting down */
|
int shutdown; /* whether or not we are shutting down */
|
||||||
int totalThreads; /* total number of threads */
|
int totalThreads; /* total number of threads */
|
||||||
int persistentThreads; /* number of persistent threads */
|
int persistentThreads; /* number of persistent threads */
|
||||||
FreeList jobFreeList; /* free list of jobs */
|
FreeList jobFreeList; /* free list of jobs */
|
||||||
LinkedList lowJobQ; /* low priority job Q */
|
LinkedList lowJobQ; /* low priority job Q */
|
||||||
LinkedList medJobQ; /* med priority job Q */
|
LinkedList medJobQ; /* med priority job Q */
|
||||||
LinkedList highJobQ; /* high priority job Q */
|
LinkedList highJobQ; /* high priority job Q */
|
||||||
ThreadPoolJob *persistentJob; /* persistent job */
|
ThreadPoolJob *persistentJob; /* persistent job */
|
||||||
|
|
||||||
ThreadPoolAttr attr; /* thread pool attributes */
|
ThreadPoolAttr attr; /* thread pool attributes */
|
||||||
|
|
||||||
#ifdef STATS
|
|
||||||
/* statistics */
|
|
||||||
ThreadPoolStats stats;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
/* statistics */
|
||||||
|
ThreadPoolStats stats;
|
||||||
} ThreadPool;
|
} ThreadPool;
|
||||||
|
|
||||||
|
|
||||||
@@ -266,8 +259,7 @@ typedef struct THREADPOOL
|
|||||||
* INVALID_POLICY if schedPolicy can't be set
|
* INVALID_POLICY if schedPolicy can't be set
|
||||||
* EMAXTHREADS if minimum threads is greater than maximum threads
|
* EMAXTHREADS if minimum threads is greater than maximum threads
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
int ThreadPoolInit(ThreadPool *tp,
|
int ThreadPoolInit(ThreadPool *tp, ThreadPoolAttr *attr);
|
||||||
ThreadPoolAttr *attr);
|
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Function: ThreadPoolAddPersistent
|
* Function: ThreadPoolAddPersistent
|
||||||
@@ -289,9 +281,7 @@ int ThreadPoolInit(ThreadPool *tp,
|
|||||||
* EOUTOFMEM not enough memory to add job.
|
* EOUTOFMEM not enough memory to add job.
|
||||||
* EMAXTHREADS not enough threads to add persistent job.
|
* EMAXTHREADS not enough threads to add persistent job.
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
int ThreadPoolAddPersistent (ThreadPool*tp,
|
int ThreadPoolAddPersistent(ThreadPool*tp, ThreadPoolJob *job, int *jobId);
|
||||||
ThreadPoolJob *job,
|
|
||||||
int *jobId);
|
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Function: ThreadPoolGetAttr
|
* Function: ThreadPoolGetAttr
|
||||||
@@ -306,8 +296,7 @@ int ThreadPoolAddPersistent (ThreadPool*tp,
|
|||||||
* 0 on success, nonzero on failure
|
* 0 on success, nonzero on failure
|
||||||
* Always returns 0.
|
* Always returns 0.
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
int ThreadPoolGetAttr(ThreadPool *tp,
|
int ThreadPoolGetAttr(ThreadPool *tp, ThreadPoolAttr *out);
|
||||||
ThreadPoolAttr *out);
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Function: ThreadPoolSetAttr
|
* Function: ThreadPoolSetAttr
|
||||||
*
|
*
|
||||||
@@ -321,8 +310,7 @@ int ThreadPoolGetAttr(ThreadPool *tp,
|
|||||||
* 0 on success, nonzero on failure
|
* 0 on success, nonzero on failure
|
||||||
* Returns INVALID_POLICY if policy can not be set.
|
* Returns INVALID_POLICY if policy can not be set.
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
int ThreadPoolSetAttr(ThreadPool *tp,
|
int ThreadPoolSetAttr(ThreadPool *tp, ThreadPoolAttr *attr);
|
||||||
ThreadPoolAttr *attr);
|
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Function: ThreadPoolAdd
|
* Function: ThreadPoolAdd
|
||||||
@@ -341,9 +329,7 @@ int ThreadPoolSetAttr(ThreadPool *tp,
|
|||||||
* 0 on success, nonzero on failure
|
* 0 on success, nonzero on failure
|
||||||
* EOUTOFMEM if not enough memory to add job.
|
* EOUTOFMEM if not enough memory to add job.
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
int ThreadPoolAdd (ThreadPool*tp,
|
int ThreadPoolAdd (ThreadPool*tp, ThreadPoolJob *job, int *jobId);
|
||||||
ThreadPoolJob *job,
|
|
||||||
int *jobId);
|
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Function: ThreadPoolRemove
|
* Function: ThreadPoolRemove
|
||||||
@@ -360,8 +346,7 @@ int ThreadPoolAdd (ThreadPool*tp,
|
|||||||
* 0 on success, nonzero on failure.
|
* 0 on success, nonzero on failure.
|
||||||
* INVALID_JOB_ID if job not found.
|
* INVALID_JOB_ID if job not found.
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
int ThreadPoolRemove(ThreadPool *tp,
|
int ThreadPoolRemove(ThreadPool *tp, int jobId, ThreadPoolJob *out);
|
||||||
int jobId, ThreadPoolJob *out);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -424,7 +409,6 @@ int TPJobSetPriority(ThreadPoolJob *job, ThreadPriority priority);
|
|||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
int TPJobSetFreeFunction(ThreadPoolJob *job, free_routine func);
|
int TPJobSetFreeFunction(ThreadPoolJob *job, free_routine func);
|
||||||
|
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Function: TPAttrInit
|
* Function: TPAttrInit
|
||||||
*
|
*
|
||||||
|
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user