Changes to attempt to silence bcc64x
[ACE_TAO.git] / ACE / ace / Condition_Recursive_Thread_Mutex.cpp
blob8b05327c5ac5affb162f306ffe31fc26cda58b1f
1 // -*- C++ -*-
3 /**
4 * @file Condition_Recursive_Thread_Mutex.cpp
6 * @author Douglas C. Schmidt <d.schmidt@vanderbilt.edu>
7 */
9 #include "ace/Condition_Recursive_Thread_Mutex.h"
11 #if defined (ACE_HAS_THREADS)
13 #include "ace/Log_Category.h"
15 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
17 int
18 ACE_Condition<ACE_Recursive_Thread_Mutex>::remove ()
20 return ACE_OS::cond_destroy (&this->cond_);
23 void
24 ACE_Condition<ACE_Recursive_Thread_Mutex>::dump () const
26 #if defined (ACE_HAS_DUMP)
27 // ACE_TRACE ("ACE_Condition<MUTEX>::dump");
29 ACELIB_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this));
30 // No dump method for ACE_cond_t even in emulated mode.
31 // cond_.dump ();
32 this->mutex_.dump ();
33 ACELIB_DEBUG ((LM_DEBUG, ACE_TEXT ("\n")));
34 ACELIB_DEBUG ((LM_DEBUG, ACE_END_DUMP));
35 #endif /* ACE_HAS_DUMP */
38 ACE_Condition<ACE_Recursive_Thread_Mutex>::~ACE_Condition ()
40 this->remove ();
43 ACE_Condition<ACE_Recursive_Thread_Mutex>::ACE_Condition (ACE_Recursive_Thread_Mutex &m)
44 : mutex_ (m)
46 if (ACE_OS::cond_init (&this->cond_) != 0)
47 ACELIB_ERROR ((LM_ERROR, ACE_TEXT ("%p\n"),
48 ACE_TEXT ("ACE_Condition<ACE_Recursive_Thread_Mutex>::ACE_Condition<ACE_Recursive_Thread_Mutex>")));
51 ACE_Condition<ACE_Recursive_Thread_Mutex>::ACE_Condition (ACE_Recursive_Thread_Mutex &m,
52 const ACE_Condition_Attributes &attributes)
53 : mutex_ (m)
55 if (ACE_OS::cond_init (&this->cond_,
56 const_cast<ACE_condattr_t &> (attributes.attributes ())) != 0)
57 ACELIB_ERROR ((LM_ERROR, ACE_TEXT ("%p\n"),
58 ACE_TEXT ("ACE_Condition<ACE_Recursive_Thread_Mutex>::ACE_Condition<ACE_Recursive_Thread_Mutex>")));
61 int
62 ACE_Condition<ACE_Recursive_Thread_Mutex>::wait (const ACE_Time_Value *abstime)
64 return this->wait (this->mutex_, abstime);
67 int
68 ACE_Condition<ACE_Recursive_Thread_Mutex>::wait (ACE_Recursive_Thread_Mutex &mutex,
69 const ACE_Time_Value *abstime)
71 ACE_recursive_mutex_state mutex_state_holder;
72 ACE_recursive_thread_mutex_t &recursive_mutex = mutex.lock ();
74 if (ACE_OS::recursive_mutex_cond_unlock (&recursive_mutex,
75 mutex_state_holder) == -1)
76 return -1;
78 // We wait on the condition, specifying the nesting mutex. For platforms
79 // with ACE_HAS_RECURSIVE_MUTEXES, this is the recursive mutex itself,
80 // and is the same as recursive_mutex, above. The caller should have been
81 // holding the lock on entry to this method, and it is still held.
82 // For other platforms, this is the nesting mutex that guards the
83 // ACE_recursive_mutex_t internals, and recursive_mutex_cond_unlock()
84 // returned with the lock held, but waiters primed and waiting to be
85 // released. At cond_wait below, the mutex will be released.
86 // On return, it will be reacquired.
87 int const result = abstime == 0
88 ? ACE_OS::cond_wait (&this->cond_,
89 &mutex.get_nesting_mutex ())
90 : ACE_OS::cond_timedwait (&this->cond_,
91 &mutex.get_nesting_mutex (),
92 const_cast <ACE_Time_Value *> (abstime));
93 // We are holding the mutex, whether the wait succeeded or failed.
94 // Stash errno (in case it failed) and then we need to reset the
95 // recursive mutex state to what it was on entry to this method.
96 // Resetting it may require a wait for another thread to release
97 // the ACE_recursive_thread_mutex_t if this is a platform without
98 // ACE_HAS_RECURSIVE_MUTEXES, and recursive_mutex_cond_relock() takes
99 // care of that.
101 ACE_Errno_Guard error (errno);
102 ACE_OS::recursive_mutex_cond_relock (&recursive_mutex,
103 mutex_state_holder);
106 return result;
110 ACE_Condition<ACE_Recursive_Thread_Mutex>::signal ()
112 return ACE_OS::cond_signal (&this->cond_);
116 ACE_Condition<ACE_Recursive_Thread_Mutex>::broadcast ()
118 return ACE_OS::cond_broadcast (&this->cond_);
121 ACE_Recursive_Thread_Mutex &
122 ACE_Condition<ACE_Recursive_Thread_Mutex>::mutex ()
124 return this->mutex_;
127 ACE_END_VERSIONED_NAMESPACE_DECL
129 #endif /* ACE_HAS_THREADS */