2 * @file Recursive_Thread_Mutex.cpp
4 * Originally in Synch.cpp
6 * @author Douglas C. Schmidt <d.schmidt@vanderbilt.edu>
9 #include "ace/Recursive_Thread_Mutex.h"
11 #if defined (ACE_HAS_THREADS)
13 #if !defined (__ACE_INLINE__)
14 #include "ace/Recursive_Thread_Mutex.inl"
15 #endif /* __ACE_INLINE__ */
17 #include "ace/Log_Category.h"
18 #if defined (ACE_HAS_ALLOC_HOOKS)
19 # include "ace/Malloc_Base.h"
20 #endif /* ACE_HAS_ALLOC_HOOKS */
22 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
24 ACE_ALLOC_HOOK_DEFINE(ACE_Recursive_Thread_Mutex
)
26 ACE_Recursive_Thread_Mutex::ACE_Recursive_Thread_Mutex (const ACE_TCHAR
*name
,
30 // ACE_TRACE ("ACE_Recursive_Thread_Mutex::ACE_Recursive_Thread_Mutex");
31 if (ACE_OS::recursive_mutex_init (&this->lock_
,
34 ACELIB_ERROR ((LM_ERROR
,
36 ACE_TEXT ("recursive_mutex_init")));
39 ACE_Recursive_Thread_Mutex::~ACE_Recursive_Thread_Mutex (void)
41 // ACE_TRACE ("ACE_Recursive_Thread_Mutex::~ACE_Recursive_Thread_Mutex");
46 ACE_Recursive_Thread_Mutex::remove (void)
48 // ACE_TRACE ("ACE_Recursive_Thread_Mutex::remove");
50 if (this->removed_
== false)
52 this->removed_
= true;
53 result
= ACE_OS::recursive_mutex_destroy (&this->lock_
);
58 // The counter part of the following two functions for Win32 are
59 // located in file Synch.i
61 ACE_Recursive_Thread_Mutex::get_thread_id (void)
63 // ACE_TRACE ("ACE_Recursive_Thread_Mutex::get_thread_id");
64 #if defined (ACE_HAS_RECURSIVE_MUTEXES)
65 // @@ The structure CriticalSection in Win32 doesn't hold the thread
66 // handle of the thread that owns the lock. However it is still not
67 // clear at this point how to translate a thread handle to its
68 // corresponding thread id.
70 return ACE_OS::NULL_thread
;
72 ACE_thread_t owner_id
;
73 ACE_OS::mutex_lock (&this->lock_
.nesting_mutex_
);
74 owner_id
= this->lock_
.owner_id_
;
75 ACE_OS::mutex_unlock (&this->lock_
.nesting_mutex_
);
77 #endif /* ACE_WIN32 */
81 ACE_Recursive_Thread_Mutex::get_nesting_level (void)
83 // ACE_TRACE ("ACE_Recursive_Thread_Mutex::get_nesting_level");
84 #if defined (ACE_HAS_VXTHREADS) || defined (ACE_HAS_PHARLAP) || defined (ACE_HAS_WINCE)
85 ACE_NOTSUP_RETURN (-1);
86 #elif defined (ACE_HAS_RECURSIVE_MUTEXES)
87 # if defined (ACE_WIN32)
88 // This is really a Win32-ism...
89 // Nothing inside of a CRITICAL_SECTION object should ever be
90 // accessed directly. It is documented to change at any time.
92 // It has been reported that this this works for all three
93 // architectures. However, this does not work on Win64 before SP1.
94 return this->lock_
.RecursionCount
;
96 ACE_NOTSUP_RETURN (-1);
97 # endif /* ACE_WIN32 */
99 int nesting_level
= 0;
100 ACE_OS::mutex_lock (&this->lock_
.nesting_mutex_
);
101 nesting_level
= this->lock_
.nesting_level_
;
102 ACE_OS::mutex_unlock (&this->lock_
.nesting_mutex_
);
103 return nesting_level
;
104 #endif /* !ACE_HAS_WINCE */
108 ACE_Recursive_Thread_Mutex::dump (void) const
110 #if defined (ACE_HAS_DUMP)
111 // ACE_TRACE ("ACE_Recursive_Thread_Mutex::dump");
113 ACELIB_DEBUG ((LM_DEBUG
, ACE_BEGIN_DUMP
, this));
114 ACELIB_DEBUG ((LM_DEBUG
, ACE_END_DUMP
));
115 #endif /* ACE_HAS_DUMP */
118 ACE_END_VERSIONED_NAMESPACE_DECL
120 #endif /* ACE_HAS_THREADS */