SASC-NG
DVBSoftCAM

cCondWait Class Reference

#include <thread.h>

List of all members.

Public Member Functions

 cCondWait (void)
 ~cCondWait ()
bool Wait (int TimeoutMs=0)
void Signal (void)
 Signals a caller of Wait() that the condition it is waiting for is met.

Static Public Member Functions

static void SleepMs (int TimeoutMs)

Detailed Description

Definition at line 17 of file thread.h.


Constructor & Destructor Documentation

cCondWait::cCondWait ( void  )

Definition at line 39 of file thread.cpp.

References NULL.

{
  signaled = false;
  pthread_mutex_init(&mutex, NULL);
  pthread_cond_init(&cond, NULL);
}
cCondWait::~cCondWait ( )

Definition at line 46 of file thread.cpp.

{
  pthread_cond_broadcast(&cond); // wake up any sleepers
  pthread_cond_destroy(&cond);
  pthread_mutex_destroy(&mutex);
}

Member Function Documentation

void cCondWait::Signal ( void  )

Signals a caller of Wait() that the condition it is waiting for is met.

Definition at line 81 of file thread.cpp.

{
  pthread_mutex_lock(&mutex);
  signaled = true;
  pthread_cond_broadcast(&cond);
  pthread_mutex_unlock(&mutex);
}
void cCondWait::SleepMs ( int  TimeoutMs) [static]

Creates a cCondWait object and uses it to sleep for TimeoutMs milliseconds, immediately giving up the calling thread's time slice and thus avoiding a "busy wait". In order to avoid a possible busy wait, TimeoutMs will be automatically limited to values >2.

Definition at line 53 of file thread.cpp.

References max(), and Wait().

Referenced by cSmartCardSlot::Action(), cScHousekeeper::Action(), cAction::Action(), cLogStats::Action(), cThread::Cancel(), cPipe::Close(), cSmartCardNagra::Decode(), cSmartCardSlotSerial::DeviceWrite(), cDeCsaTSBuffer::Get(), cSystemNagra2::ProcessECM(), cSystemNagra::ProcessECM(), cCam::Read(), cSmartCardSlot::Reset(), cThread::Start(), and cSmartCardNagra::Update().

{
  cCondWait w;
  w.Wait(max(TimeoutMs, 3)); // making sure the time is >2ms to avoid a possible busy wait
}
bool cCondWait::Wait ( int  TimeoutMs = 0)

Waits at most TimeoutMs milliseconds for a call to Signal(), or forever if TimeoutMs is 0.

Returns:
Returns true if Signal() has been called, false it the given timeout has expired.

Definition at line 59 of file thread.cpp.

References GetAbsTime().

Referenced by SleepMs().

{
  pthread_mutex_lock(&mutex);
  if (!signaled) {
     if (TimeoutMs) {
        struct timespec abstime;
        if (GetAbsTime(&abstime, TimeoutMs)) {
           while (!signaled) {
                 if (pthread_cond_timedwait(&cond, &mutex, &abstime) == ETIMEDOUT)
                    break;
                 }
           }
        }
     else
        pthread_cond_wait(&cond, &mutex);
     }
  bool r = signaled;
  signaled = false;
  pthread_mutex_unlock(&mutex);
  return r;
}

The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines