39 #include "osal/Util.hpp"
41 CCEC_OSAL_BEGIN_NAMESPACE
43 ConditionVariable::ConditionVariable() : cond(NULL), mutex(NULL), nativeHandle(NULL)
45 cond =
new Condition(
false);
48 pthread_cond_init( (pthread_cond_t *)
nativeHandle, NULL );
53 if (nativeHandle != NULL) {
54 pthread_cond_destroy((pthread_cond_t *) nativeHandle);
95 ret = pthread_cond_wait((pthread_cond_t *)nativeHandle,
102 struct timeval curTime;
103 memset(&curTime, 0,
sizeof(curTime));
104 gettimeofday(&curTime, NULL);
106 struct timespec wakeTime;
107 memset(&wakeTime, 0,
sizeof(wakeTime));
108 wakeTime.tv_nsec = curTime.tv_usec * 1000 + (timeout % 1000) * 1000000;
109 wakeTime.tv_sec = curTime.tv_sec + (timeout / 1000);
110 if (wakeTime.tv_nsec > 1000000000)
112 wakeTime.tv_nsec -= 1000000000;
116 ret = pthread_cond_timedwait((pthread_cond_t *)nativeHandle,
120 if ((ret != 0) && !cond->
isSet() && ret == ETIMEDOUT) {
135 void ConditionVariable::notify(
void)
139 pthread_cond_signal((pthread_cond_t *)nativeHandle);
143 void ConditionVariable::notifyAll(
void)
147 pthread_cond_broadcast((pthread_cond_t *)nativeHandle);
151 void * ConditionVariable::getNativeHandle(
void)
156 CCEC_OSAL_END_NAMESPACE