00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef WT_COND_H
00022 #define WT_COND_H
00023
00024 #include <wefts_mutex.h>
00025 #include <wefts_cleancond.h>
00026
00027 namespace Wefts {
00028
00045 class Condition
00046 {
00047 protected:
00049 OSCondition m_cond;
00054 Mutex *m_my_mutex;
00055
00056
00057 public:
00060 Condition( Mutex *mtx=0 )
00061 {
00062 m_my_mutex = mtx;
00063 }
00064
00065 ~Condition() {}
00066
00076 virtual inline bool wait( CleanupHandler *cup = 0, int pos = 0 ) {
00077 CleanupItem clup( cup, pos, this );
00078 return m_cond.wait( m_my_mutex->m_mutex, clup );
00079 }
00080
00088 void setMutex( Mutex *mtx) { m_my_mutex = mtx; }
00089
00090 Mutex *getMutex() { return m_my_mutex; }
00091
00110 virtual inline bool wait( long seconds, long nanoseconds, CleanupHandler *cup = 0, int pos = 0)
00111 {
00112 CleanupItem clup( cup, pos, this );
00113 return m_cond.timedWait( m_my_mutex->m_mutex, seconds, nanoseconds, clup );
00114 }
00115
00116
00128 inline bool wait( double seconds, CleanupHandler *cup = 0, int pos = 0 )
00129 {
00130 return wait( long( seconds ),
00131 long( (seconds - long(seconds)) *1000000000l), cup, pos );
00132 }
00133
00137 virtual inline void signal() { m_cond.signal(); }
00138
00149 virtual inline void signalOne() { m_cond.signalOne(); }
00150
00151 };
00152
00153 }
00154
00155 #endif
00156