Changes to attempt to silence bcc64x
[ACE_TAO.git] / ACE / ace / Recursive_Thread_Mutex.cpp
blobd75cf7d83547d4ae0bc2b2ac3ebc5f9bed1faaa6
1 /**
2 * @file Recursive_Thread_Mutex.cpp
4 * @author Douglas C. Schmidt <d.schmidt@vanderbilt.edu>
5 */
7 #include "ace/Recursive_Thread_Mutex.h"
9 #if defined (ACE_HAS_THREADS)
11 #if !defined (__ACE_INLINE__)
12 #include "ace/Recursive_Thread_Mutex.inl"
13 #endif /* __ACE_INLINE__ */
15 #include "ace/Log_Category.h"
16 #if defined (ACE_HAS_ALLOC_HOOKS)
17 # include "ace/Malloc_Base.h"
18 #endif /* ACE_HAS_ALLOC_HOOKS */
20 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
22 ACE_ALLOC_HOOK_DEFINE(ACE_Recursive_Thread_Mutex)
24 ACE_Recursive_Thread_Mutex::ACE_Recursive_Thread_Mutex (const ACE_TCHAR *name,
25 ACE_mutexattr_t *arg)
26 : removed_ (false)
28 // ACE_TRACE ("ACE_Recursive_Thread_Mutex::ACE_Recursive_Thread_Mutex");
29 if (ACE_OS::recursive_mutex_init (&this->lock_,
30 name,
31 arg) == -1)
32 ACELIB_ERROR ((LM_ERROR,
33 ACE_TEXT ("%p\n"),
34 ACE_TEXT ("recursive_mutex_init")));
37 ACE_Recursive_Thread_Mutex::~ACE_Recursive_Thread_Mutex ()
39 // ACE_TRACE ("ACE_Recursive_Thread_Mutex::~ACE_Recursive_Thread_Mutex");
40 this->remove ();
43 int
44 ACE_Recursive_Thread_Mutex::remove ()
46 // ACE_TRACE ("ACE_Recursive_Thread_Mutex::remove");
47 int result = 0;
48 if (!this->removed_)
50 this->removed_ = true;
51 result = ACE_OS::recursive_mutex_destroy (&this->lock_);
53 return result;
56 // The counter part of the following two functions for Win32 are
57 // located in file Synch.i
58 ACE_thread_t
59 ACE_Recursive_Thread_Mutex::get_thread_id ()
61 // ACE_TRACE ("ACE_Recursive_Thread_Mutex::get_thread_id");
62 #if defined (ACE_HAS_RECURSIVE_MUTEXES)
63 // @@ The structure CriticalSection in Win32 doesn't hold the thread
64 // handle of the thread that owns the lock. However it is still not
65 // clear at this point how to translate a thread handle to its
66 // corresponding thread id.
67 errno = ENOTSUP;
68 return ACE_OS::NULL_thread;
69 #else
70 ACE_thread_t owner_id;
71 ACE_OS::mutex_lock (&this->lock_.nesting_mutex_);
72 owner_id = this->lock_.owner_id_;
73 ACE_OS::mutex_unlock (&this->lock_.nesting_mutex_);
74 return owner_id;
75 #endif /* ACE_WIN32 */
78 int
79 ACE_Recursive_Thread_Mutex::get_nesting_level ()
81 // ACE_TRACE ("ACE_Recursive_Thread_Mutex::get_nesting_level");
82 #if defined (ACE_HAS_VXTHREADS)
83 ACE_NOTSUP_RETURN (-1);
84 #elif defined (ACE_HAS_RECURSIVE_MUTEXES)
85 # if defined (ACE_WIN32)
86 // This is really a Win32-ism...
87 // Nothing inside of a CRITICAL_SECTION object should ever be
88 // accessed directly. It is documented to change at any time.
90 // It has been reported that this this works for all three
91 // architectures. However, this does not work on Win64 before SP1.
92 return this->lock_.RecursionCount;
93 # else
94 ACE_NOTSUP_RETURN (-1);
95 # endif /* ACE_WIN32 */
96 #else
97 int nesting_level = 0;
98 ACE_OS::mutex_lock (&this->lock_.nesting_mutex_);
99 nesting_level = this->lock_.nesting_level_;
100 ACE_OS::mutex_unlock (&this->lock_.nesting_mutex_);
101 return nesting_level;
102 #endif /* ACE_HAS_VXTHREADS */
105 void
106 ACE_Recursive_Thread_Mutex::dump () const
108 #if defined (ACE_HAS_DUMP)
109 // ACE_TRACE ("ACE_Recursive_Thread_Mutex::dump");
111 ACELIB_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this));
112 ACELIB_DEBUG ((LM_DEBUG, ACE_END_DUMP));
113 #endif /* ACE_HAS_DUMP */
116 ACE_END_VERSIONED_NAMESPACE_DECL
118 #endif /* ACE_HAS_THREADS */