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 void assertIdenticalMutex(const T&) const
inline ~epicsGuard()

Private Functions

epicsGuard(const epicsGuard&)
epicsGuard &operator=(const epicsGuard&)

Private Members

T *_pTargetMutex

Friends

friend class epicsGuardRelease< 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&)

Private Members

epicsGuard<T> &_guard
T *_pTargetMutex
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.

Public Functions

inline void lock()

Does nothing.

inline bool tryLock()

Does nothing, always returns true.

inline void unlock()

Does nothing.

inline void show(unsigned level) const

Does nothing.