Open CASCADE Technology
7.5.0
|
Mutex: a class to synchronize access to shared data. More...
#include <Standard_Mutex.hxx>
Data Structures | |
class | Sentry |
Simple sentry class providing convenient interface to mutex. More... | |
Public Member Functions | |
Standard_Mutex () | |
Constructor: creates a mutex object and initializes it. It is strongly recommended that mutexes were created as static objects whenever possible. More... | |
~Standard_Mutex () | |
Destructor: destroys the mutex object. More... | |
void | Lock () |
Method to lock the mutex; waits until the mutex is released by other threads, locks it and then returns. More... | |
Standard_Boolean | TryLock () |
Method to test the mutex; if the mutex is not hold by other thread, locks it and returns True; otherwise returns False without waiting mutex to be released. More... | |
void | Unlock () |
Method to unlock the mutex; releases it to other users. More... | |
Public Member Functions inherited from Standard_ErrorHandler::Callback | |
void | RegisterCallback () |
Registers this callback object in the current error handler (if found). More... | |
void | UnregisterCallback () |
Unregisters this callback object from the error handler. More... | |
virtual | ~Callback () |
Destructor. More... | |
Additional Inherited Members | |
Protected Member Functions inherited from Standard_ErrorHandler::Callback | |
Callback () | |
Empty constructor. More... | |
Mutex: a class to synchronize access to shared data.
This is simple encapsulation of tools provided by the operating system to syncronize access to shared data from threads within one process.
Current implementation is very simple and straightforward; it is just a wrapper around POSIX pthread librray on UNIX/Linux, and CRITICAL_SECTIONs on Windows NT. It does not provide any advanced functionaly such as recursive calls to the same mutex from within one thread (such call will froze the execution).
Note that all the methods of that class are made inline, in order to keep maximal performance. This means that a library using the mutex might need to be linked to threads library directly.
The typical use of this class should be as follows:
Note that this class provides one feature specific to Open CASCADE: safe unlocking the mutex when signal is raised and converted to OCC exceptions (Note that with current implementation of this functionality on UNIX and Linux, C longjumps are used for that, thus destructors of classes are not called automatically).
To use this feature, call RegisterCallback() after Lock() or successful TryLock(), and UnregisterCallback() before Unlock() (or use Sentry classes).
Standard_Mutex::Standard_Mutex | ( | ) |
Constructor: creates a mutex object and initializes it. It is strongly recommended that mutexes were created as static objects whenever possible.
Standard_Mutex::~Standard_Mutex | ( | ) |
Destructor: destroys the mutex object.
void Standard_Mutex::Lock | ( | ) |
Method to lock the mutex; waits until the mutex is released by other threads, locks it and then returns.
Standard_Boolean Standard_Mutex::TryLock | ( | ) |
Method to test the mutex; if the mutex is not hold by other thread, locks it and returns True; otherwise returns False without waiting mutex to be released.
|
inline |
Method to unlock the mutex; releases it to other users.