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 <sys/time.h>
00026
00027
00028 namespace Wefts {
00029
00042 class Cond
00043 {
00044 protected:
00046 pthread_cond_t m_cond;
00051 pthread_mutex_t *m_my_mutex;
00052
00053 protected:
00056 Cond() { pthread_cond_init( &m_cond, NULL ); }
00057 ~Cond() { pthread_cond_destroy( &m_cond ); }
00058
00059 public:
00064 virtual inline int wait() { return pthread_cond_wait( &m_cond, m_my_mutex ); }
00065
00066
00078 virtual inline int wait( long seconds, long nanoseconds)
00079 {
00080 struct timeval now;
00081 struct timespec timeout;
00082
00083 gettimeofday(&now, NULL);
00084 timeout.tv_sec = now.tv_sec + seconds;
00085 timeout.tv_nsec = now.tv_usec * 1000 + nanoseconds;
00086 return pthread_cond_timedwait(&m_cond, m_my_mutex, &timeout);
00087 }
00088
00089
00096 inline int wait( double seconds )
00097 {
00098 return wait( long( seconds ),
00099 long( (seconds - long(seconds)) *1000000000l) );
00100 }
00101
00105 virtual inline void signal() { pthread_cond_broadcast( &m_cond ); }
00106 };
00107
00108 }
00109
00110 #endif
00111