#include "src/internal_config.h"
#include "src/sthread/sthread.h"
+#include <cmath>
#include <dlfcn.h>
#include <pthread.h>
#include <semaphore.h>
int sthread_main(int argc, char** argv, char** envp, int (*raw_main)(int, char**, char**))
{
+ /* Do not intercept the main when run from SMPI: it will initialize the simulation properly */
+ for (int i = 0; envp[i] != nullptr; i++)
+ if (strncmp(envp[i], "SMPI_GLOBAL_SIZE", strlen("SMPI_GLOBAL_SIZE")) == 0)
+ return raw_main(argc, argv, envp);
+
+ /* If not in SMPI, the old main becomes an actor in a newly created simulation */
std::ostringstream id;
id << std::this_thread::get_id();
return 0;
}
+int sthread_gettimeofday(struct timeval* tv)
+{
+ 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;
return raw_sem_post(sem);
}
-int pthread_join(pthread_t thread, void **retval) {
- sg_actor_join(thread, -1);
- return 0;
-}
-
int pthread_cond_init(pthread_cond_t *cond, pthread_condattr_t *cond_attr) {
*cond = sg_cond_init();
return 0;