1#ifndef COMPA_THREADPOOL_HPP
2#define COMPA_THREADPOOL_HPP
49#if defined(_WIN32) || defined(DOXYGEN_RUN)
50#if !defined(_TIMEZONE_DEFINED) || defined(DOXYGEN_RUN)
68#define INVALID_JOB_ID (-2 & 1 << 29)
123#define DEFAULT_POLICY SCHED_OTHER
151 UPnPsdk::start_routine func;
154 struct timeval requestTime;
170 double totalWorkTime;
171 double totalIdleTime;
174 int persistentThreads;
381 UPnPsdk::start_routine func,
537#if defined(STATS) || defined(DOXYGEN_RUN)
556#if defined(STATS) || defined(DOXYGEN_RUN)
Stores head and size of free list, as well as mutex for protection.
Manage a linked list (for internal use only).
Linked list (no protection).
int minThreads
ThreadPool will always maintain at least this many threads.
int ThreadPoolInit(ThreadPool *tp, ThreadPoolAttr *attr)
Initializes and starts ThreadPool.
int ThreadPoolAdd(ThreadPool *tp, ThreadPoolJob *job, int *jobId)
Adds a job to the thread pool.
constexpr free_routine DEFAULT_FREE_ROUTINE
int TPJobSetFreeFunction(ThreadPoolJob *job, free_routine func)
Sets the jobs free function.
int ThreadPoolShutdown(ThreadPool *tp)
Shuts the thread pool down.
constexpr int DEFAULT_STACK_SIZE
int ThreadPoolGetAttr(ThreadPool *tp, ThreadPoolAttr *out)
Gets the current set of attributes associated with the thread pool.
void ThreadPoolPrintStats(ThreadPoolStats *stats)
Prints various statistics about the thread pool to stderr.
constexpr int DEFAULT_JOBS_PER_THREAD
int tz_minuteswest
Minutes W of Greenwich.
constexpr int DEFAULT_STARVATION_TIME
constexpr ThreadPriority DEFAULT_PRIORITY
int maxIdleTime
this is the maximum time a thread will remain idle before dying (in milliseconds).
constexpr int DEFAULT_IDLE_TIME
constexpr int DEFAULT_MAX_JOBS_TOTAL
int maxJobsTotal
Maximum number of jobs that can be queued totally.
int TPAttrSetMaxJobsTotal(ThreadPoolAttr *attr, int totalMaxJobs)
Sets the maximum number jobs that can be qeued totally.
constexpr int DEFAULT_MAX_THREADS
int TPAttrSetStarvationTime(ThreadPoolAttr *attr, int starvationTime)
Sets the starvation time for the thread pool attributes.
PolicyType schedPolicy
Scheduling policy to use.
int TPAttrSetMaxThreads(ThreadPoolAttr *attr, int maxThreads)
Sets the max threads for the thread pool attributes.
int TPJobSetPriority(ThreadPoolJob *job, ThreadPriority priority)
Sets the priority of the threadpool job.
ThreadPoolJob * persistentJob
int starvationTime
The time a low priority or med priority job waits before getting bumped up a priority (in millisecond...
int ThreadPoolSetAttr(ThreadPool *tp, ThreadPoolAttr *attr)
Sets the attributes for the thread pool.
int ThreadPoolRemove(ThreadPool *tp, int jobId, ThreadPoolJob *out)
Removes a job from the thread pool.
int tz_dsttime
Type of dst correction.
int ThreadPoolGetStats(ThreadPool *tp, ThreadPoolStats *stats)
Returns various statistics about the thread pool.
int TPAttrSetJobsPerThread(ThreadPoolAttr *attr, int jobsPerThread)
Sets the jobs per thread ratio.
pthread_cond_t start_and_shutdown
int gettimeofday(struct timeval *tv, struct timezone *tz)
Get time of day.
int TPJobInit(ThreadPoolJob *job, UPnPsdk::start_routine func, void *arg)
Initializes thread pool job.
int jobsPerThread
Jobs per thread to maintain.
int PolicyType
Type of the thread policy.
ThreadPriority
Thread priority.
int TPAttrInit(ThreadPoolAttr *attr)
Initializes thread pool attributes.
void TPSetMaxJobsTotal(int mjt)
Sets the maximum number of jobs in the thread pool.
int pendingWorkerThreadStart
int TPAttrSetIdleTime(ThreadPoolAttr *attr, int idleTime)
Sets the idle time for the thread pool attributes.
int TPAttrSetMinThreads(ThreadPoolAttr *attr, int minThreads)
Sets the min threads for the thread pool attributes.
int TPAttrSetSchedPolicy(ThreadPoolAttr *attr, PolicyType schedPolicy)
Sets the scheduling policy for the thread pool attributes.
void(* free_routine)(void *arg)
int TPAttrSetStackSize(ThreadPoolAttr *attr, size_t stackSize)
Sets the stack size for the thread pool attributes.
int ThreadPoolAddPersistent(ThreadPool *tp, ThreadPoolJob *job, int *jobId)
Adds a persistent job to the thread pool.
size_t stackSize
This is the minimum stack size allocated for each thread.
int maxThreads
ThreadPool will never have more than this number of threads.
constexpr int DEFAULT_MIN_THREADS
Structure to hold statistics.
Attributes for thread pool.
Specifications to be portable with sockets between different platforms.