00001
00002
00003
00004
00005
00006
00007
00008
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
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
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
00043 this->remove ();
00044 }
00045
00046 int
00047 ACE_Recursive_Thread_Mutex::remove (void)
00048 {
00049
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
00060
00061 ACE_thread_t
00062 ACE_Recursive_Thread_Mutex::get_thread_id (void)
00063 {
00064
00065 #if defined (ACE_HAS_RECURSIVE_MUTEXES)
00066
00067
00068
00069
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
00079 }
00080
00081 int
00082 ACE_Recursive_Thread_Mutex::get_nesting_level (void)
00083 {
00084
00085 #if defined (ACE_HAS_WINCE) || defined (ACE_VXWORKS)
00086 ACE_NOTSUP_RETURN (-1);
00087 #elif defined (ACE_HAS_RECURSIVE_MUTEXES)
00088
00089
00090 # if defined (ACE_WIN64) && !defined(_M_AMD64)
00091
00092
00093
00094
00095 return this->lock_.LockCount + 1;
00096 # elif defined (ACE_WIN32)
00097
00098 return this->lock_.RecursionCount;
00099 # else
00100 ACE_NOTSUP_RETURN (-1);
00101 # endif
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
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
00120
00121 ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this));
00122 ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP));
00123 #endif
00124 }
00125
00126 ACE_END_VERSIONED_NAMESPACE_DECL
00127
00128 #endif