
#include <Util/WorkThreadServer.H>
Inheritance diagram for WorkThreadServer:


To use this class, derive a job class from JobServer::Job whose run() function does the work that you want done. Then instantiate a WorkThreadServer object, start() it with your desired number of work threads, and start calling enqueueJob() with your Job objects. See DiskDataStream for an example of usage.
Definition at line 60 of file WorkThreadServer.H.
Public Types | |
| enum | DropPolicy { DROP_OLDEST, DROP_NEWEST, DROP_OLDEST_LOWEST_PRIORITY, DROP_NEWEST_LOWEST_PRIORITY } |
Public Member Functions | |
| WorkThreadServer (const char *name, unsigned int n) | |
| Construct with a descriptive nameand a number of worker threads. | |
| virtual | ~WorkThreadServer () |
| Virtual destructor for safe inheritance. | |
| virtual void | enqueueJob (const rutz::shared_ptr< Job > &job) |
| Put a Job in the queue. | |
| virtual void | enqueueJobs (const rutz::shared_ptr< Job > *jobs, const size_t njobs) |
| Submit multiple jobs in a batch. | |
| virtual unsigned int | getParallelismHint () |
| Returns the number of worker threads. | |
| void | flushQueue (uint sleepLength=250000, bool verbose=true) |
| Wait now for all jobs in the queue to be completed. | |
| size_t | size () |
| Get the number of jobs currently waiting in the queue. | |
| void | setCheckpointPeriod (int p) |
| How often (in number of jobs) should a checkpoint log entry be written. | |
| void | setSleepUsecs (unsigned int us) |
| Number of microseconds to usleep() in between running each job. | |
| void | setMaxQueueSize (size_t maxsize) |
| Change the maximum size for the internal queue. | |
| void | setFlushBeforeStopping (bool v) |
| Whether to wait for the job queue to become empty before stopping the worker threads. | |
| void | setSortJobs (bool v) |
| Whether to sort jobs by priority. | |
| void | setDropPolicy (DropPolicy p) |
| Specify the policy to be used to drop jobs to avoid exceeding the maximum queue size. | |
Classes | |
| struct | Checkpoint |
| struct | JobStats |
| struct | ThreadData |
|
|
Definition at line 120 of file WorkThreadServer.H. |
|
||||||||||||
|
Construct with a descriptive nameand a number of worker threads.
Definition at line 99 of file WorkThreadServer.C. References rutz::mutex_atomic_int::atomic_set(), itsName, and LFATAL. |
|
|
Virtual destructor for safe inheritance.
Definition at line 130 of file WorkThreadServer.C. References LERROR. |
|
|
Put a Job in the queue. Worker threads process Job requests in the order they are received. Implements JobServer. Definition at line 311 of file WorkThreadServer.C. References ASSERT, GVX_MUTEX_LOCK, and LFATAL. Referenced by workthread_job_server(), and DiskDataStream::writeFrame(). |
|
||||||||||||
|
Submit multiple jobs in a batch. This is more efficient than multiple individual enqueueJob() calls, since we can lock/unlock the queue mutex just once for the entire batch. Reimplemented from JobServer. Definition at line 330 of file WorkThreadServer.C. References ASSERT, GVX_MUTEX_LOCK, i, and LFATAL. |
|
||||||||||||
|
Wait now for all jobs in the queue to be completed.
Definition at line 358 of file WorkThreadServer.C. |
|
|
Returns the number of worker threads.
Implements JobServer. Definition at line 352 of file WorkThreadServer.C. |
|
|
How often (in number of jobs) should a checkpoint log entry be written. If <= 0, then never print checkpoint entries. Definition at line 100 of file WorkThreadServer.H. Referenced by DiskDataStream::start2(). |
|
|
Specify the policy to be used to drop jobs to avoid exceeding the maximum queue size.
Definition at line 129 of file WorkThreadServer.H. |
|
|
Whether to wait for the job queue to become empty before stopping the worker threads. If false (the default), then any jobs left in the queue will be abandoned when stop() or the destructor is called. Definition at line 115 of file WorkThreadServer.H. |
|
|
Change the maximum size for the internal queue. If an enqueueJob() or enqueueJobs() call would otherwise cause the maximum queue size to be exceeded, then jobs will be dropped from the queue in accordance with the current drop policy. Definition at line 385 of file WorkThreadServer.C. References GVX_MUTEX_LOCK, and LFATAL. |
|
|
Number of microseconds to usleep() in between running each job. If <= 0, then don't usleep() at all. Definition at line 104 of file WorkThreadServer.H. Referenced by DiskDataStream::start2(). |
|
|
Whether to sort jobs by priority.
Definition at line 118 of file WorkThreadServer.H. |
|
|
Get the number of jobs currently waiting in the queue.
Definition at line 374 of file WorkThreadServer.C. References GVX_MUTEX_LOCK. Referenced by flushQueue(), and DiskDataStream::stop1(). |
1.4.4