Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

ACE_Recursive_Thread_Mutex Class Reference

Implement a C++ wrapper that allows nested acquisition and release of a mutex that occurs in the same thread. More...

#include <Synch.h>

Collaboration diagram for ACE_Recursive_Thread_Mutex:

Collaboration graph
[legend]
List of all members.

Public Methods

 ACE_Recursive_Thread_Mutex (const ACE_TCHAR *name=0, ACE_mutexattr_t *arg=0)
 Initialize a recursive mutex. More...

 ~ACE_Recursive_Thread_Mutex (void)
 Implicitly release a recursive mutex. More...

int remove (void)
int acquire (void)
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. More...

int get_nesting_level (void)
ACE_recursive_thread_mutex_tmutex (void)
 Returns a reference to the recursive mutex;. More...

ACE_thread_mutex_t & get_nesting_mutex (void)
 Returns a reference to the recursive mutex's internal mutex;. More...

void dump (void) const
 Dump the state of an object. More...


Public Attributes

 ACE_ALLOC_HOOK_DECLARE
 Declare the dynamic allocation hooks. More...


Protected Methods

void set_thread_id (ACE_thread_t t)

Protected Attributes

ACE_recursive_thread_mutex_t recursive_mutex_
 Recursive mutex. More...

int removed_
 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... More...


Private Methods

void operator= (const ACE_Recursive_Thread_Mutex &)
 ACE_Recursive_Thread_Mutex (const ACE_Recursive_Thread_Mutex &)

Detailed Description

Implement a C++ wrapper that allows nested acquisition and release of a mutex that occurs in the same thread.

Definition at line 1336 of file Synch.h.


Constructor & Destructor Documentation

ACE_Recursive_Thread_Mutex::ACE_Recursive_Thread_Mutex const ACE_TCHAR   name = 0,
ACE_mutexattr_t *    arg = 0
 

Initialize a recursive mutex.

Definition at line 452 of file Synch.cpp.

References ACE_ERROR, ACE_LIB_TEXT, ACE_TCHAR, LM_ERROR, and ACE_OS::recursive_mutex_init.

00454   : removed_ (0)
00455 {
00456   // ACE_TRACE ("ACE_Recursive_Thread_Mutex::ACE_Recursive_Thread_Mutex");
00457 #if defined (ACE_HAS_FSU_PTHREADS) && ! defined (ACE_WIN32)
00458   // Initialize FSU pthreads package.  If called more than once,
00459   // pthread_init does nothing and so does no harm.
00460    pthread_init ();
00461 #endif  /*  ACE_HAS_FSU_PTHREADS && ! ACE_WIN32 */
00462    if (ACE_OS::recursive_mutex_init (&this->recursive_mutex_,
00463                                      name,
00464                                      arg) == -1)
00465      ACE_ERROR ((LM_ERROR,
00466                  ACE_LIB_TEXT ("%p\n"),
00467                  ACE_LIB_TEXT ("recursive_mutex_init")));
00468 }

ACE_Recursive_Thread_Mutex::~ACE_Recursive_Thread_Mutex void   
 

Implicitly release a recursive mutex.

Definition at line 472 of file Synch.cpp.

References remove.

00473 {
00474   // ACE_TRACE ("ACE_Recursive_Thread_Mutex::~ACE_Recursive_Thread_Mutex");
00475   this->remove ();
00476 }

ACE_Recursive_Thread_Mutex::ACE_Recursive_Thread_Mutex const ACE_Recursive_Thread_Mutex &    [private]
 

Definition at line 540 of file Synch.cpp.

00541 {
00542 }


Member Function Documentation

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 545 of file Synch.cpp.

References ACE_OS::recursive_mutex_lock.

Referenced by ACE_Log_Msg::acquire.

00546 {
00547   return ACE_OS::recursive_mutex_lock (&this->recursive_mutex_);
00548 }

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.

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.

void ACE_Recursive_Thread_Mutex::dump void    const
 

Dump the state of an object.

Definition at line 563 of file Synch.cpp.

References ACE_BEGIN_DUMP, ACE_DEBUG, ACE_END_DUMP, and LM_DEBUG.

00564 {
00565 // ACE_TRACE ("ACE_Recursive_Thread_Mutex::dump");
00566 
00567   ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this));
00568   ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP));
00569 }

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.

Definition at line 514 of file Synch.cpp.

References ACE_OS::mutex_lock, ACE_OS::mutex_unlock, ACE_recursive_thread_mutex_t::nesting_level_, and recursive_mutex_.

00515 {
00516   // ACE_TRACE ("ACE_Recursive_Thread_Mutex::get_nesting_level");
00517 #if defined (ACE_HAS_WINCE) || defined (VXWORKS) || defined (ACE_PSOS)
00518   ACE_NOTSUP_RETURN (-1);
00519 #elif defined (ACE_HAS_RECURSIVE_MUTEXES)
00520   // Nothing inside of a CRITICAL_SECTION object should ever be
00521   // accessed directly.  It is documented to change at any time.
00522 # if defined (ACE_WIN64)
00523   // Things are different on Windows XP 64-bit
00524   return this->recursive_mutex_.LockCount + 1;
00525 # elif defined (ACE_WIN32)
00526   // This is really a Win32-ism...
00527   return this->recursive_mutex_.RecursionCount;
00528 # else
00529   ACE_NOTSUP_RETURN (-1);
00530 # endif /* ACE_HAS_RECURSIVE_MUTEXES */
00531 #else
00532   int nesting_level = 0;
00533   ACE_OS::mutex_lock (&this->recursive_mutex_.nesting_mutex_);
00534   nesting_level = this->recursive_mutex_.nesting_level_;
00535   ACE_OS::mutex_unlock (&this->recursive_mutex_.nesting_mutex_);
00536   return nesting_level;
00537 #endif /* !ACE_HAS_WINCE */
00538 }

ACE_thread_mutex_t& ACE_Recursive_Thread_Mutex::get_nesting_mutex void   
 

Returns a reference to the recursive mutex's internal mutex;.

Referenced by ACE_Condition< ACE_Recursive_Thread_Mutex >::wait.

ACE_thread_t ACE_Recursive_Thread_Mutex::get_thread_id void   
 

Return the id of the thread that currently owns the mutex.

Definition at line 494 of file Synch.cpp.

References ACE_thread_t, ENOTSUP, ACE_OS::mutex_lock, ACE_OS::mutex_unlock, ACE_OS::NULL_thread, ACE_recursive_thread_mutex_t::owner_id_, and recursive_mutex_.

00495 {
00496   // ACE_TRACE ("ACE_Recursive_Thread_Mutex::get_thread_id");
00497 #if defined (ACE_HAS_RECURSIVE_MUTEXES)
00498   // @@ The structure CriticalSection in Win32 doesn't hold the thread
00499   // handle of the thread that owns the lock.  However it is still not
00500   // clear at this point how to translate a thread handle to its
00501   // corresponding thread id.
00502   errno = ENOTSUP;
00503   return ACE_OS::NULL_thread;
00504 #else
00505   ACE_thread_t owner_id;
00506   ACE_OS::mutex_lock (&this->recursive_mutex_.nesting_mutex_);
00507   owner_id = this->recursive_mutex_.owner_id_;
00508   ACE_OS::mutex_unlock (&this->recursive_mutex_.nesting_mutex_);
00509   return owner_id;
00510 #endif /* ACE_WIN32 */
00511 }

ACE_recursive_thread_mutex_t& ACE_Recursive_Thread_Mutex::mutex void   
 

Returns a reference to the recursive mutex;.

Referenced by ACE_Condition< ACE_Recursive_Thread_Mutex >::wait.

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 551 of file Synch.cpp.

References ACE_OS::recursive_mutex_unlock.

Referenced by ACE_Log_Msg::release.

00552 {
00553   return ACE_OS::recursive_mutex_unlock (&this->recursive_mutex_);
00554 }

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.

Definition at line 479 of file Synch.cpp.

References ACE_OS::recursive_mutex_destroy, and removed_.

Referenced by ~ACE_Recursive_Thread_Mutex.

00480 {
00481 // ACE_TRACE ("ACE_Recursive_Thread_Mutex::remove");
00482   int result = 0;
00483   if (this->removed_ == 0)
00484     {
00485       this->removed_ = 1;
00486       result = ACE_OS::recursive_mutex_destroy (&this->recursive_mutex_);
00487     }
00488   return result;
00489 }

void ACE_Recursive_Thread_Mutex::set_thread_id ACE_thread_t    t [protected]
 

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 557 of file Synch.cpp.

References ACE_OS::recursive_mutex_trylock.

00558 {
00559   return ACE_OS::recursive_mutex_trylock (&this->recursive_mutex_);
00560 }

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>.

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>.

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.


Member Data Documentation

ACE_Recursive_Thread_Mutex::ACE_ALLOC_HOOK_DECLARE
 

Declare the dynamic allocation hooks.

Definition at line 1437 of file Synch.h.

ACE_recursive_thread_mutex_t ACE_Recursive_Thread_Mutex::recursive_mutex_ [protected]
 

Recursive mutex.

Definition at line 1444 of file Synch.h.

Referenced by get_nesting_level, and get_thread_id.

int 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 1451 of file Synch.h.

Referenced by remove.


The documentation for this class was generated from the following files:
Generated on Mon Jun 16 12:54:58 2003 for ACE by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002