Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

Condition.h

Go to the documentation of this file.
00001 #ifndef __CONDITION_H
00002 #define __CONDITION_H
00003 
00010 
00011 #include "Mutex.h"
00012 #include "Guard.h"
00013 #include "TimeValue.h"
00014 
00015 class Condition 
00016 {
00017 public:
00021     Condition() {
00022         pthread_cond_init(&m_condition, NULL);
00023     }
00024 
00025 
00029     Condition::Condition(const Condition& c) {
00030         m_condition = c.m_condition;
00031     }
00032 
00033 
00037     ~Condition() {
00038         pthread_cond_destroy(&m_condition);
00039     }
00040 
00041 
00049     int wait() {
00050         Mutex tmp;
00051         Guard guard(&tmp);
00052         return wait(&tmp);
00053     }
00054 
00055 
00059     int wait(Mutex* mutex) {
00060         return pthread_cond_wait(&m_condition, mutex->getMutex());
00061     }
00062 
00063 
00067     int timedWait(Mutex* mutex, const struct timespec* timeToWait) {
00068         return pthread_cond_timedwait(&m_condition, mutex->getMutex(), timeToWait);
00069     }
00070 
00071 
00084     bool timedWait(Mutex* mutex, int milli) {
00085         TimeValue waitUntil = TimeValue::getCurrentTime() + TimeValue(0, milli * 1000);
00086         return (pthread_cond_timedwait(&m_condition, mutex->getMutex(), &(waitUntil.getTimespecStruct())) == 0);
00087     }  // fn timedWait
00088 
00089 
00090 
00094     int broadcast() {
00095         return pthread_cond_broadcast(&m_condition);
00096     }
00097 
00098 
00102     int signal() {
00103         return pthread_cond_signal(&m_condition);
00104     }
00105 
00106 protected:
00107     pthread_cond_t m_condition;
00108 };
00109 
00110 #endif
00111 

Generated at Thu Jul 11 13:31:49 2002 for Peekabooty by doxygen1.2.9 written by Dimitri van Heesch, © 1997-2001