OpendTect  6.3
Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | Friends | List of all members
Threads::WorkManager Class Reference

Takes work and puts it on a queue for execution either in parallel, singlethread or manual. More...

Inheritance diagram for Threads::WorkManager:
[legend]

Public Types

enum  QueueType { MultiThread, SingleThread, Manual }
 

Public Member Functions

 WorkManager (int nrthreads=-1)
 
 ~WorkManager ()
 
int addQueue (QueueType type, const char *name)
 
void setQueueName (int queueid, const char *)
 
int queueSize (int queueid) const
 
void emptyQueue (int queueid, bool finishall)
 
void removeQueue (int queueid, bool finishall)
 
bool executeQueue (int queueid)
 
void addWork (const Work &, CallBack *finished=0, int queueid=cDefaultQueueID(), bool putfirstinline=false, bool discardduplicates=false, bool forcedifferentthread=false)
 
bool addWork (TypeSet< Work > &, int queueid=-1, bool firstinline=false)
 
bool executeWork (Work *, int sz, int queueid=-1, bool firstinline=false)
 Returns when finished with all. More...
 
bool removeWork (const Work &)
 
const WorkgetWork (CallBacker *) const
 
bool getWorkExitStatus (CallBacker *) const
 
int nrThreads () const
 
int nrFreeThreads () const
 Valid right now, may change any time. More...
 
bool isWorkThread () const
 
void shutdown ()
 
- Public Member Functions inherited from CallBacker
 CallBacker ()
 
 CallBacker (const CallBacker &)
 
virtual ~CallBacker ()
 
bool attachCB (const NotifierAccess &, const CallBack &, bool onlyifnew=false) const
 
bool attachCB (const NotifierAccess *notif, const CallBack &cb, bool onlyifnew=false) const
 
void detachCB (const NotifierAccess &, const CallBack &) const
 
void detachCB (const NotifierAccess *notif, const CallBack &cb) const
 
bool isNotifierAttached (const NotifierAccess *) const
 Only for debugging purposes, don't use. More...
 
virtual bool isCapsule () const
 
void stopReceivingNotifications () const
 

Static Public Member Functions

static int cDefaultQueueID ()
 
static Threads::WorkManagertwm ()
 
- Static Public Member Functions inherited from CallBacker
static void createReceiverForCurrentThread ()
 
static void removeReceiverForCurrentThread ()
 

Public Attributes

Notifier< WorkManagerisidle
 
Notifier< WorkManagerisShuttingDown
 

Protected Member Functions

int queueSizeNoLock (int queueid) const
 
int reportFinishedAndAskForMore (WorkThread *, int oldqueueid)
 
void reduceWorkload (int queueidx)
 
- Protected Member Functions inherited from CallBacker
void detachAllNotifiers () const
 Call from the destructor of your inherited object. More...
 

Protected Attributes

TypeSet< Workworkload_
 
TypeSet< int > workqueueid_
 
TypeSet< CallBackcallbacks_
 
ObjectSet< WorkThreadthreads_
 
ObjectSet< const void > threadids_
 
ObjectSet< WorkThreadfreethreads_
 
TypeSet< int > queueids_
 
TypeSet< int > queueworkload_
 
TypeSet< QueueTypequeuetypes_
 
BufferStringSet queuenames_
 
BoolTypeSet queueisclosing_
 
ConditionVarworkloadcond_
 
int freeid_
 
const int twmid_
 Only for debugging. More...
 

Friends

class WorkThread
 

Detailed Description

Takes work and puts it on a queue for execution either in parallel, singlethread or manual.

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,
const char *  name 
)

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

Returns
queid
Parameters
nameis for debugging
void Threads::WorkManager::addWork ( const Work ,
CallBack finished = 0,
int  queueid = cDefaultQueueID(),
bool  putfirstinline = false,
bool  discardduplicates = false,
bool  forcedifferentthread = false 
)
Parameters
forcedifferentthreadwill force work to be put on the queue, even if it could be done directly in current thread.
bool Threads::WorkManager::addWork ( TypeSet< Work > &  ,
int  queueid = -1,
bool  firstinline = false 
)

Will wait for all work to be finished.

Returns
true if all Work was completed without error.
static int Threads::WorkManager::cDefaultQueueID ( )
inlinestatic
void Threads::WorkManager::emptyQueue ( int  queueid,
bool  finishall 
)
bool Threads::WorkManager::executeQueue ( int  queueid)

Runs all jobs in a que. Only for manual queues

bool Threads::WorkManager::executeWork ( Work ,
int  sz,
int  queueid = -1,
bool  firstinline = false 
)

Returns when finished with all.

const Work* Threads::WorkManager::getWork ( CallBacker ) const

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.

bool Threads::WorkManager::getWorkExitStatus ( CallBacker ) const

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, the exit status of the work will be returned. Otherwise false.

bool Threads::WorkManager::isWorkThread ( ) const
int Threads::WorkManager::nrFreeThreads ( ) const

Valid right now, may change any time.

int Threads::WorkManager::nrThreads ( ) const
inline
int Threads::WorkManager::queueSize ( int  queueid) const
int Threads::WorkManager::queueSizeNoLock ( int  queueid) const
protected
void Threads::WorkManager::reduceWorkload ( int  queueidx)
inlineprotected
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 Work )

Removes the task from queue and stop it if allready running.

Returns
true if the task was removed before it had started.
int Threads::WorkManager::reportFinishedAndAskForMore ( WorkThread ,
int  oldqueueid 
)
protected
void Threads::WorkManager::setQueueName ( int  queueid,
const char *   
)
void Threads::WorkManager::shutdown ( )
static Threads::WorkManager& Threads::WorkManager::twm ( )
static

Friends And Related Function Documentation

friend class WorkThread
friend

Member Data Documentation

TypeSet<CallBack> Threads::WorkManager::callbacks_
protected
int Threads::WorkManager::freeid_
protected
ObjectSet<WorkThread> Threads::WorkManager::freethreads_
protected
Notifier<WorkManager> Threads::WorkManager::isidle
Notifier<WorkManager> Threads::WorkManager::isShuttingDown
TypeSet<int> Threads::WorkManager::queueids_
protected
BoolTypeSet Threads::WorkManager::queueisclosing_
protected
BufferStringSet Threads::WorkManager::queuenames_
protected
TypeSet<QueueType> Threads::WorkManager::queuetypes_
protected
TypeSet<int> Threads::WorkManager::queueworkload_
protected
ObjectSet<const void> Threads::WorkManager::threadids_
protected
ObjectSet<WorkThread> Threads::WorkManager::threads_
protected
const int Threads::WorkManager::twmid_
protected

Only for debugging.

TypeSet<Work> Threads::WorkManager::workload_
protected
ConditionVar& Threads::WorkManager::workloadcond_
protected
TypeSet<int> Threads::WorkManager::workqueueid_
protected

Generated at for the OpendTect seismic interpretation project. Copyright (C): dGB Beheer B. V. 2017