From: Martin Quinson Date: Sun, 10 Jul 2022 18:00:43 +0000 (+0200) Subject: sthread: Intercept gettimeofday + sleep + usleep X-Git-Tag: v3.32~160 X-Git-Url: http://bilbo.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/e3d4520d56f2d11ff8c384d9adbb2e8ab1068f78 sthread: Intercept gettimeofday + sleep + usleep --- diff --git a/src/sthread/sthread.c b/src/sthread/sthread.c index 24213e0c72..0de4be3667 100644 --- a/src/sthread/sthread.c +++ b/src/sthread/sthread.c @@ -1,12 +1,13 @@ /* SimGrid's pthread interposer. Redefinition of the pthread symbols (see the comment in sthread.h) */ #define _GNU_SOURCE -#include "src/internal_config.h" #include "src/sthread/sthread.h" +#include "src/internal_config.h" #include #include #include #include +#include #if HAVE_VALGRIND_H #include @@ -146,6 +147,23 @@ int pthread_mutex_destroy(pthread_mutex_t* mutex) return res; } +int gettimeofday(struct timeval* tv, void* tz) +{ + return sthread_gettimeofday(tv, tz); +} + +unsigned int sleep(unsigned int seconds) +{ + sthread_sleep(seconds); + return 0; +} + +int usleep(useconds_t usec) +{ + sthread_sleep(((double)usec) / 1000000.); + return 0; +} + #if 0 int sem_init(sem_t *sem, int pshared, unsigned int value) { int res; diff --git a/src/sthread/sthread.h b/src/sthread/sthread.h index 9bc6c50152..1af86186cd 100644 --- a/src/sthread/sthread.h +++ b/src/sthread/sthread.h @@ -10,6 +10,8 @@ #ifndef SIMGRID_STHREAD_H #define SIMGRID_STHREAD_H +#include + #if defined(__ELF__) #define XBT_PUBLIC __attribute__((visibility("default"))) #else @@ -38,6 +40,9 @@ int sthread_mutex_trylock(sthread_mutex_t* mutex); int sthread_mutex_unlock(sthread_mutex_t* mutex); int sthread_mutex_destroy(sthread_mutex_t* mutex); +int sthread_gettimeofday(struct timeval* tv, struct timezone* tz); +void sthread_sleep(double seconds); + #if defined(__cplusplus) } #endif diff --git a/src/sthread/sthread_impl.cpp b/src/sthread/sthread_impl.cpp index d1a88a7038..243aa7b801 100644 --- a/src/sthread/sthread_impl.cpp +++ b/src/sthread/sthread_impl.cpp @@ -12,6 +12,7 @@ #include "src/internal_config.h" #include "src/sthread/sthread.h" +#include #include #include #include @@ -129,6 +130,23 @@ int sthread_mutex_destroy(sthread_mutex_t* mutex) return 0; } +int sthread_gettimeofday(struct timeval* tv, struct timezone* tz) +{ + if (tv) { + double now = simgrid::s4u::Engine::get_clock(); + double secs = trunc(now); + double usecs = (now - secs) * 1e6; + tv->tv_sec = static_cast(secs); + tv->tv_usec = static_casttv_usec)>(usecs); // suseconds_t (or useconds_t on WIN32) + } + return 0; +} + +void sthread_sleep(double seconds) +{ + simgrid::s4u::this_actor::sleep_for(seconds); +} + #if 0 int sem_init(sem_t *sem, int pshared, unsigned int value) { int res;