Overview
The RoseMeshJobMgr class is a subclass of RoseMeshThreadMonitor that manages background worker tasks and assigns jobs to a pool of threads for executation. The lifecycle of a job is a follows:
- Instance of a RoseMeshJob subtype is created.
- Job is added to the job manager by the submit() function.
- Job waits in a queue
- Job is executed by calling its run() function.
- Job is moved to the completed queue in the job manager.
- Higher level code calls getCompleted() to examine completed jobs.
cancel()
void cancel();
The cancel() function signals all running and queued jobs to cancel themselves. This does not actually kill the jobs, but rather causes isCanceled() to return true, which the workers should poll.
getCompleted()
RoseMeshJob * getCompleted( int wait=0 );
The getCompleted() function returns a completed job. A job is completed when its run() function returns. If there are no completed jobs and wait parameter is 0 (false), this function return null. If the wait parameter is non-zero, and there are jobs running this function waits until a job is completed. If there are no completed jobs and no running jobs, this function return null.
getMaxThreadCount()
unsigned getMaxThreadCount();
The getMaxThreadCount() function returns the maximum number of worker threads that will be created by the job manager. See getThreadCount() for current number of threads that have been created
getProcessorCount()
static unsigned getProcessorCount();
The getProcessorCount function returns the number of virtual processors available on your system. This is a static function on the class and provides a simple and portable way to find this information.
getShutdownOnDtor()
int getShutdownOnDtor()
The getShutdownOnDtor() function returns a flag indicating whether the manager should shut down jobs when it is destroyed. This might be set to false if the application is exiting and the threads will be killed via a different mechanism.
getThreadCount()
unsigned getThreadCount();
The getThreadCount() function returns the current number of worker threads being used by the job manager. Not all threads may be active — some may be blocked waiting for jobs.
hasRunningJobs()
int hasRunningJobs();
The hasRunningJobs() function returns non-zero if any jobs are currently running, zero otherwise.
isCanceled()
int isCanceled();
The isCanceled() function return non-zero (true) if a request has been made to cancel all running jobs. This should be periodically polled by the workers as part of the RoseMeshJob::run() function, which should then abort the work if this function returns true.
raisePriority()
void raisePriority( RoseMeshJob * job );
The raisePriority() function increases the priority of the given job, so that it will be run before jobs that have not had their priority raised.
remove()
void remove( RoseMeshJob * job );
The remove() function removes the given job from the run queue.
resetCancel()
void resetCancel();
The resetCancel() function re-enables the queue manager after the cancel() function has been called.
setMaxThreadCount()
void setMaxThreadCount( unsigned c );
The setMaxThreadCount() function sets the maximum number of worker threads that the job manager will create. This defaults to the value returned by getProcessorCount().
setShutdownOnDtor()
void setShutdownOnDtor(int v)
The setShutdownOnDtor() function changes the value returned by getShutdownOnDtor().
shutdown()
void shutdown();
The shutdown() function causes idle threads to exit rather than waiting for additional jobs to be submitted. This can be used to signal to the job manager that no further jobs will be submitted, so the unneeded worker threads can be terminated.
submit()
void submit(RoseMeshJob * job);
The submit() function is used to add a job to the queue of jobs to be run. The job will then be executed at some time after it has been submitted.
wait()
void wait( RoseMeshJob * job );
The wait() function waits until the given job has completed.