DCL 3.7.4
Loading...
Searching...
No Matches
Thread::CondVar Class Reference

#include <Thread.h>

Public Member Functions

 CondVar ()
 ~CondVar ()
void signal ()
bool wait (Mutex &_mutex, unsigned int _milliseconds=INFINITE)
bool isWaiting ()

Detailed Description

CondVar: Conditional Variable Windows Note. Major Version >= 6, Vista, 2008 See. InitializeCondVaritionVariable

Definition at line 352 of file Thread.h.

Constructor & Destructor Documentation

◆ CondVar()

Thread::CondVar::CondVar ( )

Definition at line 618 of file Thread.cpp.

619{
620 __bWaiting = false;
621#if __DCL_PTHREAD
622 __DCL_VERIFY(pthread_cond_init(&__cond, NULL) == 0);
623#elif defined(__WINNT__) && _WIN32_WINNT >= 0x0600
624 // Windows Vista, Windows Server 2008
625 __DCL_ASSERT(IsWindowsVistaOrGreater());
626 InitializeConditionVariable(&__cond);
627#endif
628
629}
#define NULL
Definition Config.h:312
#define __DCL_VERIFY(expr)
Definition Object.h:396
#define __DCL_ASSERT(expr)
Definition Object.h:394

◆ ~CondVar()

Thread::CondVar::~CondVar ( )

Definition at line 631 of file Thread.cpp.

632{
633#if __DCL_PTHREAD
634 __DCL_VERIFY(pthread_cond_destroy(&__cond) == 0);
635#endif
636}

Member Function Documentation

◆ isWaiting()

bool Thread::CondVar::isWaiting ( )
inline

Definition at line 382 of file Thread.h.

382{ return __bWaiting; }

◆ signal()

void Thread::CondVar::signal ( )

Definition at line 638 of file Thread.cpp.

639{
640#if __DCL_PTHREAD
641 __DCL_VERIFY(pthread_cond_signal(&__cond) == 0);
642#elif defined(__WINNT__)
643 #if _WIN32_WINNT >= 0x0600
644 WakeConditionVariable(&__cond);
645 #else
646 __cond.set();
647 #endif
648#endif
649}

◆ wait()

bool Thread::CondVar::wait ( Mutex & _mutex,
unsigned int _milliseconds = INFINITE )
Returns
false는 timed-out Windows: GetLastError() == ERROR_TIMEOUT UNIX: errno == ETIMEDOUT

Definition at line 662 of file Thread.cpp.

663{
664 bool r = true;
665 __bWaiting = true;
666#if __DCL_PTHREAD
667 // INFINITE == -1
668 if (_milliseconds == (unsigned int) INFINITE) {
669 __DCL_VERIFY(pthread_cond_wait(&__cond, (pthread_mutex_t*)&_mutex) == 0);
670 r = true;
671 }
672 else {
673 // millisoconds 1/1000
674 // microseconds 1/1000000
675 // nanoseconds 1/1000000000
676 struct timeval tv;
677 struct timezone tz;
678 struct timespec ts;
679 __DCL_VERIFY(gettimeofday(&tv, &tz) == 0);
680 ts.tv_sec = tv.tv_sec + (_milliseconds / 1000);
681 ts.tv_nsec = (tv.tv_usec * 1000) + ((_milliseconds % 1000) * 1000000);
682 int n = pthread_cond_timedwait(&__cond, (pthread_mutex_t*)&_mutex, &ts);
683 if (n != 0) {
684 r = false;
685 __DCL_ASSERT(n == ETIMEDOUT);
686 errno = n;
687 }
688 }
689#elif defined(__WINNT__)
690 #if _WIN32_WINNT >= 0x0600
691 if (!SleepConditionVariableCS(&__cond,
692 (CRITICAL_SECTION*)&_mutex, _milliseconds)) {
693 r = false;
694 __DCL_ASSERT(GetLastError() == ERROR_TIMEOUT);
695 }
696 #else
697 _mutex.unlock();
698 r = __cond.wait(INFINITE);
699 _mutex.lock();
700 if (r)
701 __cond.reset();
702 #endif
703#endif
704
705 __bWaiting = false;
706 return r;
707}
IOException *size_t r
Definition MediaInfo.cpp:82
#define INFINITE
Definition Thread.h:34

The documentation for this class was generated from the following files: