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

A ManualLockGuard can be used to protect a variable with a mutex in situations where it is not possible for scoping to be used. More...

#include "lockguards.h"

Inheritance diagram for ion::base::ManualLockGuard< T >:
Collaboration diagram for ion::base::ManualLockGuard< T >:

Public Member Functions

 ManualLockGuard (const T &initial_value)
 The constructor is passed the initial value of the variable being protected. More...
 
 ~ManualLockGuard ()
 The destructor unlocks the mutex if necessary. More...
 
void SetAndLock (const T &new_value)
 Sets the variable's value and locks the mutex. More...
 
const T ResetAndUnlock ()
 Resets the variable's value to the initial value (passed to the constructor), unlocks the mutex, and returns the previous value. More...
 
const T GetCurrentValue ()
 Returns the current value of the variable. More...
 
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 Attributes

port::Mutexmutex_
 The mutex used for locking. More...
 
bool is_locked_
 Whether the mutex is currently locked by this guard. More...
 

Detailed Description

template<typename T>
class ion::base::ManualLockGuard< T >

A ManualLockGuard can be used to protect a variable with a mutex in situations where it is not possible for scoping to be used.

The mutex is built into the class.

Definition at line 142 of file lockguards.h.

Constructor & Destructor Documentation

template<typename T >
ion::base::ManualLockGuard< T >::ManualLockGuard ( const T initial_value)
inlineexplicit

The constructor is passed the initial value of the variable being protected.

Definition at line 146 of file lockguards.h.

template<typename T >
ion::base::ManualLockGuard< T >::~ManualLockGuard ( )
inline

The destructor unlocks the mutex if necessary.

This destructor is intentionally non-virtual for speed. It duplicates what the base class destructor does.

Definition at line 156 of file lockguards.h.

Member Function Documentation

template<typename T >
const T ion::base::ManualLockGuard< T >::GetCurrentValue ( )
inline

Returns the current value of the variable.

This blocks if the mutex is already locked.

Definition at line 176 of file lockguards.h.

bool ion::base::GenericLockGuardBase< port::Mutex >::IsLocked ( ) const
inlineinherited

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.

void ion::base::GenericLockGuardBase< port::Mutex >::Lock ( )
inlineinherited

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.

References mutex_.

template<typename T >
const T ion::base::ManualLockGuard< T >::ResetAndUnlock ( )
inline

Resets the variable's value to the initial value (passed to the constructor), unlocks the mutex, and returns the previous value.

Definition at line 167 of file lockguards.h.

template<typename T >
void ion::base::ManualLockGuard< T >::SetAndLock ( const T new_value)
inline

Sets the variable's value and locks the mutex.

This blocks while the mutex is locked.

Definition at line 160 of file lockguards.h.

bool ion::base::GenericLockGuardBase< port::Mutex >::TryLock ( )
inlineinherited

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.

References mutex_.

void ion::base::GenericLockGuardBase< port::Mutex >::Unlock ( )
inlineinherited

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

Definition at line 63 of file lockguards.h.

References mutex_.

Member Data Documentation

bool ion::base::GenericLockGuardBase< port::Mutex >::is_locked_
protectedinherited

Whether the mutex is currently locked by this guard.

Definition at line 81 of file lockguards.h.

port::Mutex & ion::base::GenericLockGuardBase< port::Mutex >::mutex_
protectedinherited

The mutex used for locking.

Definition at line 79 of file lockguards.h.


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