Recursive_Thread_Mutex.cpp

Go to the documentation of this file.
00001 /**
00002  * @file Recursive_Thread_Mutex.cpp
00003  *
00004  * $Id: Recursive_Thread_Mutex.cpp 80826 2008-03-04 14:51:23Z wotte $
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, "$Id: Recursive_Thread_Mutex.cpp 80826 2008-03-04 14:51:23Z wotte $")
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_ (false)
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_TEXT ("%p\n"),
00037                  ACE_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_ == false)
00052     {
00053       this->removed_ = true;
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_HAS_VXTHREADS)
00086   ACE_NOTSUP_RETURN (-1);
00087 #elif defined (ACE_HAS_RECURSIVE_MUTEXES)
00088 # if defined (ACE_WIN32)
00089   // This is really a Win32-ism...
00090   // Nothing inside of a CRITICAL_SECTION object should ever be
00091   // accessed directly.  It is documented to change at any time.
00092   //
00093   // It has been reported that this this works for all three
00094   // architectures.  However, this does not work on Win64 before SP1.
00095   return this->lock_.RecursionCount;
00096 # else
00097   ACE_NOTSUP_RETURN (-1);
00098 # endif /* ACE_WIN32 */
00099 #else
00100   int nesting_level = 0;
00101   ACE_OS::mutex_lock (&this->lock_.nesting_mutex_);
00102   nesting_level = this->lock_.nesting_level_;
00103   ACE_OS::mutex_unlock (&this->lock_.nesting_mutex_);
00104   return nesting_level;
00105 #endif /* !ACE_HAS_WINCE */
00106 }
00107 
00108 ACE_Recursive_Thread_Mutex::ACE_Recursive_Thread_Mutex (const ACE_Recursive_Thread_Mutex &)
00109 {
00110 }
00111 
00112 void
00113 ACE_Recursive_Thread_Mutex::dump (void) const
00114 {
00115 #if defined (ACE_HAS_DUMP)
00116 // ACE_TRACE ("ACE_Recursive_Thread_Mutex::dump");
00117 
00118   ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this));
00119   ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP));
00120 #endif /* ACE_HAS_DUMP */
00121 }
00122 
00123 ACE_END_VERSIONED_NAMESPACE_DECL
00124 
00125 #endif /* ACE_HAS_THREADS */

Generated on Tue Feb 2 17:18:42 2010 for ACE by  doxygen 1.4.7