Recursive_Thread_Mutex.cpp

Go to the documentation of this file.
00001 /**
00002  * @file Recursive_Thread_Mutex.cpp
00003  *
00004  * Recursive_Thread_Mutex.cpp,v 4.10 2006/05/30 13:15:25 schmidt Exp
00005  *
00006  * Originally in Synch.cpp
00007  *
00008  * @author Douglas C. Schmidt <schmidt@cs.wustl.edu>
00009  */
00010 
00011 #include "ace/Recursive_Thread_Mutex.h"
00012 
00013 #if defined (ACE_HAS_THREADS)
00014 
00015 #if !defined (__ACE_INLINE__)
00016 #include "ace/Recursive_Thread_Mutex.inl"
00017 #endif /* __ACE_INLINE__ */
00018 
00019 #include "ace/Log_Msg.h"
00020 
00021 ACE_RCSID(ace, Recursive_Thread_Mutex, "Recursive_Thread_Mutex.cpp,v 4.10 2006/05/30 13:15:25 schmidt Exp")
00022 
00023 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00024 
00025 ACE_ALLOC_HOOK_DEFINE(ACE_Recursive_Thread_Mutex)
00026 
00027 ACE_Recursive_Thread_Mutex::ACE_Recursive_Thread_Mutex (const ACE_TCHAR *name,
00028                                                         ACE_mutexattr_t *arg)
00029   : removed_ (0)
00030 {
00031   // ACE_TRACE ("ACE_Recursive_Thread_Mutex::ACE_Recursive_Thread_Mutex");
00032    if (ACE_OS::recursive_mutex_init (&this->lock_,
00033                                      name,
00034                                      arg) == -1)
00035      ACE_ERROR ((LM_ERROR,
00036                  ACE_LIB_TEXT ("%p\n"),
00037                  ACE_LIB_TEXT ("recursive_mutex_init")));
00038 }
00039 
00040 ACE_Recursive_Thread_Mutex::~ACE_Recursive_Thread_Mutex (void)
00041 {
00042   // ACE_TRACE ("ACE_Recursive_Thread_Mutex::~ACE_Recursive_Thread_Mutex");
00043   this->remove ();
00044 }
00045 
00046 int
00047 ACE_Recursive_Thread_Mutex::remove (void)
00048 {
00049 // ACE_TRACE ("ACE_Recursive_Thread_Mutex::remove");
00050   int result = 0;
00051   if (this->removed_ == 0)
00052     {
00053       this->removed_ = 1;
00054       result = ACE_OS::recursive_mutex_destroy (&this->lock_);
00055     }
00056   return result;
00057 }
00058 
00059 // The counter part of the following two functions for Win32 are
00060 // located in file Synch.i
00061 ACE_thread_t
00062 ACE_Recursive_Thread_Mutex::get_thread_id (void)
00063 {
00064   // ACE_TRACE ("ACE_Recursive_Thread_Mutex::get_thread_id");
00065 #if defined (ACE_HAS_RECURSIVE_MUTEXES)
00066   // @@ The structure CriticalSection in Win32 doesn't hold the thread
00067   // handle of the thread that owns the lock.  However it is still not
00068   // clear at this point how to translate a thread handle to its
00069   // corresponding thread id.
00070   errno = ENOTSUP;
00071   return ACE_OS::NULL_thread;
00072 #else
00073   ACE_thread_t owner_id;
00074   ACE_OS::mutex_lock (&this->lock_.nesting_mutex_);
00075   owner_id = this->lock_.owner_id_;
00076   ACE_OS::mutex_unlock (&this->lock_.nesting_mutex_);
00077   return owner_id;
00078 #endif /* ACE_WIN32 */
00079 }
00080 
00081 int
00082 ACE_Recursive_Thread_Mutex::get_nesting_level (void)
00083 {
00084   // ACE_TRACE ("ACE_Recursive_Thread_Mutex::get_nesting_level");
00085 #if defined (ACE_HAS_WINCE) || defined (ACE_VXWORKS) 
00086   ACE_NOTSUP_RETURN (-1);
00087 #elif defined (ACE_HAS_RECURSIVE_MUTEXES)
00088   // Nothing inside of a CRITICAL_SECTION object should ever be
00089   // accessed directly.  It is documented to change at any time.
00090 # if defined (ACE_WIN64) && !defined(_M_AMD64)
00091   // Things are different on Windows XP 64-bit. However, as of Feb 2006
00092   // Windows XP 64-bit edition on Intel EM64T w/ VC8, LockCount is
00093   // decremented at first acquire and then doesn't change. RecursionCount,
00094   // however, works the same as Win32, below.
00095   return this->lock_.LockCount + 1;
00096 # elif defined (ACE_WIN32)
00097   // This is really a Win32-ism...
00098   return this->lock_.RecursionCount;
00099 # else
00100   ACE_NOTSUP_RETURN (-1);
00101 # endif /* ACE_HAS_RECURSIVE_MUTEXES */
00102 #else
00103   int nesting_level = 0;
00104   ACE_OS::mutex_lock (&this->lock_.nesting_mutex_);
00105   nesting_level = this->lock_.nesting_level_;
00106   ACE_OS::mutex_unlock (&this->lock_.nesting_mutex_);
00107   return nesting_level;
00108 #endif /* !ACE_HAS_WINCE */
00109 }
00110 
00111 ACE_Recursive_Thread_Mutex::ACE_Recursive_Thread_Mutex (const ACE_Recursive_Thread_Mutex &)
00112 {
00113 }
00114 
00115 void
00116 ACE_Recursive_Thread_Mutex::dump (void) const
00117 {
00118 #if defined (ACE_HAS_DUMP)
00119 // ACE_TRACE ("ACE_Recursive_Thread_Mutex::dump");
00120 
00121   ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this));
00122   ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP));
00123 #endif /* ACE_HAS_DUMP */
00124 }
00125 
00126 ACE_END_VERSIONED_NAMESPACE_DECL
00127 
00128 #endif /* ACE_HAS_THREADS */

Generated on Thu Nov 9 09:42:01 2006 for ACE by doxygen 1.3.6