oasys::Lock Class Reference

#include <Lock.h>

Inheritance diagram for oasys::Lock:

oasys::Logger oasys::Mutex oasys::NoLock oasys::SpinLock

List of all members.


Detailed Description

Abstract Lock base class.

Definition at line 32 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

Constructor & Destructor Documentation

oasys::Lock::Lock (  )  [inline]

Default Lock constructor.

Definition at line 37 of file Lock.h.

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 48 of file Lock.h.

References ASSERT, is_locked(), is_locked_by_me(), and scope_lock_count_.


Member Function Documentation

virtual int oasys::Lock::lock ( const char *  lock_user  )  [pure virtual]

Acquire the lock.

Returns:
0 on success, -1 on error

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.

Returns:
0 on success, -1 on error

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.

Returns:
0 on success, 1 if already locked, -1 on error.

Implemented in oasys::Mutex, oasys::NoLock, and oasys::SpinLock.

bool oasys::Lock::is_locked (  )  [inline]

Check for whether the lock is locked or not.

Returns:
true if locked, false otherwise

Definition at line 82 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.

Returns:
true if locked by the current thread, false otherwise

Definition at line 93 of file Lock.h.

References oasys::Thread::current(), is_locked(), and lock_holder_.

Referenced by dtn::BundleList::add_bundle(), dtn::BundleOfferList::begin(), dtn::ProphetTable::begin(), dtn::BundleList::begin(), dtn::BundleList::del_bundle(), dtn::BundleOfferList::end(), dtn::ProphetTable::end(), dtn::BundleList::end(), dtn::BundleList::erase(), dtn::ProphetStats::find_entry(), 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(), dtn::RegistrationTable::reg_list(), dtn::RouteTable::route_table(), oasys::SpinLock::try_lock(), oasys::SpinLock::unlock(), oasys::Mutex::unlock(), dtn::GlobalStore::update(), and ~Lock().


Friends And Related Function Documentation

friend class ScopeLock [friend]

Definition at line 100 of file Lock.h.

friend class ScopeLockIf [friend]

Definition at line 101 of file Lock.h.


Member Data Documentation

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 108 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 120 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 126 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 134 of file Lock.h.

Referenced by oasys::ScopeLockIf::do_lock(), oasys::ScopeLock::do_lock(), oasys::ScopeLockIf::unlock(), oasys::ScopeLock::unlock(), and ~Lock().


The documentation for this class was generated from the following file:
Generated on Sat Sep 8 08:43:54 2007 for DTN Reference Implementation by  doxygen 1.5.3