From 5843ccab4e336d47ca34f54e68760ac78d242f36 Mon Sep 17 00:00:00 2001 From: Martin Quinson Date: Sun, 12 Nov 2023 21:49:02 +0100 Subject: [PATCH] Template implem of cond_timedwait in sthread --- src/sthread/sthread.c | 4 ++++ src/sthread/sthread.h | 1 + src/sthread/sthread_impl.cpp | 31 ++++--------------------------- 3 files changed, 9 insertions(+), 27 deletions(-) diff --git a/src/sthread/sthread.c b/src/sthread/sthread.c index 0bf6c54523..af260220f2 100644 --- a/src/sthread/sthread.c +++ b/src/sthread/sthread.c @@ -42,6 +42,7 @@ static int (*raw_pthread_cond_init)(pthread_cond_t*, const pthread_condattr_t*); static int (*raw_pthread_cond_signal)(pthread_cond_t*); static int (*raw_pthread_cond_broadcast)(pthread_cond_t*); static int (*raw_pthread_cond_wait)(pthread_cond_t*, pthread_mutex_t*); +static int (*raw_pthread_cond_timedwait)(pthread_cond_t*, pthread_mutex_t*, const struct timespec* abstime); static int (*raw_pthread_cond_destroy)(pthread_cond_t*); static unsigned int (*raw_sleep)(unsigned int); @@ -80,6 +81,7 @@ static void intercepter_init() raw_pthread_cond_signal = dlsym(RTLD_NEXT, "raw_pthread_cond_signal"); raw_pthread_cond_broadcast = dlsym(RTLD_NEXT, "raw_pthread_cond_broadcast"); raw_pthread_cond_wait = dlsym(RTLD_NEXT, "raw_pthread_cond_wait"); + raw_pthread_cond_timedwait = dlsym(RTLD_NEXT, "raw_pthread_cond_timedwait"); raw_pthread_cond_destroy = dlsym(RTLD_NEXT, "raw_pthread_cond_destroy"); raw_sleep = dlsym(RTLD_NEXT, "sleep"); @@ -152,6 +154,8 @@ intercepted_pthcall(cond_signal, (pthread_cond_t * cond), (cond), ((sthread_cond intercepted_pthcall(cond_broadcast, (pthread_cond_t * cond), (cond), ((sthread_cond_t*)cond)); intercepted_pthcall(cond_wait, (pthread_cond_t * cond, pthread_mutex_t* mutex), (cond, mutex), ((sthread_cond_t*)cond, (sthread_mutex_t*)mutex)); +intercepted_pthcall(cond_timedwait, (pthread_cond_t * cond, pthread_mutex_t* mutex, const struct timespec* abstime), + (cond, mutex, abstime), ((sthread_cond_t*)cond, (sthread_mutex_t*)mutex, abstime)); intercepted_pthcall(cond_destroy, (pthread_cond_t * cond), (cond), ((sthread_cond_t*)cond)); #define intercepted_call(rettype, name, raw_params, call_params, sim_params) \ diff --git a/src/sthread/sthread.h b/src/sthread/sthread.h index 8447d9702c..ecc6494070 100644 --- a/src/sthread/sthread.h +++ b/src/sthread/sthread.h @@ -74,6 +74,7 @@ int sthread_cond_init(sthread_cond_t* cond, sthread_condattr_t* attr); int sthread_cond_signal(sthread_cond_t* cond); int sthread_cond_broadcast(sthread_cond_t* cond); int sthread_cond_wait(sthread_cond_t* cond, sthread_mutex_t* mutex); +int sthread_cond_timedwait(sthread_cond_t* cond, sthread_mutex_t* mutex, const struct timespec* abs_timeout); int sthread_cond_destroy(sthread_cond_t* cond); typedef struct { diff --git a/src/sthread/sthread_impl.cpp b/src/sthread/sthread_impl.cpp index 063d26553b..08c7da5280 100644 --- a/src/sthread/sthread_impl.cpp +++ b/src/sthread/sthread_impl.cpp @@ -265,6 +265,10 @@ int sthread_cond_wait(sthread_cond_t* cond, sthread_mutex_t* mutex) static_cast(cond->cond)->wait(static_cast(mutex->mutex)); return 0; } +int sthread_cond_timedwait(sthread_cond_t* cond, sthread_mutex_t* mutex, const struct timespec* abs_timeout) +{ + THROW_UNIMPLEMENTED; +} int sthread_cond_destroy(sthread_cond_t* cond) { XBT_DEBUG("%s(%p)", __func__, cond); @@ -339,30 +343,3 @@ int sthread_usleep(double seconds) simgrid::s4u::this_actor::sleep_for(seconds); return 0; } - -#if 0 -int pthread_cond_init(pthread_cond_t *cond, pthread_condattr_t *cond_attr) { - *cond = sg_cond_init(); - return 0; -} - -int pthread_cond_signal(pthread_cond_t *cond) { - sg_cond_notify_one(*cond); - return 0; -} - -int pthread_cond_broadcast(pthread_cond_t *cond) { - sg_cond_notify_all(*cond); - return 0; -} - -int pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex) { - sg_cond_wait(*cond, *mutex); - return 0; -} - -int pthread_cond_destroy(pthread_cond_t *cond) { - sg_cond_destroy(*cond); - return 0; -} -#endif -- 2.20.1