csMutex Class Reference
A mutual-exclusion object. More...
#include <csutil/thread.h>
Inheritance diagram for csMutex:
Public Member Functions | |
virtual char const * | GetLastError () const =0 |
Return the last error description, else 0 if there was none. | |
virtual bool | IsRecursive () const =0 |
Return true if the mutex is recursive. | |
virtual bool | LockTry ()=0 |
Lock the mutex if not already locked by some other entity. | |
virtual bool | LockWait ()=0 |
Lock the mutex. | |
virtual bool | Release ()=0 |
Unlock the mutex. | |
Static Public Member Functions | |
static csRef< csMutex > | Create (bool recursive=false) |
Create a mutex. |
Detailed Description
A mutual-exclusion object.A thread-safe lock. Mutexes are often used to control access to one or more resources shared by multiple threads of execution. A thread should access the shared resource(s) only after it has successfully locked the mutex; and it should unlock the mutex when it is done accessing the shared resource so that other threads may access it.
Definition at line 171 of file thread.h.
Member Function Documentation
Create a mutex.
- Parameters:
-
recursive If true, the same thread can lock the mutex even when it already holds the lock without deadlocking. If false, then recursive locking within the same thread is not supported, and will probably deadlock.
- Returns:
- The new mutex.
- Remarks:
- On Windows, mutexes always exhibit recursive semantics, however, for best portability, you should still choose an appropriate value for recursive. On other platforms, such as GNU/Linux, non-recursive threads may be the default since they are can be implemented more efficiently.
Referenced by CS::SndSys::Queue< CS::SndSys::SndSysBasicStream::StreamNotificationEvent >::Queue().
virtual char const* csMutex::GetLastError | ( | ) | const [pure virtual] |
Return the last error description, else 0 if there was none.
virtual bool csMutex::IsRecursive | ( | ) | const [pure virtual] |
Return true if the mutex is recursive.
virtual bool csMutex::LockTry | ( | ) | [pure virtual] |
virtual bool csMutex::LockWait | ( | ) | [pure virtual] |
Lock the mutex.
Suspends execution of the thread until the mutex can be locked. Each LockWait() must be balanced by a call to Release(). Returns true if locking succeeded. Returns false if locking failed for some catastrophic reason; check GetLastError().
Referenced by csScopedMutexLock::csScopedMutexLock().
virtual bool csMutex::Release | ( | ) | [pure virtual] |
Unlock the mutex.
Each successful call to LockWait() or LockTry() must be balanced by a call to Release(). Returns true if unlocking succeeded. Returns false if unlocking failed for some catastrophic reason; check GetLastError().
Referenced by csScopedMutexLock::~csScopedMutexLock().
The documentation for this class was generated from the following file:
- csutil/thread.h
Generated for Crystal Space by doxygen 1.4.7