aboutsummaryrefslogtreecommitdiff
path: root/src/itocondition.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/itocondition.cpp')
-rw-r--r--src/itocondition.cpp42
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
5Bu::ItoCondition::ItoCondition()
6{
7 pthread_cond_init( &cond, NULL );
8}
9
10Bu::ItoCondition::~ItoCondition()
11{
12 pthread_cond_destroy( &cond );
13}
14
15int Bu::ItoCondition::wait()
16{
17 return pthread_cond_wait( &cond, &mutex );
18}
19
20int 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
33int Bu::ItoCondition::signal()
34{
35 return pthread_cond_signal( &cond );
36}
37
38int Bu::ItoCondition::broadcast()
39{
40 return pthread_cond_broadcast( &cond );
41}
42