diff options
Diffstat (limited to '')
| -rw-r--r-- | src/itocondition.cpp | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/src/itocondition.cpp b/src/itocondition.cpp new file mode 100644 index 0000000..d8f5375 --- /dev/null +++ b/src/itocondition.cpp | |||
| @@ -0,0 +1,42 @@ | |||
| 1 | #include <sys/time.h> | ||
| 2 | |||
| 3 | #include "itocondition.h" | ||
| 4 | |||
| 5 | Bu::ItoCondition::ItoCondition() | ||
| 6 | { | ||
| 7 | pthread_cond_init( &cond, NULL ); | ||
| 8 | } | ||
| 9 | |||
| 10 | Bu::ItoCondition::~ItoCondition() | ||
| 11 | { | ||
| 12 | pthread_cond_destroy( &cond ); | ||
| 13 | } | ||
| 14 | |||
| 15 | int Bu::ItoCondition::wait() | ||
| 16 | { | ||
| 17 | return pthread_cond_wait( &cond, &mutex ); | ||
| 18 | } | ||
| 19 | |||
| 20 | int Bu::ItoCondition::wait( int nSec, int nUSec ) | ||
| 21 | { | ||
| 22 | struct timeval now; | ||
| 23 | struct timespec timeout; | ||
| 24 | struct timezone tz; | ||
| 25 | |||
| 26 | gettimeofday( &now, &tz ); | ||
| 27 | timeout.tv_sec = now.tv_sec + nSec + ((now.tv_usec + nUSec)/1000000); | ||
| 28 | timeout.tv_nsec = ((now.tv_usec + nUSec)%1000000)*1000; | ||
| 29 | |||
| 30 | return pthread_cond_timedwait( &cond, &mutex, &timeout ); | ||
| 31 | } | ||
| 32 | |||
| 33 | int Bu::ItoCondition::signal() | ||
| 34 | { | ||
| 35 | return pthread_cond_signal( &cond ); | ||
| 36 | } | ||
| 37 | |||
| 38 | int Bu::ItoCondition::broadcast() | ||
| 39 | { | ||
| 40 | return pthread_cond_broadcast( &cond ); | ||
| 41 | } | ||
| 42 | |||
