A scoped locking class for exception safe Mutex locking.
More...
#include <c++-gtk-utils/mutex.h>
◆ Lock() [1/2]
Cgu::Thread::Mutex::Lock::Lock |
( |
Mutex & |
mutex_ | ) |
|
|
inline |
This constructor locks the mutex passed to it. It is not a cancellation point. It does not throw.
- Parameters
-
mutex_ | The mutex to be locked. |
◆ Lock() [2/2]
Cgu::Thread::Mutex::Lock::Lock |
( |
Mutex & |
mutex_, |
|
|
Locked |
tag |
|
) |
| |
|
inline |
This constructor takes an already locked mutex (say as a result of Mutex::trylock()), and takes ownership of it. It is not a cancellation point. It does not throw.
- Parameters
-
mutex_ | The mutex to be managed by this object. |
tag | Pass the Cgu::Thread::locked enum tag to this parameter. |
◆ ~Lock()
Cgu::Thread::Mutex::Lock::~Lock |
( |
| ) |
|
|
inline |
The destructor unlocks the owned mutex. It is not a cancellation point. It does not throw.
◆ lock()
int Cgu::Thread::Mutex::Lock::lock |
( |
| ) |
|
|
inline |
Calls Mutex::lock(), and so locks the mutex and reacquires ownership. It blocks if the mutex is already locked until the mutex becomes free. This method should normally only be called if a previous call has been made to Mutex::Lock::unlock() (that is, where the thread owning the Mutex::Lock object has temporarily allowed another thread to take the mutex concerned). It is not a cancellation point. It does not throw.
- Returns
- 0 if successful, otherwise the pthread mutex error number.
- Note
- With this library implementation, the only pthread error number which could be returned by this method is EDEADLK, which it would do if the default pthread mutex behaviour happens to return that error rather than deadlock in the case of recursive locking. Most default implementations do not do this and hence the return value is usually not worth checking for except during debugging.
- See also
- Mutex::TrackLock.
◆ trylock()
int Cgu::Thread::Mutex::Lock::trylock |
( |
| ) |
|
|
inline |
Calls Mutex::trylock(), and so tries to lock the mutex and reacquire ownership, but returns immediately if it is already locked with value EBUSY. This method should normally only be called if a previous call has been made to Mutex::Lock::unlock() (that is, where the thread owning the Mutex::Lock object has temporarily allowed another thread to take the mutex concerned). It is not a cancellation point. It does not throw.
- Returns
- 0 if successful, otherwise EBUSY.
- Note
- With this library implementation, the only pthread error number which could be returned by this method is EBUSY.
- See also
- Mutex::TrackLock.
◆ unlock()
int Cgu::Thread::Mutex::Lock::unlock |
( |
| ) |
|
|
inline |
Calls Mutex::unlock(), and so unlocks a locked mutex owned by the calling thread and relinquishes ownership (so temporarily allowing another thread to take the mutex). This method should normally only be called if it is to be followed by a call to Mutex::Lock::lock() or a successful call to Mutex::Lock::trylock() before the Mutex::Lock object concerned goes out of scope (otherwise Mutex::Lock's destructor will attempt to unlock an already unlocked mutex or a mutex of which another thread has by then taken ownership - Mutex::Lock objects do not maintain state). See Mutex::TrackLock::unlock() for a safe version of this method. It is not a cancellation point. It does not throw.
- Returns
- 0 if successful, otherwise the pthread mutex error number.
- Note
- With this library implementation, the only pthread error number which could be returned by this method is EPERM because the calling thread does not own the mutex (however POSIX does not require that return value in that case and hence the return value is usually not worth checking for except during debugging).
- See also
- Mutex::TrackLock.
◆ Cond
The documentation for this class was generated from the following file: