OpendTect  7.0
Public Member Functions | Protected Attributes | List of all members
Threads::ConditionVar Class Reference

Is an object that faciliates many threads to wait for something to happen. More...

Inheritance diagram for Threads::ConditionVar:
[legend]

Public Member Functions

 ConditionVar ()
 
 ConditionVar (const ConditionVar &)
 
 ~ConditionVar ()
 
void signal (bool all)
 
void wait ()
 
bool wait (unsigned long timeout)
 
- Public Member Functions inherited from Threads::Mutex
 Mutex (bool recursive=false)
 
 Mutex (const Mutex &)=delete
 
virtual ~Mutex ()
 
int getCount () const
 
bool isRecursive () const
 
void lock ()
 
bool tryLock ()
 
void unLock ()
 

Protected Attributes

QWaitCondition * cond_
 
- Protected Attributes inherited from Threads::Mutex
int count_ = 0
 Only set in debug-mode. More...
 
ThreadID lockingthread_ = 0
 Only set in debug-mode. More...
 
QMutex * qmutex_ = nullptr
 
QRecursiveMutex * qrecursivemutex_ = nullptr
 

Detailed Description

Is an object that faciliates many threads to wait for something to happen.

Usage:

From the working thread

  1. lock() You will now be the only one allowed to check weather condition is true (e.g. if new work has arrived).
  2. Check condition. If false, call wait(). You will now sleep until someone calls signal(); If you are awakened, check the condition again and go back to sleep if it is false.
  3. If condition is true, unLock() and start working. When finished working go back to 1.

It is wise to put an exit flag in the loop, so it's possible to say that we are about to quit.

From the manager: When you want to change the condition:

  1. lock
  2. set condition (e.g. add more work)
  3. signal
  4. unLock

    <>

Constructor & Destructor Documentation

◆ ConditionVar() [1/2]

Threads::ConditionVar::ConditionVar ( )

◆ ConditionVar() [2/2]

Threads::ConditionVar::ConditionVar ( const ConditionVar )

◆ ~ConditionVar()

Threads::ConditionVar::~ConditionVar ( )

Member Function Documentation

◆ signal()

void Threads::ConditionVar::signal ( bool  all)

If all is true, all threads that have called wait() will be Notified about the signal. If all is false, only one thread will respond.

◆ wait() [1/2]

void Threads::ConditionVar::wait ( )

◆ wait() [2/2]

bool Threads::ConditionVar::wait ( unsigned long  timeout)
Parameters
timeoutis in milliseconds.
Return values
falseif timeout was hit

Member Data Documentation

◆ cond_

QWaitCondition* Threads::ConditionVar::cond_
protected

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