Condition_Recursive_Thread_Mutex.cpp

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 /**
00004  * @file Condition_Recursive_Thread_Mutex.cpp
00005  *
00006  * Condition_Recursive_Thread_Mutex.cpp,v 4.8 2005/10/28 16:14:51 ossama Exp
00007  *
00008  * Originally in Synch.cpp
00009  *
00010  * @author Douglas C. Schmidt <schmidt@cs.wustl.edu>
00011  */
00012 
00013 #include "ace/Condition_Recursive_Thread_Mutex.h"
00014 
00015 #if defined (ACE_HAS_THREADS)
00016 
00017 #if defined (ACE_HAS_DUMP)
00018 #  include "ace/Log_Msg.h"
00019 #endif /* ACE_HAS_DUMP */
00020 
00021 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00022 
00023 int
00024 ACE_Condition<ACE_Recursive_Thread_Mutex>::remove (void)
00025 {
00026   return ACE_OS::cond_destroy (&this->cond_);
00027 }
00028 
00029 void
00030 ACE_Condition<ACE_Recursive_Thread_Mutex>::dump (void) const
00031 {
00032 #if defined (ACE_HAS_DUMP)
00033 // ACE_TRACE ("ACE_Condition<MUTEX>::dump");
00034 
00035   ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this));
00036   // No dump method for ACE_cond_t even in emulated mode.
00037   // cond_.dump ();
00038   this->mutex_.dump ();
00039   ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT ("\n")));
00040   ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP));
00041 #endif /* ACE_HAS_DUMP */
00042 }
00043 
00044 ACE_Condition<ACE_Recursive_Thread_Mutex>::~ACE_Condition (void)
00045 {
00046   this->remove ();
00047 }
00048 
00049 ACE_Condition<ACE_Recursive_Thread_Mutex>::ACE_Condition (ACE_Recursive_Thread_Mutex &m)
00050   : mutex_ (m)
00051 {
00052   ACE_OS::cond_init (&this->cond_);
00053 }
00054 
00055 int
00056 ACE_Condition<ACE_Recursive_Thread_Mutex>::wait (const ACE_Time_Value *abstime)
00057 {
00058   return this->wait (this->mutex_, abstime);
00059 }
00060 
00061 int
00062 ACE_Condition<ACE_Recursive_Thread_Mutex>::wait (ACE_Recursive_Thread_Mutex &mutex,
00063                                                  const ACE_Time_Value *abstime)
00064 {
00065   ACE_recursive_mutex_state mutex_state_holder;
00066   ACE_recursive_thread_mutex_t &recursive_mutex = mutex.mutex ();
00067 
00068   if (ACE_OS::recursive_mutex_cond_unlock (&recursive_mutex,
00069                                            mutex_state_holder) == -1)
00070     return -1;
00071 
00072   // We wait on the condition, specifying the nesting mutex. For platforms
00073   // with ACE_HAS_RECURSIVE_MUTEXES, this is the recursive mutex itself,
00074   // and is the same as recursive_mutex, above. The caller should have been
00075   // holding the lock on entry to this method, and it is still held.
00076   // For other platforms, this is the nesting mutex that guards the
00077   // ACE_recursive_mutex_t internals, and recursive_mutex_cond_unlock()
00078   // returned with the lock held, but waiters primed and waiting to be
00079   // released. At cond_wait below, the mutex will be released.
00080   // On return, it will be reacquired.
00081   const int result = abstime == 0
00082     ? ACE_OS::cond_wait (&this->cond_,
00083                          &mutex.get_nesting_mutex ())
00084     : ACE_OS::cond_timedwait (&this->cond_,
00085                               &mutex.get_nesting_mutex (),
00086                               const_cast <ACE_Time_Value *> (abstime));
00087   // We are holding the mutex, whether the wait succeeded or failed.
00088   // Stash errno (in case it failed) and then we need to reset the
00089   // recursive mutex state to what it was on entry to this method.
00090   // Resetting it may require a wait for another thread to release
00091   // the ACE_recursive_thread_mutex_t if this is a platform without
00092   // ACE_HAS_RECURSIVE_MUTEXES, and recursive_mutex_cond_relock() takes
00093   // care of that.
00094   {
00095     ACE_Errno_Guard error (errno);
00096     ACE_OS::recursive_mutex_cond_relock (&recursive_mutex,
00097                                          mutex_state_holder);
00098   }
00099 
00100   return result;
00101 }
00102 
00103 int
00104 ACE_Condition<ACE_Recursive_Thread_Mutex>::signal (void)
00105 {
00106   return ACE_OS::cond_signal (&this->cond_);
00107 }
00108 
00109 int
00110 ACE_Condition<ACE_Recursive_Thread_Mutex>::broadcast (void)
00111 {
00112   return ACE_OS::cond_broadcast (&this->cond_);
00113 }
00114 
00115 ACE_Recursive_Thread_Mutex &
00116 ACE_Condition<ACE_Recursive_Thread_Mutex>::mutex (void)
00117 {
00118   return this->mutex_;
00119 }
00120 
00121 ACE_Condition_Recursive_Thread_Mutex::ACE_Condition_Recursive_Thread_Mutex (
00122   ACE_Recursive_Thread_Mutex &m) :
00123     ACE_Condition<ACE_Recursive_Thread_Mutex> (m)
00124 {
00125 }
00126 
00127 ACE_END_VERSIONED_NAMESPACE_DECL
00128 
00129 #endif /* ACE_HAS_THREADS */

Generated on Thu Nov 9 09:41:48 2006 for ACE by doxygen 1.3.6