Implement a C++ wrapper that allows nested acquisition and release of a mutex that occurs in the same thread. More...
#include <Recursive_Thread_Mutex.h>
Public Member Functions | |
| ACE_Recursive_Thread_Mutex (const ACE_TCHAR *name=0, ACE_mutexattr_t *arg=0) | |
| Initialize a recursive mutex. | |
| ~ACE_Recursive_Thread_Mutex (void) | |
| Implicitly release a recursive mutex. | |
| int | remove (void) |
| int | acquire (void) |
| int | acquire (ACE_Time_Value &tv) |
| int | acquire (ACE_Time_Value *tv) |
| int | tryacquire (void) |
| int | acquire_read (void) |
| int | acquire_write (void) |
| int | tryacquire_read (void) |
| int | tryacquire_write (void) |
| int | tryacquire_write_upgrade (void) |
| int | release (void) |
| ACE_thread_t | get_thread_id (void) |
| Return the id of the thread that currently owns the mutex. | |
| int | get_nesting_level (void) |
| ACE_recursive_thread_mutex_t & | mutex (void) |
| Returns a reference to the recursive mutex;. | |
| ACE_thread_mutex_t & | get_nesting_mutex (void) |
| Returns a reference to the recursive mutex's internal mutex;. | |
| void | dump (void) const |
| Dump the state of an object. | |
Public Attributes | |
| ACE_ALLOC_HOOK_DECLARE | |
| Declare the dynamic allocation hooks. | |
Protected Member Functions | |
| void | set_thread_id (ACE_thread_t t) |
Protected Attributes | |
| ACE_recursive_thread_mutex_t | lock_ |
| Recursive mutex. | |
| bool | removed_ |
Private Member Functions | |
| void | operator= (const ACE_Recursive_Thread_Mutex &) |
| ACE_Recursive_Thread_Mutex (const ACE_Recursive_Thread_Mutex &) | |
Implement a C++ wrapper that allows nested acquisition and release of a mutex that occurs in the same thread.
Definition at line 41 of file Recursive_Thread_Mutex.h.
| ACE_Recursive_Thread_Mutex::ACE_Recursive_Thread_Mutex | ( | const ACE_TCHAR * | name = 0, |
|
| ACE_mutexattr_t * | arg = 0 | |||
| ) |
Initialize a recursive mutex.
| ACE_Recursive_Thread_Mutex::~ACE_Recursive_Thread_Mutex | ( | void | ) |
Implicitly release a recursive mutex.
| ACE_Recursive_Thread_Mutex::ACE_Recursive_Thread_Mutex | ( | const ACE_Recursive_Thread_Mutex & | ) | [private] |
| int ACE_Recursive_Thread_Mutex::acquire | ( | ACE_Time_Value * | tv | ) |
If tv == 0 the call <acquire()> directly. Otherwise, Block the thread until we acquire the mutex or until tv times out, in which case -1 is returned with errno == ETIME. Note that <*tv> is assumed to be in "absolute" rather than "relative" time. The value of <*tv> is updated upon return to show the actual (absolute) acquisition time.
Definition at line 59 of file Recursive_Thread_Mutex.inl.
00060 { 00061 return ACE_OS::recursive_mutex_lock (&this->lock_, tv); 00062 }
| int ACE_Recursive_Thread_Mutex::acquire | ( | ACE_Time_Value & | tv | ) |
Block the thread until we acquire the mutex or until tv times out, in which case -1 is returned with errno == ETIME. Note that tv is assumed to be in "absolute" rather than "relative" time. The value of tv is updated upon return to show the actual (absolute) acquisition time.
Definition at line 53 of file Recursive_Thread_Mutex.inl.
00054 { 00055 return ACE_OS::recursive_mutex_lock (&this->lock_, tv); 00056 }
| int ACE_Recursive_Thread_Mutex::acquire | ( | void | ) |
Acquire a recursive mutex (will increment the nesting level and not deadmutex if the owner of the mutex calls this method more than once).
Definition at line 35 of file Recursive_Thread_Mutex.inl.
00036 { 00037 return ACE_OS::recursive_mutex_lock (&this->lock_); 00038 }
| int ACE_Recursive_Thread_Mutex::acquire_read | ( | void | ) |
Acquire mutex ownership. This calls <acquire> and is only here to make the <ACE_Recusive_Thread_Mutex> interface consistent with the other synchronization APIs.
Definition at line 65 of file Recursive_Thread_Mutex.inl.
00066 { 00067 return this->acquire (); 00068 }
| int ACE_Recursive_Thread_Mutex::acquire_write | ( | void | ) |
Acquire mutex ownership. This calls <acquire> and is only here to make the <ACE_Recusive_Thread_Mutex> interface consistent with the other synchronization APIs.
Definition at line 71 of file Recursive_Thread_Mutex.inl.
00072 { 00073 return this->acquire (); 00074 }
| void ACE_Recursive_Thread_Mutex::dump | ( | void | ) | const |
Dump the state of an object.
| int ACE_Recursive_Thread_Mutex::get_nesting_level | ( | void | ) |
Return the nesting level of the recursion. When a thread has acquired the mutex for the first time, the nesting level == 1. The nesting level is incremented every time the thread acquires the mutex recursively. Note that if the ACE_HAS_RECURSIVE_MUTEXES macro is enabled then this method may return -1 on platforms that do not expose the internal count.
| ACE_thread_mutex_t & ACE_Recursive_Thread_Mutex::get_nesting_mutex | ( | void | ) |
Returns a reference to the recursive mutex's internal mutex;.
Definition at line 14 of file Recursive_Thread_Mutex.inl.
00015 { 00016 #if defined (ACE_HAS_RECURSIVE_MUTEXES) 00017 return static_cast<ACE_thread_mutex_t &> (lock_); 00018 #else 00019 return lock_.nesting_mutex_; 00020 #endif /* ACE_HAS_RECURSIVE_MUTEXES */ 00021 }
| ACE_thread_t ACE_Recursive_Thread_Mutex::get_thread_id | ( | void | ) |
Return the id of the thread that currently owns the mutex.
| ACE_recursive_thread_mutex_t & ACE_Recursive_Thread_Mutex::mutex | ( | void | ) |
Returns a reference to the recursive mutex;.
Definition at line 8 of file Recursive_Thread_Mutex.inl.
00009 { 00010 return lock_; 00011 }
| void ACE_Recursive_Thread_Mutex::operator= | ( | const ACE_Recursive_Thread_Mutex & | ) | [private] |
| int ACE_Recursive_Thread_Mutex::release | ( | void | ) |
Releases a recursive mutex (will not release mutex until all the nesting level drops to 0, which means the mutex is no longer held).
Definition at line 41 of file Recursive_Thread_Mutex.inl.
00042 { 00043 return ACE_OS::recursive_mutex_unlock (&this->lock_); 00044 }
| int ACE_Recursive_Thread_Mutex::remove | ( | void | ) |
Implicitly release a recursive mutex. Note that only one thread should call this method since it doesn't protect against race conditions.
| void ACE_Recursive_Thread_Mutex::set_thread_id | ( | ACE_thread_t | t | ) | [protected] |
Definition at line 24 of file Recursive_Thread_Mutex.inl.
00025 { 00026 // ACE_TRACE ("ACE_Recursive_Thread_Mutex::set_thread_id"); 00027 #if defined (ACE_HAS_RECURSIVE_MUTEXES) 00028 ACE_UNUSED_ARG (t); 00029 #else /* ! ACE_HAS_RECURSIVE_MUTEXES */ 00030 this->lock_.owner_id_ = t; 00031 #endif /* ! ACE_HAS_RECURSIVE_MUTEXES */ 00032 }
| int ACE_Recursive_Thread_Mutex::tryacquire | ( | void | ) |
Conditionally acquire a recursive mutex (i.e., won't block). Returns -1 on failure. If we "failed" because someone else already had the lock, errno is set to EBUSY.
Definition at line 47 of file Recursive_Thread_Mutex.inl.
00048 { 00049 return ACE_OS::recursive_mutex_trylock (&this->lock_); 00050 }
| int ACE_Recursive_Thread_Mutex::tryacquire_read | ( | void | ) |
Conditionally acquire mutex (i.e., won't block). This calls <tryacquire> and is only here to make the <ACE_Recusive_Thread_Mutex> interface consistent with the other synchronization APIs. Returns -1 on failure. If we "failed" because someone else already had the lock, errno is set to EBUSY.
Definition at line 77 of file Recursive_Thread_Mutex.inl.
00078 { 00079 return this->tryacquire (); 00080 }
| int ACE_Recursive_Thread_Mutex::tryacquire_write | ( | void | ) |
Conditionally acquire mutex (i.e., won't block). This calls <tryacquire> and is only here to make the <ACE_Recusive_Thread_Mutex> interface consistent with the other synchronization APIs. Returns -1 on failure. If we "failed" because someone else already had the lock, errno is set to EBUSY.
Definition at line 83 of file Recursive_Thread_Mutex.inl.
00084 { 00085 return this->tryacquire (); 00086 }
| int ACE_Recursive_Thread_Mutex::tryacquire_write_upgrade | ( | void | ) |
This is only here to make the ACE_Recursive_Thread_Mutex interface consistent with the other synchronization APIs. Assumes the caller has already acquired the mutex using one of the above calls, and returns 0 (success) always.
Definition at line 89 of file Recursive_Thread_Mutex.inl.
Declare the dynamic allocation hooks.
Definition at line 163 of file Recursive_Thread_Mutex.h.
Recursive mutex.
Definition at line 170 of file Recursive_Thread_Mutex.h.
bool ACE_Recursive_Thread_Mutex::removed_ [protected] |
Keeps track of whether <remove> has been called yet to avoid multiple <remove> calls, e.g., explicitly and implicitly in the destructor. This flag isn't protected by a lock, so make sure that you don't have multiple threads simultaneously calling <remove> on the same object, which is a bad idea anyway...
Definition at line 177 of file Recursive_Thread_Mutex.h.
1.6.1