Apama  10.7.2.2
com::softwareag::connectivity::SAG_LOCK_GUARD Class Reference

A simple RAII wrapper for SAG_MUTEX_T that locks the specified mutex in its constructor, and guarantees that it will be unlocked when this object goes out of scope unless it has been unlocked already by that point. More...

#include <sag_connectivity_threading.h>

Public Member Functions

 SAG_LOCK_GUARD (SAG_MUTEX_T &mx)
 Create a SAG_LOG_GUARD for a particular mutex. More...
 
 ~SAG_LOCK_GUARD ()
 Destroy this lock guard. More...
 
void lock ()
 Locks the mutex (throws if the mutex is already locked by this lock guard). More...
 
void unlock ()
 Unlocks the mutex (throws if the mutex is already unlocked by this lock guard). More...
 

Detailed Description

A simple RAII wrapper for SAG_MUTEX_T that locks the specified mutex in its constructor, and guarantees that it will be unlocked when this object goes out of scope unless it has been unlocked already by that point.

This is safer than relying on explicitly calling unlock() which can lead to hangs if an exception is thrown before the mutex is unlocked.

Note that you should only use this if your compiler is too old to support C++11 threading primitives. On modern compilers you should use std::mutex with either std::lock_guard or std::unique_lock.

Constructor & Destructor Documentation

◆ SAG_LOCK_GUARD()

com::softwareag::connectivity::SAG_LOCK_GUARD::SAG_LOCK_GUARD ( SAG_MUTEX_T mx)
inline

Create a SAG_LOG_GUARD for a particular mutex.

Takes the mutex.

◆ ~SAG_LOCK_GUARD()

com::softwareag::connectivity::SAG_LOCK_GUARD::~SAG_LOCK_GUARD ( )
inline

Destroy this lock guard.

Releases the mutex if still held.

Member Function Documentation

◆ lock()

void com::softwareag::connectivity::SAG_LOCK_GUARD::lock ( )
inline

Locks the mutex (throws if the mutex is already locked by this lock guard).

◆ unlock()

void com::softwareag::connectivity::SAG_LOCK_GUARD::unlock ( )
inline

Unlocks the mutex (throws if the mutex is already unlocked by this lock guard).


The documentation for this class was generated from the following file: