Belle II Software development
|
Handles creation, locking and unlocking of System V semaphores. More...
#include <SemaphoreLocker.h>
Public Member Functions | |
SemaphoreLocker (int semId) | |
Lock the given semaphore. | |
~SemaphoreLocker () | |
Unlock. | |
void | lock () |
Lock the semaphore. | |
void | unlock () |
Unlock the semaphore. | |
Static Public Member Functions | |
static int | create (key_t semkey) |
Create a new semaphore and initialize it. | |
static void | destroy (int semId) |
Destroy the given semaphore. | |
static bool | isLocked (int semId) |
Return true if the given semaphore is locked. | |
Private Attributes | |
int | m_id |
semaphore id, see semget(2). | |
Handles creation, locking and unlocking of System V semaphores.
create() is used to create a new semaphore with a given semaphore key.
The returned semaphore id can then be used to protect critical sections by constructing an instance of this class. The semaphore is unlocked again on destruction.
Definition at line 24 of file SemaphoreLocker.h.
|
inlineexplicit |
|
inline |
|
static |
Create a new semaphore and initialize it.
Returns the semaphore id or value < 0 on error.
Definition at line 19 of file SemaphoreLocker.cc.
|
static |
Destroy the given semaphore.
Definition at line 39 of file SemaphoreLocker.cc.
|
static |
Return true if the given semaphore is locked.
If you know the lock might be held by the current process (e.g. while in a signal handler), locking is only safe if this returns false.
Definition at line 46 of file SemaphoreLocker.cc.
void lock | ( | ) |
Lock the semaphore.
If the semaphore is locked, this function will block until it can acquire a lock.
Definition at line 72 of file SemaphoreLocker.cc.
void unlock | ( | ) |
Unlock the semaphore.
Definition at line 77 of file SemaphoreLocker.cc.
|
private |
semaphore id, see semget(2).
Definition at line 52 of file SemaphoreLocker.h.