00001
00002
00003
00004
00005
00006
00007
00008 #ifndef __condition_h
00009 #define __condition_h
00010
00011 #include <common/synchronizer.h>
00012
00013 __BEGIN_SYS
00014
00015 class Condition: public Synchronizer_Common
00016 {
00017 private:
00018 typedef Traits<Condition> Traits;
00019 static const Type_Id TYPE = Type<Condition>::TYPE;
00020
00021 public:
00022 Condition() : _not_condition(true), _broadcast(0), _time_stamp(1) {
00023 db<Condition>(TRC) << "Condition()\n";
00024 }
00025 ~Condition() {
00026 db<Condition>(TRC) << "~Condition()\n";
00027 }
00028
00029 void wait() {
00030 db<Condition>(TRC) << "Condition::wait()\n";
00031 int ts = inc(_time_stamp);
00032 while(tsl(_not_condition) && (ts <= _broadcast))
00033 sleep();
00034 }
00035 void signal() {
00036 db<Condition>(TRC) << "Condition::signal()\n";
00037 _not_condition = false;
00038 wakeup();
00039 }
00040 void broadcast() {
00041 db<Condition>(TRC) << "Condition::broadcast()\n";
00042 _broadcast = _time_stamp;
00043 wakeupAll();
00044 }
00045
00046 static int init(System_Info * si);
00047
00048 private:
00049 volatile bool _not_condition;
00050 volatile int _broadcast;
00051 volatile int _time_stamp;
00052 };
00053
00054 __END_SYS
00055
00056 #endif