51 #ifndef _TIMEZONE_DEFINED
58 int gettimeofday(
struct timeval *tv,
struct timezone *tz);
60 #include <sys/param.h>
62 #if defined(__APPLE__) || defined(__NetBSD__)
63 #include <sys/resource.h>
72 #define JOBFREELISTSIZE 100
74 #define INFINITE_THREADS -1
76 #define EMAXTHREADS (-8 & 1 << 29)
79 #define INVALID_POLICY (-9 & 1 << 29)
82 #define INVALID_JOB_ID (-2 & 1 << 29)
98 #define DEFAULT_PRIORITY MED_PRIORITY
101 #define DEFAULT_MIN_THREADS 1
104 #define DEFAULT_MAX_THREADS 10
107 #define DEFAULT_STACK_SIZE 0u
110 #define DEFAULT_JOBS_PER_THREAD 10
113 #define DEFAULT_STARVATION_TIME 500
116 #define DEFAULT_IDLE_TIME 10 * 1000
119 #define DEFAULT_FREE_ROUTINE NULL
122 #define DEFAULT_MAX_JOBS_TOTAL 100
123 extern int maxJobsTotal;
136 typedef int PolicyType;
138 #define DEFAULT_POLICY SCHED_OTHER
173 struct timeval requestTime;
174 ThreadPriority priority;
190 double totalWorkTime;
191 double totalIdleTime;
194 int persistentThreads;
398 ThreadPriority priority);
496 PolicyType schedPolicy);
int ThreadPoolInit(ThreadPool *tp, ThreadPoolAttr *attr)
Initializes and starts ThreadPool. Must be called first and only once for ThreadPool.
Definition: ThreadPool.c:710
int ThreadPoolAdd(ThreadPool *tp, ThreadPoolJob *job, int *jobId)
Adds a job to the thread pool. Job will be run as soon as possible.
Definition: ThreadPool.c:826
struct THREADPOOL ThreadPool
A thread pool similar to the thread pool in the UPnP SDK.
int TPJobSetFreeFunction(ThreadPoolJob *job, free_routine func)
Sets the max threads for the thread pool attributes.
Definition: ThreadPool.c:1117
int ThreadPoolShutdown(ThreadPool *tp)
Shuts the thread pool down. Waits for all threads to finish. May block indefinitely if jobs do not ex...
Definition: ThreadPool.c:990
int ThreadPoolGetAttr(ThreadPool *tp, ThreadPoolAttr *out)
Gets the current set of attributes associated with the thread pool.
Definition: ThreadPool.c:936
int TPAttrSetMaxJobsTotal(ThreadPoolAttr *attr, int maxJobsTotal)
Sets the maximum number jobs that can be qeued totally.
Definition: ThreadPool.c:1189
int TPJobInit(ThreadPoolJob *job, start_routine func, void *arg)
Initializes thread pool job. Sets the priority to default defined in ThreadPool.h....
Definition: ThreadPool.c:1090
UPNP_EXPORT_SPEC void ThreadPoolPrintStats(ThreadPoolStats *stats)
Definition: ThreadPool.c:1199
int TPAttrSetStarvationTime(ThreadPoolAttr *attr, int starvationTime)
Sets the starvation time for the thread pool attributes.
Definition: ThreadPool.c:1171
int TPAttrSetMaxThreads(ThreadPoolAttr *attr, int maxThreads)
Sets the max threads for the thread pool attributes.
Definition: ThreadPool.c:1126
int TPJobSetPriority(ThreadPoolJob *job, ThreadPriority priority)
Sets the max threads for the thread pool attributes.
Definition: ThreadPool.c:1102
struct TPOOLSTATS ThreadPoolStats
int ThreadPoolSetAttr(ThreadPool *tp, ThreadPoolAttr *attr)
Sets the attributes for the thread pool. Only affects future calculations.
Definition: ThreadPool.c:949
int ThreadPoolRemove(ThreadPool *tp, int jobId, ThreadPoolJob *out)
Removes a job from the thread pool. Can only remove jobs which are not currently running.
Definition: ThreadPool.c:879
struct THREADPOOLATTR ThreadPoolAttr
int TPAttrSetJobsPerThread(ThreadPoolAttr *attr, int jobsPerThread)
Sets the jobs per thread ratio.
Definition: ThreadPool.c:1162
struct THREADPOOLJOB ThreadPoolJob
int TPAttrInit(ThreadPoolAttr *attr)
Initializes thread pool attributes. Sets values to defaults defined in ThreadPool....
Definition: ThreadPool.c:1074
void TPSetMaxJobsTotal(int mjt)
Sets the maximum number of jobs in the thread pool. This option is intended for server applications t...
Definition: ThreadPool.c:1072
int TPAttrSetIdleTime(ThreadPoolAttr *attr, int idleTime)
Sets the idle time for the thread pool attributes.
Definition: ThreadPool.c:1153
int TPAttrSetMinThreads(ThreadPoolAttr *attr, int minThreads)
Sets the min threads for the thread pool attributes.
Definition: ThreadPool.c:1135
int TPAttrSetSchedPolicy(ThreadPoolAttr *attr, PolicyType schedPolicy)
Sets the scheduling policy for the thread pool attributes.
Definition: ThreadPool.c:1180
void(* free_routine)(void *arg)
Definition: ThreadPool.h:141
int TPAttrSetStackSize(ThreadPoolAttr *attr, size_t stackSize)
Sets the stack size for the thread pool attributes.
Definition: ThreadPool.c:1144
int ThreadPoolAddPersistent(ThreadPool *tp, ThreadPoolJob *job, int *jobId)
Adds a persistent job to the thread pool.
Definition: ThreadPool.c:778
UPNP_EXPORT_SPEC int ThreadPoolGetStats(ThreadPool *tp, ThreadPoolStats *stats)
Returns various statistics about the thread pool.
Definition: ThreadPool.c:1235
Defines constants that for some reason are not defined on some systems.
#define UPNP_EXPORT_SPEC
Export functions on WIN32 DLLs.
Definition: UpnpGlobal.h:105
#define UPNP_INLINE
Declares an inline function.
Definition: UpnpGlobal.h:119
Provides a platform independent way to include TCP/IP types and functions.
Definition: FreeList.h:62
Definition: LinkedList.h:84
Definition: ThreadPool.h:146
int maxJobsTotal
Definition: ThreadPool.h:159
PolicyType schedPolicy
Definition: ThreadPool.h:164
int maxThreads
Definition: ThreadPool.h:150
int jobsPerThread
Definition: ThreadPool.h:157
int maxIdleTime
Definition: ThreadPool.h:155
int minThreads
Definition: ThreadPool.h:148
size_t stackSize
Definition: ThreadPool.h:152
int starvationTime
Definition: ThreadPool.h:162
Definition: ThreadPool.h:169
A thread pool similar to the thread pool in the UPnP SDK.
Definition: ThreadPool.h:218
int lastJobId
Definition: ThreadPool.h:226
int pendingWorkerThreadStart
Definition: ThreadPool.h:232
int busyThreads
Definition: ThreadPool.h:234
LinkedList lowJobQ
Definition: ThreadPool.h:240
ithread_mutex_t mutex
Definition: ThreadPool.h:220
ThreadPoolAttr attr
Definition: ThreadPool.h:248
int persistentThreads
Definition: ThreadPool.h:236
int totalThreads
Definition: ThreadPool.h:230
LinkedList medJobQ
Definition: ThreadPool.h:242
int shutdown
Definition: ThreadPool.h:228
LinkedList highJobQ
Definition: ThreadPool.h:244
ThreadPoolStats stats
Definition: ThreadPool.h:250
FreeList jobFreeList
Definition: ThreadPool.h:238
ithread_cond_t condition
Definition: ThreadPool.h:222
ThreadPoolJob * persistentJob
Definition: ThreadPool.h:246
ithread_cond_t start_and_shutdown
Definition: ThreadPool.h:224
Definition: ThreadPool.h:180