Go to the documentation of this file.00001 #ifndef MT_CONDITION_H
00002 #define MT_CONDITION_H
00003
00004 #include "base.h"
00005 #include "mutex.h"
00006
00007 #include <pthread.h>
00008
00009 namespace mt
00010 {
00011
00012 class condition
00013 {
00014 MT_PREVENT_COPY(condition)
00015
00016 public:
00017
00018 typedef condition this_type;
00019 typedef void base_type;
00020
00021 condition(void)
00022 {
00023 pthread_cond_init(&(this->c), 0);
00024 }
00025
00026 ~condition(void)
00027 {
00028 pthread_cond_destroy(&(this->c));
00029 }
00030
00031 void signal(void)
00032 {
00033 pthread_cond_signal(&(this->c));
00034 }
00035
00036 void broadcast(void)
00037 {
00038 pthread_cond_broadcast(&(this->c));
00039 }
00040
00041 void wait(mutex & m)
00042 {
00043 pthread_cond_wait(&(this->c), &(m.m));
00044 }
00045
00046 private:
00047
00048 pthread_cond_t c;
00049 };
00050
00051 }
00052
00053 #endif // MT_CONDITION_H