UPnPsdk 0.1
Universal Plug and Play +, Software Development Kit
 
Loading...
Searching...
No Matches
anonymous_namespace{ThreadPool.cpp} Namespace Reference

Functions

Scope restricted to file
long DiffMillis (timeval *time1, timeval *time2)
 Returns the difference in milliseconds between two timeval structures.
 
void StatsInit (ThreadPoolStats *stats)
 Initializes the statistics structure.
 
void StatsAccountLQ (ThreadPool *tp, long diffTime)
 StatsAccountLQ.
 
void StatsAccountMQ (ThreadPool *tp, long diffTime)
 StatsAccountMQ.
 
void StatsAccountHQ (ThreadPool *tp, long diffTime)
 StatsAccountHQ.
 
void CalcWaitTime (ThreadPool *tp, ThreadPriority p, ThreadPoolJob *job)
 Calculates the time the job has been waiting at the specified priority.
 
time_t StatsTime (time_t *t)
 StatsTime.
 
int CmpThreadPoolJob (void *jobA, void *jobB)
 Compares thread pool jobs.
 
void FreeThreadPoolJob (ThreadPool *tp, ThreadPoolJob *tpj)
 Deallocates a dynamically allocated ThreadPoolJob.
 
int SetPolicyType (PolicyType in)
 Sets the scheduling policy of the current process.
 
int SetPriority (ThreadPriority priority)
 Sets the priority of the currently running thread.
 
void BumpPriority (ThreadPool *tp)
 Determines whether any jobs need to be bumped to a higher priority Q and bumps them.
 
void SetRelTimeout (timespec *time, int relMillis)
 Sets the fields of the passed in timespec to be relMillis milliseconds in the future.
 
void SetSeed (void)
 Sets seed for random number generator.
 
void * WorkerThread (void *arg)
 Implements a thread pool worker.
 
ThreadPoolJobCreateThreadPoolJob (ThreadPoolJob *job, int id, ThreadPool *tp)
 Creates a Thread Pool Job. (Dynamically allocated)
 
int CreateWorker (ThreadPool *tp)
 Creates a worker thread, if the thread pool does not already have max threads.
 
void AddWorker (ThreadPool *tp)
 Determines whether or not a thread should be added based on the jobsPerThread ratio.
 

Function Documentation

◆ DiffMillis()

long anonymous_namespace{ThreadPool.cpp}::DiffMillis ( timeval *  time1,
timeval *  time2 
)

Returns the difference in milliseconds between two timeval structures.

Returns
The difference in milliseconds, time1-time2.

Definition at line 75 of file ThreadPool.cpp.

+ Here is the caller graph for this function:

◆ StatsInit()

void anonymous_namespace{ThreadPool.cpp}::StatsInit ( ThreadPoolStats stats)

Initializes the statistics structure.

Parameters
statsValid non null stats structure.

Definition at line 93 of file ThreadPool.cpp.

+ Here is the caller graph for this function:

◆ StatsAccountLQ()

void anonymous_namespace{ThreadPool.cpp}::StatsAccountLQ ( ThreadPool tp,
long  diffTime 
)

StatsAccountLQ.

Parameters
[in]tpValid, non null, pointer to ThreadPool.
diffTime.

Definition at line 118 of file ThreadPool.cpp.

+ Here is the caller graph for this function:

◆ StatsAccountMQ()

void anonymous_namespace{ThreadPool.cpp}::StatsAccountMQ ( ThreadPool tp,
long  diffTime 
)

StatsAccountMQ.

Parameters
[in]tpValid, non null, pointer to ThreadPool.
diffTime.

Definition at line 130 of file ThreadPool.cpp.

+ Here is the caller graph for this function:

◆ StatsAccountHQ()

void anonymous_namespace{ThreadPool.cpp}::StatsAccountHQ ( ThreadPool tp,
long  diffTime 
)

StatsAccountHQ.

Parameters
[in]tpValid, non null, pointer to ThreadPool.
diffTime.

Definition at line 142 of file ThreadPool.cpp.

+ Here is the caller graph for this function:

◆ CalcWaitTime()

void anonymous_namespace{ThreadPool.cpp}::CalcWaitTime ( ThreadPool tp,
ThreadPriority  p,
ThreadPoolJob job 
)

Calculates the time the job has been waiting at the specified priority.

Adds to the totalTime and totalJobs kept in the thread pool statistics structure.

Parameters
[in]tpValid, non null, pointer to ThreadPool.
[in]pThread priority.
[in]jobValid thread pool job.

Definition at line 158 of file ThreadPool.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ StatsTime()

time_t anonymous_namespace{ThreadPool.cpp}::StatsTime ( time_t *  t)

StatsTime.

Parameters
t.

Definition at line 191 of file ThreadPool.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ CmpThreadPoolJob()

int anonymous_namespace{ThreadPool.cpp}::CmpThreadPoolJob ( void *  jobA,
void *  jobB 
)

Compares thread pool jobs.

Definition at line 215 of file ThreadPool.cpp.

+ Here is the caller graph for this function:

◆ FreeThreadPoolJob()

void anonymous_namespace{ThreadPool.cpp}::FreeThreadPoolJob ( ThreadPool tp,
ThreadPoolJob tpj 
)

Deallocates a dynamically allocated ThreadPoolJob.

Parameters
[in]tpValid, non null, pointer to ThreadPool.
[in]tpjMust be allocated with CreateThreadPoolJob.

Definition at line 225 of file ThreadPool.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ SetPolicyType()

int anonymous_namespace{ThreadPool.cpp}::SetPolicyType ( PolicyType  in)

Sets the scheduling policy of the current process.

Returns
On success: 0
On error: result of GetLastError() on failure.
Parameters
in.

Definition at line 240 of file ThreadPool.cpp.

+ Here is the caller graph for this function:

◆ SetPriority()

int anonymous_namespace{ThreadPool.cpp}::SetPriority ( ThreadPriority  priority)

Sets the priority of the currently running thread.

Returns
On success: 0
On error: EINVAL invalid priority or the result of GerLastError.
Parameters
[in]priorityThread priority

Definition at line 276 of file ThreadPool.cpp.

+ Here is the caller graph for this function:

◆ BumpPriority()

void anonymous_namespace{ThreadPool.cpp}::BumpPriority ( ThreadPool tp)

Determines whether any jobs need to be bumped to a higher priority Q and bumps them.

tp->mutex must be locked.

Parameters
[in]tpValid, non null, pointer to ThreadPool.

Definition at line 327 of file ThreadPool.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ SetRelTimeout()

void anonymous_namespace{ThreadPool.cpp}::SetRelTimeout ( timespec *  time,
int  relMillis 
)

Sets the fields of the passed in timespec to be relMillis milliseconds in the future.

Parameters
time.
relMillismilliseconds in the future.

Definition at line 369 of file ThreadPool.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ SetSeed()

void anonymous_namespace{ThreadPool.cpp}::SetSeed ( void  )

Sets seed for random number generator.

Each thread sets the seed random number generator.

Todo:
Solve problem with type casts.

Definition at line 390 of file ThreadPool.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ WorkerThread()

void * anonymous_namespace{ThreadPool.cpp}::WorkerThread ( void *  arg)

Implements a thread pool worker.

Worker waits for a job to become available. Worker picks up persistent jobs first, high priority, med priority, then low priority. If worker remains idle for more than specified max, the worker is released.

Parameters
argarg -> is cast to (ThreadPool *).

Definition at line 423 of file ThreadPool.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ CreateThreadPoolJob()

ThreadPoolJob * anonymous_namespace{ThreadPool.cpp}::CreateThreadPoolJob ( ThreadPoolJob job,
int  id,
ThreadPool tp 
)

Creates a Thread Pool Job. (Dynamically allocated)

Returns
On success: Pointer to a ThreadPoolJob
On error: nullptr
Parameters
jobjob is copied.
idid of job.
[in]tpValid, non null, pointer to ThreadPool.

Definition at line 571 of file ThreadPool.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ CreateWorker()

int anonymous_namespace{ThreadPool.cpp}::CreateWorker ( ThreadPool tp)

Creates a worker thread, if the thread pool does not already have max threads.

Remarks
The ThreadPool object mutex must be locked prior to calling this function.
Returns
On success: 0
On error: **< 0**
  • EMAXTHREADS if already max threads reached.
  • EAGAIN if system can not create thread.
Parameters
[in]tpValid, non null, pointer to ThreadPool.

Definition at line 603 of file ThreadPool.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ AddWorker()

void anonymous_namespace{ThreadPool.cpp}::AddWorker ( ThreadPool tp)

Determines whether or not a thread should be added based on the jobsPerThread ratio.

Adds a thread if appropriate.

Remarks
The ThreadPool object mutex must be locked prior to calling this function.
Parameters
[in]tpValid, non null, pointer to ThreadPool.

Definition at line 648 of file ThreadPool.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function: