OpendTect  7.0
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 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)
 
void emptyQueue (int queueid, bool finishall)
 
bool executeQueue (int queueid)
 
bool executeWork (Work *, int sz, int queueid=-1, bool firstinline=false)
 Returns when finished with all. More...
 
const WorkgetWork (CallBacker *) const
 
bool getWorkExitStatus (CallBacker *) const
 
bool isWorkThread () const
 
int nrFreeThreads () const
 Valid right now, may change any time. More...
 
int nrThreads () const
 
int queueSize (int queueid) const
 
void removeQueue (int queueid, bool finishall)
 
bool removeWork (const Work &)
 
void setQueueName (int queueid, const char *)
 
void shutdown ()
 
uiString uiMessage (CallBacker *) const
 
- 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 detachAllNotifiers () const
 Call from the destructor of your inherited object. More...
 
void detachCB (const NotifierAccess &, const CallBack &) const
 
void detachCB (const NotifierAccess *notif, const CallBack &cb) const
 
virtual bool isCapsule () const
 
bool isNotifierAttached (const NotifierAccess *) const
 Only for debugging purposes, don't use. More...
 
void stopReceivingNotifications () const
 
virtual CallBackertrueCaller ()
 

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
 
void reduceWorkload (int queueidx)
 
int reportFinishedAndAskForMore (WorkThread *, int oldqueueid)
 

Protected Attributes

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

Friends

class WorkThread
 

Detailed Description

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

<>

Member Enumeration Documentation

◆ QueueType

Enumerator
MultiThread 
SingleThread 
Manual 

Constructor & Destructor Documentation

◆ WorkManager()

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

◆ ~WorkManager()

Threads::WorkManager::~WorkManager ( )

Member Function Documentation

◆ addQueue()

int Threads::WorkManager::addQueue ( QueueType  type,
const char *  name 
)

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

Returns
queid
Parameters
typeSee QueueType
nameis for debugging

◆ addWork() [1/2]

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.
finished,queueid,putfirstinline,discardduplicates

◆ addWork() [2/2]

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.

◆ cDefaultQueueID()

static int Threads::WorkManager::cDefaultQueueID ( )
inlinestatic

◆ emptyQueue()

void Threads::WorkManager::emptyQueue ( int  queueid,
bool  finishall 
)

◆ executeQueue()

bool Threads::WorkManager::executeQueue ( int  queueid)

Runs all jobs in a que. Only for manual queues

◆ executeWork()

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

Returns when finished with all.

◆ getWork()

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

When a work is submitted 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.

◆ getWorkExitStatus()

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

When a work is submitted 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.

◆ isWorkThread()

bool Threads::WorkManager::isWorkThread ( ) const

◆ nrFreeThreads()

int Threads::WorkManager::nrFreeThreads ( ) const

Valid right now, may change any time.

◆ nrThreads()

int Threads::WorkManager::nrThreads ( ) const
inline

◆ queueSize()

int Threads::WorkManager::queueSize ( int  queueid) const

◆ queueSizeNoLock()

int Threads::WorkManager::queueSizeNoLock ( int  queueid) const
protected

◆ reduceWorkload()

void Threads::WorkManager::reduceWorkload ( int  queueidx)
inlineprotected

◆ removeQueue()

void Threads::WorkManager::removeQueue ( int  queueid,
bool  finishall 
)

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

◆ removeWork()

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.

◆ reportFinishedAndAskForMore()

int Threads::WorkManager::reportFinishedAndAskForMore ( WorkThread ,
int  oldqueueid 
)
protected

◆ setQueueName()

void Threads::WorkManager::setQueueName ( int  queueid,
const char *   
)

◆ shutdown()

void Threads::WorkManager::shutdown ( )

◆ twm()

static Threads::WorkManager& Threads::WorkManager::twm ( )
static

◆ uiMessage()

uiString Threads::WorkManager::uiMessage ( CallBacker ) const

When a work is submitted and setup with a task, returns the task message when not finished successfully.

Friends And Related Function Documentation

◆ WorkThread

friend class WorkThread
friend

Member Data Documentation

◆ callbacks_

TypeSet<CallBack> Threads::WorkManager::callbacks_
protected

◆ freeid_

int Threads::WorkManager::freeid_
protected

◆ freethreads_

ObjectSet<WorkThread> Threads::WorkManager::freethreads_
protected

◆ isidle

Notifier<WorkManager> Threads::WorkManager::isidle

◆ isShuttingDown

Notifier<WorkManager> Threads::WorkManager::isShuttingDown

◆ queueids_

TypeSet<int> Threads::WorkManager::queueids_
protected

◆ queueisclosing_

BoolTypeSet Threads::WorkManager::queueisclosing_
protected

◆ queuenames_

BufferStringSet Threads::WorkManager::queuenames_
protected

◆ queuetypes_

TypeSet<QueueType> Threads::WorkManager::queuetypes_
protected

◆ queueworkload_

TypeSet<int> Threads::WorkManager::queueworkload_
protected

◆ threadids_

ObjectSet<const void> Threads::WorkManager::threadids_
protected

◆ threads_

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

◆ twmid_

const int Threads::WorkManager::twmid_
protected

Only for debugging.

◆ workload_

TypeSet<Work> Threads::WorkManager::workload_
protected

◆ workloadcond_

ConditionVar& Threads::WorkManager::workloadcond_
protected

◆ workqueueid_

TypeSet<int> Threads::WorkManager::workqueueid_
protected

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