DCL 4.0
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 337 of file Thread.h.

Constructor & Destructor Documentation

◆ CondVar()

Thread::CondVar::CondVar ( )

Definition at line 579 of file Thread.cpp.

580{
581 __bWaiting = false;
582#if __DCL_PTHREAD
583 __DCL_VERIFY(pthread_cond_init(&__cond, NULL) == 0);
584#elif __DCL_WINDOWS && _WIN32_WINNT >= 0x0600
585 // Windows Vista, Windows Server 2008
586 __DCL_ASSERT(IsWindowsVistaOrGreater());
587 InitializeConditionVariable(&__cond);
588#endif
589
590}
#define NULL
Definition Config.h:340
#define __DCL_VERIFY(expr)
Definition Object.h:373
#define __DCL_ASSERT(expr)
Definition Object.h:371

◆ ~CondVar()

Thread::CondVar::~CondVar ( )

Definition at line 592 of file Thread.cpp.

593{
594#if __DCL_PTHREAD
595 __DCL_VERIFY(pthread_cond_destroy(&__cond) == 0);
596#endif
597}

Member Function Documentation

◆ isWaiting()

bool Thread::CondVar::isWaiting ( )
inline

Definition at line 367 of file Thread.h.

367{ return __bWaiting; }

◆ signal()

void Thread::CondVar::signal ( )

Definition at line 599 of file Thread.cpp.

600{
601#if __DCL_PTHREAD
602 __DCL_VERIFY(pthread_cond_signal(&__cond) == 0);
603#elif __DCL_WINDOWS
604 #if _WIN32_WINNT >= 0x0600
605 WakeConditionVariable(&__cond);
606 #else
607 __cond.set();
608 #endif
609#endif
610}

◆ 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 623 of file Thread.cpp.

624{
625 bool r = true;
626 __bWaiting = true;
627#if __DCL_PTHREAD
628 // INFINITE == -1
629 if (_milliseconds == (unsigned int) INFINITE) {
630 __DCL_VERIFY(pthread_cond_wait(&__cond, (pthread_mutex_t*)&_mutex) == 0);
631 r = true;
632 }
633 else {
634 // millisoconds 1/1000
635 // microseconds 1/1000000
636 // nanoseconds 1/1000000000
637 struct timeval tv;
638 struct timezone tz;
639 struct timespec ts;
640 __DCL_VERIFY(gettimeofday(&tv, &tz) == 0);
641 ts.tv_sec = tv.tv_sec + (_milliseconds / 1000);
642 ts.tv_nsec = (tv.tv_usec * 1000) + ((_milliseconds % 1000) * 1000000);
643 int n = pthread_cond_timedwait(&__cond, (pthread_mutex_t*)&_mutex, &ts);
644 if (n != 0)
645 {
646 r = false;
647 __DCL_ASSERT(n == ETIMEDOUT);
648 errno = n;
649 }
650 }
651#elif __DCL_WINDOWS
652 #if _WIN32_WINNT >= 0x0600
653 if (!SleepConditionVariableCS(&__cond,
654 (CRITICAL_SECTION*)&_mutex, _milliseconds)) {
655 r = false;
656 __DCL_ASSERT(GetLastError() == ERROR_TIMEOUT);
657 }
658 #else
659 _mutex.unlock();
660 r = __cond.wait(INFINITE);
661 _mutex.lock();
662 if (r)
663 __cond.reset();
664 #endif
665#endif
666
667 __bWaiting = false;
668 return r;
669}
ByteString r
void CharsetConvertException *size_t n
Definition SQLField.cpp:253
#define INFINITE
Definition Thread.h:17

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