Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | Friends

Threads::WorkManager Class Reference

is the top manager of everything. Give the tasks to it and it will be performed in time. Note that no notification is done when the task is done. It's up to the user of the class to implement such things in the ThreadTask. More...

Inheritance diagram for Threads::WorkManager:
CallBacker

List of all members.

Public Types

enum  QueueType { MultiThread, SingleThread, Manual }

Public Member Functions

 WorkManager (int nrthreads=-1)
 ~WorkManager ()
int addQueue (QueueType type)
int queueSize (int queueid) const
void removeQueue (int queueid, bool finishall)
void executeQueue (int queueid)
void addWork (SequentialTask *, CallBack *finished, int queueid, bool putfirstinline, bool manage)
 Managed by caller if manage flag is false.
bool addWork (ObjectSet< SequentialTask > &, bool firstinline=false)
bool removeWork (const SequentialTask *)
const SequentialTaskgetWork (CallBacker *) const
int nrThreads () const

Static Public Member Functions

static int cDefaultQueueID ()
static Threads::WorkManagertwm ()

Public Attributes

Notifier< WorkManagerisidle

Protected Member Functions

int queueSizeNoLock (int queueid) const
int reportFinishedAndAskForMore (WorkThread *, int oldqueueid)

Protected Attributes

ObjectSet< SequentialTaskworkload_
TypeSet< int > workqueueid_
ObjectSet< CallBackcallbacks_
BoolTypeSet isowner_
ObjectSet< WorkThread > threads_
ObjectSet< WorkThread > freethreads_
TypeSet< int > queueids_
TypeSet< int > queueworkload_
TypeSet< QueueTypequeuetypes_
BoolTypeSet queueisclosing_
ConditionVarworkloadcond_
int freeid_

Friends

class WorkThread

Detailed Description

is the top manager of everything. Give the tasks to it and it will be performed in time. Note that no notification is done when the task is done. It's up to the user of the class to implement such things in the ThreadTask.

The object can handle multiple queues. This is mostly intersting when you want to ensure that a shared resource is always accessed single threaded, but without using syncronization.


Member Enumeration Documentation

Enumerator:
MultiThread 
SingleThread 
Manual 

Constructor & Destructor Documentation

Threads::WorkManager::WorkManager ( int  nrthreads = -1  ) 
Threads::WorkManager::~WorkManager (  ) 

Member Function Documentation

int Threads::WorkManager::addQueue ( QueueType  type  ) 

Manual queues will not be executed automaticall, only at executeQueue.

Returns:
queid
void Threads::WorkManager::addWork ( SequentialTask ,
CallBack finished,
int  queueid,
bool  putfirstinline,
bool  manage 
)

Managed by caller if manage flag is false.

bool Threads::WorkManager::addWork ( ObjectSet< SequentialTask > &  ,
bool  firstinline = false 
)
static int Threads::WorkManager::cDefaultQueueID (  )  [inline, static]
void Threads::WorkManager::executeQueue ( int  queueid  ) 

Runs all jobs in a que. Only for manual queues

const SequentialTask* Threads::WorkManager::getWork ( CallBacker  )  const
int Threads::WorkManager::nrThreads (  )  const [inline]

When a work is sumbmitted with a callback, the callback is called with a callbacker. If called from the callback and the callbacker is non-zero, a pointer to the work that was completed is returned. If not possible, a zero pointer will be returned.

int Threads::WorkManager::queueSize ( int  queueid  )  const
int Threads::WorkManager::queueSizeNoLock ( int  queueid  )  const [protected]
void Threads::WorkManager::removeQueue ( int  queueid,
bool  finishall 
)

Removes queue. If finishall is true, all work in the queue will be finished.

bool Threads::WorkManager::removeWork ( const SequentialTask  ) 

Removes the task from queue and stop it if allready running. If task is managed, it will be deleted.

Returns:
true if the task was removed before it had started.
int Threads::WorkManager::reportFinishedAndAskForMore ( WorkThread *  ,
int  oldqueueid 
) [protected]
static Threads::WorkManager& Threads::WorkManager::twm (  )  [static]

Friends And Related Function Documentation

friend class WorkThread [friend]

Member Data Documentation

ObjectSet<WorkThread> Threads::WorkManager::threads_ [protected]