Removed ACE_HAS_BSTRING, not used
[ACE_TAO.git] / ACE / ace / Recursive_Thread_Mutex.cpp
blob7d379ab20b5f2d7382525ee322388c381fd0b2d9
1 /**
2 * @file Recursive_Thread_Mutex.cpp
4 * Originally in Synch.cpp
6 * @author Douglas C. Schmidt <d.schmidt@vanderbilt.edu>
7 */
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,
27 ACE_mutexattr_t *arg)
28 : removed_ (false)
30 // ACE_TRACE ("ACE_Recursive_Thread_Mutex::ACE_Recursive_Thread_Mutex");
31 if (ACE_OS::recursive_mutex_init (&this->lock_,
32 name,
33 arg) == -1)
34 ACELIB_ERROR ((LM_ERROR,
35 ACE_TEXT ("%p\n"),
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");
42 this->remove ();
45 int
46 ACE_Recursive_Thread_Mutex::remove (void)
48 // ACE_TRACE ("ACE_Recursive_Thread_Mutex::remove");
49 int result = 0;
50 if (this->removed_ == false)
52 this->removed_ = true;
53 result = ACE_OS::recursive_mutex_destroy (&this->lock_);
55 return result;
58 // The counter part of the following two functions for Win32 are
59 // located in file Synch.i
60 ACE_thread_t
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.
69 errno = ENOTSUP;
70 return ACE_OS::NULL_thread;
71 #else
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_);
76 return owner_id;
77 #endif /* ACE_WIN32 */
80 int
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;
95 # else
96 ACE_NOTSUP_RETURN (-1);
97 # endif /* ACE_WIN32 */
98 #else
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 */
107 void
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 */