00001 // -*- C++ -*- 00002 00003 //========================================================================== 00004 /** 00005 * @file Condition_Recursive_Thread_Mutex.h 00006 * 00007 * $Id: Condition_Recursive_Thread_Mutex.h 74005 2006-08-14 11:30:00Z johnnyw $ 00008 * 00009 * Moved from Synch.h. 00010 * 00011 * @author Douglas C. Schmidt <schmidt@cs.wustl.edu> 00012 */ 00013 //========================================================================== 00014 00015 #ifndef ACE_CONDITION_RECURSIVE_THREAD_MUTEX_H 00016 #define ACE_CONDITION_RECURSIVE_THREAD_MUTEX_H 00017 #include /**/ "ace/pre.h" 00018 00019 #include /**/ "ace/ACE_export.h" 00020 00021 #if !defined (ACE_LACKS_PRAGMA_ONCE) 00022 # pragma once 00023 #endif /* ACE_LACKS_PRAGMA_ONCE */ 00024 00025 #if !defined (ACE_HAS_THREADS) 00026 # include "ace/Null_Condition.h" 00027 #else /* ACE_HAS_THREADS */ 00028 #include "ace/Recursive_Thread_Mutex.h" 00029 00030 ACE_BEGIN_VERSIONED_NAMESPACE_DECL 00031 00032 template <class ACE_LOCK> class ACE_Condition; 00033 00034 /** 00035 * @class ACE_Condition<ACE_Recursive_Thread_Mutex> 00036 * 00037 * @brief ACE_Condition template specialization written using 00038 * @a ACE_Recursive_Thread_Mutex. This allows threads to block until 00039 * shared data changes state using recursive mutexes. 00040 */ 00041 template<> 00042 class ACE_Export ACE_Condition<ACE_Recursive_Thread_Mutex> 00043 { 00044 public: 00045 /// Initialize the condition variable with a recursive mutex. 00046 ACE_Condition (ACE_Recursive_Thread_Mutex &m); 00047 00048 /// Implicitly destroy the condition variable. 00049 ~ACE_Condition (void); 00050 00051 /** 00052 * Explicitly destroy the condition variable. Note that only one 00053 * thread should call this method since it doesn't protect against 00054 * race conditions. 00055 */ 00056 int remove (void); 00057 00058 /** 00059 * Block on condition, or until absolute time-of-day has passed. If 00060 * abstime == 0 use "blocking" <wait> semantics. Else, if <abstime> 00061 * != 0 and the call times out before the condition is signaled 00062 * <wait> returns -1 and sets errno to ETIME. 00063 */ 00064 int wait (const ACE_Time_Value *abstime = 0); 00065 00066 /** 00067 * Block on condition or until absolute time-of-day has passed. If 00068 * abstime == 0 use "blocking" wait() semantics on the recursive @a mutex 00069 * passed as a parameter (this is useful if you need to store the 00070 * <Condition> in shared memory). Else, if <abstime> != 0 and the 00071 * call times out before the condition is signaled <wait> returns -1 00072 * and sets errno to ETIME. 00073 */ 00074 int wait (ACE_Recursive_Thread_Mutex &mutex, 00075 const ACE_Time_Value *abstime = 0); 00076 00077 /// Signal one waiting thread. 00078 int signal (void); 00079 00080 /// Signal *all* waiting threads. 00081 int broadcast (void); 00082 00083 /// Returns a reference to the underlying mutex; 00084 ACE_Recursive_Thread_Mutex &mutex (void); 00085 00086 /// Dump the state of an object. 00087 void dump (void) const; 00088 00089 private: 00090 00091 // = Prevent assignment and copying. 00092 void operator= (const ACE_Condition<ACE_Recursive_Thread_Mutex> &); 00093 ACE_Condition (const ACE_Condition<ACE_Recursive_Thread_Mutex> &); 00094 00095 private: 00096 00097 /// A normal (i.e., non-recursive) condition variable. 00098 ACE_cond_t cond_; 00099 00100 /// Reference to the recursive mutex. 00101 ACE_Recursive_Thread_Mutex &mutex_; 00102 00103 }; 00104 00105 class ACE_Export ACE_Condition_Recursive_Thread_Mutex 00106 : public ACE_Condition<ACE_Recursive_Thread_Mutex> 00107 { 00108 public: 00109 /// Initialize the condition variable with a recursive mutex. 00110 ACE_Condition_Recursive_Thread_Mutex (ACE_Recursive_Thread_Mutex &m); 00111 }; 00112 00113 ACE_END_VERSIONED_NAMESPACE_DECL 00114 00115 #endif /* !ACE_HAS_THREADS */ 00116 00117 #include /**/ "ace/post.h" 00118 #endif /* ACE_CONDITION_RECURSIVE_THREAD_MUTEX_H */