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:
Marcelo Roberto Jimenez
2007-12-17 10:39:57 +00:00
parent 9bfac585af
commit e156038d5c
3 changed files with 963 additions and 1017 deletions

View File

@@ -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.

View File

@@ -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;
/**************************************************************************** /****************************************************************************
@@ -155,8 +155,6 @@ typedef struct THREADPOOLJOB
* Structure to hold statistics * Structure to hold statistics
*****************************************************************************/ *****************************************************************************/
#ifdef STATS
typedef struct TPOOLSTATS typedef struct TPOOLSTATS
{ {
double totalTimeHQ; double totalTimeHQ;
@@ -178,9 +176,7 @@ typedef struct TPOOLSTATS
int currentJobsHQ; int currentJobsHQ;
int currentJobsLQ; int currentJobsLQ;
int currentJobsMQ; int currentJobsMQ;
}ThreadPoolStats; } ThreadPoolStats;
#endif
/**************************************************************************** /****************************************************************************
@@ -221,11 +217,8 @@ typedef struct THREADPOOL
ThreadPoolAttr attr; /* thread pool attributes */ ThreadPoolAttr attr; /* thread pool attributes */
#ifdef STATS
/* statistics */ /* statistics */
ThreadPoolStats stats; ThreadPoolStats stats;
#endif
} 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