Ion
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ion::base::GenericLockGuardBase< MutexT > Class Template Reference

This file contains utility classes for automatically locking and unlocking mutexes. More...

#include "lockguards.h"

Inheritance diagram for ion::base::GenericLockGuardBase< MutexT >:
Collaboration diagram for ion::base::GenericLockGuardBase< MutexT >:

Public Member Functions

bool IsLocked () const
 Returns whether this guard has locked the mutex; returns false even if another guard has it locked. More...
 
void Lock ()
 Locks the mutex if it is not already locked by this guard. More...
 
bool TryLock ()
 Attempts to lock the mutex if the mutex is not already locked by this guard. More...
 
void Unlock ()
 Releases a lock on the mutex if it was previously locked by this guard. More...
 

Protected Member Functions

 GenericLockGuardBase (MutexT *m)
 The constructor is protected since this is an abstract base class. More...
 
 ~GenericLockGuardBase ()
 This destructor intentionally non-virtual for speed. More...
 

Protected Attributes

MutexT & mutex_
 The mutex used for locking. More...
 
bool is_locked_
 Whether the mutex is currently locked by this guard. More...
 

Detailed Description

template<class MutexT>
class ion::base::GenericLockGuardBase< MutexT >

This file contains utility classes for automatically locking and unlocking mutexes.

Base class of guards that lock a mutex when created and unlock when destroyed.

Definition at line 35 of file lockguards.h.

Constructor & Destructor Documentation

template<class MutexT>
ion::base::GenericLockGuardBase< MutexT >::GenericLockGuardBase ( MutexT *  m)
inlineexplicitprotected

The constructor is protected since this is an abstract base class.

Definition at line 72 of file lockguards.h.

template<class MutexT>
ion::base::GenericLockGuardBase< MutexT >::~GenericLockGuardBase ( )
inlineprotected

This destructor intentionally non-virtual for speed.

Any subclasses should also call Unlock() in their destructors.

Definition at line 76 of file lockguards.h.

Member Function Documentation

template<class MutexT>
bool ion::base::GenericLockGuardBase< MutexT >::IsLocked ( ) const
inline

Returns whether this guard has locked the mutex; returns false even if another guard has it locked.

Use MutexT::IsLocked() to determine if the mutex itself is locked.

Definition at line 40 of file lockguards.h.

template<class MutexT>
void ion::base::GenericLockGuardBase< MutexT >::Lock ( )
inline

Locks the mutex if it is not already locked by this guard.

This function blocks if the mutex is locked elsewhere (e.g., by another guard).

Definition at line 44 of file lockguards.h.

template<class MutexT>
bool ion::base::GenericLockGuardBase< MutexT >::TryLock ( )
inline

Attempts to lock the mutex if the mutex is not already locked by this guard.

This function never blocks. Returns true if the mutex was successfully locked or if this guard has already locked it, and false otherwise.

Definition at line 55 of file lockguards.h.

template<class MutexT>
void ion::base::GenericLockGuardBase< MutexT >::Unlock ( )
inline

Releases a lock on the mutex if it was previously locked by this guard.

Definition at line 63 of file lockguards.h.

Member Data Documentation

template<class MutexT>
bool ion::base::GenericLockGuardBase< MutexT >::is_locked_
protected

Whether the mutex is currently locked by this guard.

Definition at line 81 of file lockguards.h.

template<class MutexT>
MutexT& ion::base::GenericLockGuardBase< MutexT >::mutex_
protected

The mutex used for locking.

Definition at line 79 of file lockguards.h.


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