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

PISemaphore autolocker 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

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
PISemaphore autolocker
Definition: pisemaphore.h:72