X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/b96e1bf5be6e8238849ba847ddbd3f39a0c86188..cd5e6b169f6a55b9e913fe0f8ea3ec85fbb330bd:/src/xbt/xbt_os_thread.c diff --git a/src/xbt/xbt_os_thread.c b/src/xbt/xbt_os_thread.c index 73fe3a4fdc..81c86e9383 100644 --- a/src/xbt/xbt_os_thread.c +++ b/src/xbt/xbt_os_thread.c @@ -13,6 +13,7 @@ #include "xbt/sysdep.h" #include "xbt/ex.h" #include "portable.h" +#include "xbt/xbt_os_time.h" /* Portable time facilities */ #include "xbt/xbt_os_thread.h" /* This module */ #include "xbt_modinter.h" /* Initialization/finalization of this module */ @@ -165,6 +166,24 @@ void xbt_os_cond_wait(xbt_os_cond_t cond, xbt_os_mutex_t mutex) { cond,mutex, strerror(errcode)); } +#include +#include +void xbt_os_cond_timedwait(xbt_os_cond_t cond, xbt_os_mutex_t mutex, double delay) { + int errcode; + struct timespec ts_end; + double end = delay + xbt_os_time(); + ts_end.tv_sec = (time_t) floor(end); + ts_end.tv_nsec = (long) ( ( end - ts_end.tv_sec) * 1000000000); + switch ( (errcode=pthread_cond_timedwait(&(cond->c),&(mutex->m), &ts_end)) ) { + case ETIMEDOUT: + THROW3(timeout_error,errcode,"condition %p (mutex %p) wasn't signaled before timeout (%f)", + cond,mutex, delay); + default: + THROW4(system_error,errcode,"pthread_cond_timedwait(%p,%p,%f) failed: %s", + cond,mutex, delay, strerror(errcode)); + } +} + void xbt_os_cond_signal(xbt_os_cond_t cond) { int errcode; if ((errcode=pthread_cond_signal(&(cond->c)))) @@ -396,6 +415,9 @@ void xbt_os_cond_wait(xbt_os_cond_t cond, xbt_os_mutex_t mutex) { /* relock the mutex associated with the condition in accordance with the posix thread specification */ EnterCriticalSection (& mutex->lock); } +void xbt_os_cond_timedwait(xbt_os_cond_t cond, xbt_os_mutex_t mutex, double delay) { + THROW_UNIMPLEMENTED; +} void xbt_os_cond_signal(xbt_os_cond_t cond) { int have_waiters;