/* 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 <dlfcn.h>
#include <pthread.h>
#include <semaphore.h>
#include <stdio.h>
+#include <unistd.h>
#if HAVE_VALGRIND_H
#include <stdlib.h>
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;
#ifndef SIMGRID_STHREAD_H
#define SIMGRID_STHREAD_H
+#include <sys/time.h>
+
#if defined(__ELF__)
#define XBT_PUBLIC __attribute__((visibility("default")))
#else
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
#include "src/internal_config.h"
#include "src/sthread/sthread.h"
+#include <cmath>
#include <dlfcn.h>
#include <pthread.h>
#include <semaphore.h>
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<time_t>(secs);
+ tv->tv_usec = static_cast<decltype(tv->tv_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;