PIP 5.6.1
Platform-Independent Primitives
Public Member Functions | List of all members
PISemaphoreLocker Class Reference

Scope guard that acquires semaphore units in constructor and releases them in destructor. More...

#include <pisemaphore.h>

Public Member Functions

 PISemaphoreLocker (PISemaphore &s, int cnt=1, bool condition=true)
 Constructs and acquire "cnt" resources on semaphore "s" if "condition" is true.
 
 ~PISemaphoreLocker ()
 Release "cnt" resources on semaphore if "condition" was true.
 

Detailed Description

Scope guard that acquires semaphore units in constructor and releases them in destructor.

PISemaphore autolocker

When a PISemaphoreLocker object is created, it attempts to acquire the semaphore resources, if "condition" true. When control leaves the scope in which the PISemaphoreLocker object was created, the PISemaphoreLocker is destructed and the resources are released, if "condition" was true.

If "condition" false this class do nothing.

The PISemaphoreLocker class is non-copyable.

// critical section start
{
PISemaphoreLocker locker(mutex, 5);
// ... your code here
}
// critical section end
Scope guard that acquires semaphore units in constructor and releases them in destructor.
Definition: pisemaphore.h:78