1 #include "pthread/condition_variable.hpp"
6 pthread_cond_wait ( &_condition, &mtx.
_mutex);
16 return wait_for(*(lck._mutex), millis);
28 rc = pthread_cond_timedwait ( &_condition, &mtx.
_mutex, &timeout );
50 #if __cplusplus < 201103L
55 pthread_cond_signal ( &_condition );
58 #if __cplusplus < 201103L
63 pthread_cond_broadcast ( &_condition );
67 void condition_variable::milliseconds(
int millis){
70 if ( gettimeofday ( &now, NULL ) == 0){
71 timeout.tv_sec = now.tv_sec;
74 auto seconds = millis / 1000;
75 auto nanos = (now.tv_usec * 1000) + ((millis % 1000) * 1000000) ;
76 seconds += nanos / 1000000000 ;
77 nanos = nanos % 1000000000 ;
79 timeout.tv_sec += seconds ;
80 timeout.tv_nsec = nanos;
82 throw condition_variable_exception(
"failed to get current time.");
88 condition_variable::condition_variable () {
89 int rc = pthread_cond_init ( &_condition, NULL );
91 throw condition_variable_exception(
"pthread_cond_init failed.", rc);
95 condition_variable::~condition_variable () {
96 int rc = pthread_cond_destroy(&_condition);
98 throw pthread_exception(
"pthread condition variable destroy failed.", rc);
void notify_one() noexcept
void notify_all() noexcept
cv_status wait_for(mutex &mtx, int millis)