X-Git-Url: https://bilbo.iut-bm.univ-fcomte.fr/and/gitweb/loba.git/blobdiff_plain/3547772c2f2424e6b3f7d4b7414e939947e7c3f4..612a491138746843a9fe0df8551e6ccf6ea2cf27:/synchro.h?ds=sidebyside diff --git a/synchro.h b/synchro.h index a2e86f3..07897e0 100644 --- a/synchro.h +++ b/synchro.h @@ -1,6 +1,7 @@ #ifndef SYNCHRO_H #define SYNCHRO_H +#include #include class mutex_t { @@ -23,8 +24,17 @@ public: void broadcast() { xbt_cond_broadcast(cond); } void signal() { xbt_cond_signal(cond); } void wait(mutex_t& mutex) { xbt_cond_wait(cond, mutex.mutex); } - void timedwait(mutex_t& mutex, double delay) { - xbt_cond_timedwait(cond, mutex.mutex, delay); + bool timedwait(mutex_t& mutex, double delay) { + try { + xbt_cond_timedwait(cond, mutex.mutex, delay); + } + catch (const xbt_ex& e) { + if (e.category != timeout_error) + throw; + mutex.acquire(); + return false; // got a timeout + } + return true; } private: