#include <Lock.h>
Inheritance diagram for oasys::Lock:
Definition at line 55 of file Lock.h.
Public Member Functions | |
Lock () | |
Default Lock constructor. | |
virtual | ~Lock () |
Lock destructor. | |
virtual int | lock (const char *lock_user)=0 |
Acquire the lock. | |
virtual int | unlock ()=0 |
Release the lock. | |
virtual int | try_lock (const char *lock_user)=0 |
Try to acquire the lock. | |
bool | is_locked () |
Check for whether the lock is locked or not. | |
bool | is_locked_by_me () |
Check for whether the lock is locked or not by the calling thread. | |
Protected Attributes | |
atomic_t | lock_count_ |
Stores a count of the number of locks currently held, needed for recursive locking. | |
volatile pthread_t | lock_holder_ |
Stores the pthread thread id of the current lock holder. | |
const char * | lock_holder_name_ |
Lock holder name for debugging purposes. | |
int | scope_lock_count_ |
Stores a count of the number of ScopeLocks holding the lock. | |
Friends | |
class | ScopeLock |
class | ScopeLockIf |
virtual oasys::Lock::~Lock | ( | ) | [inline, virtual] |
Lock destructor.
Asserts that the lock is not locked by another thread or by a scope lock.
Definition at line 71 of file Lock.h.
References ASSERT, is_locked(), is_locked_by_me(), and scope_lock_count_.
virtual int oasys::Lock::lock | ( | const char * | lock_user | ) | [pure virtual] |
Acquire the lock.
Implemented in oasys::Mutex, oasys::NoLock, and oasys::SpinLock.
Referenced by oasys::ScopeLockIf::do_lock(), oasys::ScopeLock::do_lock(), oasys::SXLock::exclusive_lock(), oasys::SXLock::exclusive_unlock(), oasys::SXLock::shared_lock(), oasys::SXLock::shared_unlock(), and oasys::OnOffNotifier::wait().
virtual int oasys::Lock::unlock | ( | ) | [pure virtual] |
Release the lock.
Implemented in oasys::Mutex, oasys::NoLock, and oasys::SpinLock.
Referenced by oasys::SXLock::exclusive_lock(), oasys::SXLock::exclusive_unlock(), oasys::SXLock::shared_lock(), oasys::SXLock::shared_unlock(), oasys::ScopeLockIf::unlock(), oasys::ScopeLock::unlock(), and oasys::OnOffNotifier::wait().
virtual int oasys::Lock::try_lock | ( | const char * | lock_user | ) | [pure virtual] |
Try to acquire the lock.
Implemented in oasys::Mutex, oasys::NoLock, and oasys::SpinLock.
bool oasys::Lock::is_locked | ( | ) | [inline] |
Check for whether the lock is locked or not.
Definition at line 105 of file Lock.h.
References lock_count_, and oasys::atomic_t::value.
Referenced by is_locked_by_me(), and ~Lock().
bool oasys::Lock::is_locked_by_me | ( | ) | [inline] |
Check for whether the lock is locked or not by the calling thread.
Definition at line 116 of file Lock.h.
References oasys::Thread::current(), is_locked(), and lock_holder_.
Referenced by dtn::BundleList::add_bundle(), dtn::BundleList::begin(), dtn::BundleList::del_bundle(), dtn::BundleList::end(), dtn::BundleList::erase(), dtn::BundlePayload::internal_write(), dtn::ContactManager::links(), oasys::SpinLock::lock(), dtn::Bundle::mappings_begin(), dtn::Bundle::mappings_end(), dtn::BlockingBundleList::pop_blocking(), oasys::TimerSystem::pop_timer(), oasys::SpinLock::try_lock(), oasys::SpinLock::unlock(), oasys::Mutex::unlock(), dtn::GlobalStore::update(), and ~Lock().
friend class ScopeLockIf [friend] |
atomic_t oasys::Lock::lock_count_ [protected] |
Stores a count of the number of locks currently held, needed for recursive locking.
Note that 0 means the lock is currently not locked.
Definition at line 131 of file Lock.h.
Referenced by is_locked(), oasys::SpinLock::lock(), oasys::Mutex::lock(), oasys::SpinLock::try_lock(), oasys::Mutex::try_lock(), oasys::SpinLock::unlock(), and oasys::Mutex::unlock().
volatile pthread_t oasys::Lock::lock_holder_ [protected] |
Stores the pthread thread id of the current lock holder.
It is the responsibility of the derived class to set this in lock() and unset it in unlock(), since the accessors is_locked() and is_locked_by_me() depend on it.
Note that this field must be declared volatile to ensure that readers of the field make sure to go to memory (which might have been updated by another thread).
Definition at line 143 of file Lock.h.
Referenced by is_locked_by_me(), oasys::SpinLock::lock(), oasys::Mutex::lock(), oasys::SpinLock::try_lock(), oasys::Mutex::try_lock(), oasys::SpinLock::unlock(), and oasys::Mutex::unlock().
const char* oasys::Lock::lock_holder_name_ [protected] |
Lock holder name for debugging purposes.
Identifies call site from which lock has been held.
Definition at line 149 of file Lock.h.
Referenced by oasys::SpinLock::lock(), oasys::Mutex::lock(), oasys::SpinLock::try_lock(), oasys::Mutex::try_lock(), oasys::SpinLock::unlock(), and oasys::Mutex::unlock().
int oasys::Lock::scope_lock_count_ [protected] |
Stores a count of the number of ScopeLocks holding the lock.
This is checked in the Lock destructor to avoid strange crashes if you delete the lock object and then the ScopeLock destructor tries to unlock it.
Definition at line 157 of file Lock.h.
Referenced by oasys::ScopeLockIf::do_lock(), oasys::ScopeLock::do_lock(), oasys::ScopeLockIf::unlock(), oasys::ScopeLock::unlock(), and ~Lock().