18 #ifndef ION_BASE_LOCKGUARDS_H_
19 #define ION_BASE_LOCKGUARDS_H_
21 #include "base/macros.h"
34 template <
class MutexT>
57 is_locked_ =
mutex_.TryLock();
89 template <
class MutexT>
95 this->is_locked_ =
true;
105 template <
class MutexT>
120 template <
class MutexT>
141 template <
typename T>
148 initial_value_(initial_value),
149 current_value_(initial_value) {
162 current_value_ = new_value;
168 const T ret = current_value_;
169 current_value_ = initial_value_;
178 T ret = current_value_;
208 #endif // ION_BASE_LOCKGUARDS_H_
GenericUnlockGuard(MutexT *m)
The passed pointer must be non-NULL.
ManualLockGuard(const T &initial_value)
The constructor is passed the initial value of the variable being protected.
GenericLockGuard< port::Mutex > LockGuard
Convenient typedefs for ion::port::Mutex.
A ManualLockGuard can be used to protect a variable with a mutex in situations where it is not possib...
GenericLockGuard(MutexT *m)
The passed pointer must be non-NULL.
GenericLockGuard< SpinMutex > SpinLockGuard
Convenient typedefs for SpinMutex.
An UnlockGuard is the reverse of a LockGuard; it unlocks a mutex when created and locks it when destr...
const T ResetAndUnlock()
Resets the variable's value to the initial value (passed to the constructor), unlocks the mutex...
A LockGuard locks a mutex when created, and unlocks it when destroyed.
void SetAndLock(const T &new_value)
Sets the variable's value and locks the mutex.
GenericTryLockGuard< port::Mutex > TryLockGuard
bool IsLocked() const
Returns whether this guard has locked the mutex; returns false even if another guard has it locked...
A TryLockGuard attempts to lock a mutex when created, and if successful, will unlock it when destroye...
~ManualLockGuard()
The destructor unlocks the mutex if necessary.
GenericTryLockGuard< SpinMutex > SpinTryLockGuard
~GenericLockGuardBase()
This destructor intentionally non-virtual for speed.
GenericLockGuardBase(MutexT *m)
The constructor is protected since this is an abstract base class.
GenericLockGuard< ReadLock > ReadGuard
Convenient typedefs for ReadWriteLock.
void Unlock()
Releases a lock on the mutex if it was previously locked by this guard.
const T GetCurrentValue()
Returns the current value of the variable.
bool TryLock()
Attempts to lock the mutex if the mutex is not already locked by this guard.
MutexT & mutex_
The mutex used for locking.
port::Mutex mutex_
Protects shared access to the Allocator and FT_Library.
bool is_locked_
Whether the mutex is currently locked by this guard.
GenericUnlockGuard< SpinMutex > SpinUnlockGuard
This file contains utility classes for automatically locking and unlocking mutexes.
void Lock()
Locks the mutex if it is not already locked by this guard.
GenericLockGuard< WriteLock > WriteGuard
GenericUnlockGuard< port::Mutex > UnlockGuard
A Mutex is used to ensure that only one thread or process can access a block of code at one time...
GenericTryLockGuard(MutexT *m)
The passed pointer must be non-NULL.