epicsGuard.h
Provides classes for RAII style locking and unlocking of mutexes.
Provides classes for RAII style locking and unlocking of mutexes
-
template<class T>
class epicsGuard - #include <epicsGuard.h>
Provides an RAII style lock/unlock of a mutex.
Provides an RAII style lock/unlock of a mutex. When this object is created, it attempts to lock the mutex it was given. When control leaves the scope where this was created, the destructor unlocks the mutex.
This class is also useful in situations where C++ exceptions are possible.
Example
epicsMutex mutex; { epicsGuard guard(mutex); printf("mutex is locked") } printf("mutex is unlocked\n");
Public Types
-
typedef epicsGuardRelease<T> release_t
Public Functions
-
inline epicsGuard(T &mutexIn)
Guard a mutex based on scope.
Constructs an epicsGuard, locking the mutex for the scope of this object.
- Parameters:
mutexIn – A mutex-like object to be lock()’ed and unlock()’ed
-
inline ~epicsGuard()
Friends
- friend class epicsGuardRelease< T >
-
typedef epicsGuardRelease<T> release_t
-
template<class T>
class epicsGuardRelease - #include <epicsGuard.h>
RAII style unlocking of an epicsGuard object.
RAII style unlocking of an epicsGuard object This class can be used while a epicsGuard is active to temporarily release the mutex and automatically re-apply the lock when this object goes out of scope.
This class is also useful in situations where C++ exceptions are possible.
Example
epicsMutex mutex; { epicsGuard guard(mutex); printf("mutex is locked"); { epicsGuardRelease grelease(guard); printf("mutex is unlocked"); } printf("mutex is locked"); } printf("mutex is unlocked");
Public Types
-
typedef epicsGuard<T> guard_t
Public Functions
-
inline epicsGuardRelease(epicsGuard<T> &guardIn)
Constructs an epicsGuardRelease, unlocking the given epicsGuard.
Constructs an epicsGuardRelease, unlocking the given epicsGuard for the duration of this object.
- Parameters:
guardIn – The epicsGuard object to be temporarily released.
-
inline ~epicsGuardRelease()
Private Functions
-
epicsGuardRelease(const epicsGuardRelease&)
-
epicsGuardRelease &operator=(const epicsGuardRelease&)
-
typedef epicsGuard<T> guard_t
-
class epicsMutexNOOP
- #include <epicsGuard.h>
Mutex-like object that does nothing.
This object can be passed into an epicsGuard or similar interface when no actual locking is needed.