00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include "selectThreadImpl.h"
00016
00017 #ifdef HAVE_POSIX_THREADS
00018
00019 #include "conditionVarPosixImpl.h"
00020 #include <sys/time.h>
00021
00022
00023
00024
00025
00026
00027 void ConditionVarPosixImpl::
00028 wait(double timeout) {
00029
00030
00031 struct timeval now;
00032 gettimeofday(&now, NULL);
00033
00034
00035 struct timespec ts;
00036 ts.tv_sec = now.tv_sec;
00037 ts.tv_nsec = now.tv_usec * 1000;
00038
00039 int seconds = (int)floor(timeout);
00040 ts.tv_sec += seconds;
00041 ts.tv_nsec += (int)((timeout - seconds) * 1000000.0);
00042 if (ts.tv_nsec > 1000000) {
00043 ts.tv_nsec -= 1000000;
00044 ++ts.tv_sec;
00045 }
00046
00047 int result = pthread_cond_timedwait(&_cvar, &_mutex._lock, &ts);
00048 #ifndef NDEBUG
00049 if (result != 0 && result != ETIMEDOUT) {
00050 pipeline_cat.error()
00051 << "Unexpected error " << result << " from pthread_cond_timedwait()\n";
00052 }
00053 #endif
00054 }
00055
00056 #endif // HAVE_POSIX_THREADS