Exemplo n.º 1
0
 Conditional::Awoken Conditional::waitTimed(Mutex& mut, unsigned long timeout)
 {
   if(SleepConditionVariableCS (&cond_, &mut.nativeHandle(), timeout))
     return SIGNALED;
   else
   {
     int res = GetLastError();
     if((res == WAIT_TIMEOUT) || (res == ERROR_TIMEOUT))
       return TIMEDOUT;
     else
       throw ConditionalError();
   }
 }
Exemplo n.º 2
0
  Conditional::Awoken Conditional::waitTimed(Mutex& mut, unsigned long timeout)
  {
    struct timespec ts;
  
    // Get monotonic clock - current time
    clock_gettime(CLOCK_MONOTONIC, &ts);

    // Calculate new absolute time by getting current monotonic time and offsetting it
    size_t secs = timeout/1000;
    size_t msecs = timeout - secs*1000;

    ts.tv_sec += secs;
    ts.tv_nsec += msecs*1000000;
    size_t overflow = ts.tv_nsec/1000000000;
  
    if(overflow)
    {
      ts.tv_sec += overflow;
      ts.tv_nsec -= overflow*1000000000;
    }  

    int res = pthread_cond_timedwait(&cond_, &mut.nativeHandle(), &ts);
    
    switch(res)
    {
      case ETIMEDOUT:
        return TIMEDOUT;
        break;
        
      case 0:
        return SIGNALED;
        break;

      default:
        throw ConditionalError();
    }
  }
Exemplo n.º 3
0
 void Conditional::wait(Mutex& mut)
 {
   if(!SleepConditionVariableCS (&cond_, &mut.nativeHandle(), INFINITE)) throw ConditionalError();
 }