00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef USE_NPTL
00024 #include <pthread.h>
00025 #else
00026 #include <nptl/pthread.h>
00027 #endif
00028 #include <unistd.h>
00029 #include <time.h>
00030 #include <sys/time.h>
00031
00032
00033 #ifndef CONDITION_HH
00034 #define CONDITION_HH
00035
00036
00040 class clCondition
00041 {
00042 pthread_cond_t pthcCond;
00043 public:
00047 clCondition() { pthread_cond_init(&pthcCond, NULL); }
00051 ~clCondition() { pthread_cond_destroy(&pthcCond); }
00061 bool Wait(pthread_mutex_t *pthmCond)
00062 {
00063 if (pthread_cond_wait(&pthcCond, pthmCond) == 0)
00064 {
00065 return true;
00066 }
00067 else
00068 {
00069 return false;
00070 }
00071 }
00079 bool Wait(pthread_mutex_t *pthmCond, int iCondTO)
00080 {
00081 struct timeval sTimeVal;
00082 struct timespec sTimeSpec;
00083 gettimeofday(&sTimeVal, NULL);
00084 sTimeSpec.tv_sec = sTimeVal.tv_sec + iCondTO / 1000;
00085 sTimeSpec.tv_nsec = (sTimeVal.tv_usec + iCondTO * 1000) %
00086 1000000 * 1000;
00087 if (pthread_cond_timedwait(&pthcCond, pthmCond,
00088 &sTimeSpec) == 0)
00089 {
00090 return true;
00091 }
00092 else
00093 {
00094 return false;
00095 }
00096 }
00102 void Notify()
00103 { pthread_cond_signal(&pthcCond); }
00109 void NotifyAll()
00110 { pthread_cond_broadcast(&pthcCond); }
00111 };
00112
00113 #endif
00114