]> AND Private Git Repository - loba.git/blob - synchro.h
Logo AND Algorithmique Numérique Distribuée

Private GIT Repository
Try to make results more consistent.
[loba.git] / synchro.h
1 #ifndef SYNCHRO_H
2 #define SYNCHRO_H
3
4 #include <xbt/synchro.h>
5
6 class mutex_t {
7 public:
8     mutex_t()                   { mutex = xbt_mutex_init(); }
9     ~mutex_t()                  { xbt_mutex_destroy(mutex); }
10     void acquire()              { xbt_mutex_acquire(mutex); }
11     void release()              { xbt_mutex_release(mutex); }
12     xbt_mutex_t get()           { return mutex;             }
13
14 private:
15     xbt_mutex_t mutex;
16 };
17
18 class condition_t {
19 public:
20     condition_t()               { cond = xbt_cond_init();           }
21     ~condition_t()              { xbt_cond_destroy(cond);           }
22     void broadcast()            { xbt_cond_broadcast(cond);         }
23     void signal()               { xbt_cond_signal(cond);            }
24     void wait(mutex_t& mutex)   { xbt_cond_wait(cond, mutex.get()); }
25     void timedwait(mutex_t& mutex, double delay) {
26         xbt_cond_timedwait(cond, mutex.get(), delay);
27     }
28
29 private:
30     xbt_cond_t cond;
31 };
32
33 #endif // !SYNCHRO_H
34
35 // Local variables:
36 // mode: c++
37 // End: