Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Missing return in the raw path.
[simgrid.git] / src / sthread / sthread.c
index b993434..dd9a67c 100644 (file)
@@ -7,10 +7,9 @@
 #include <semaphore.h>
 #include <stdio.h>
 
-int sthread_inside_simgrid = 1; // whether sthread should leave pthread operations, or intercept them.
-
 /* We don't want to intercept pthread within simgrid. Instead we should provide the real implem to simgrid */
 static int (*raw_pthread_create)(pthread_t*, const pthread_attr_t*, void* (*)(void*), void*);
+static int (*raw_pthread_join)(pthread_t, void**);
 static int (*raw_mutex_init)(pthread_mutex_t*, const pthread_mutexattr_t*) = NULL;
 static int (*raw_mutex_lock)(pthread_mutex_t*)                             = NULL;
 static int (*raw_mutex_trylock)(pthread_mutex_t*)                          = NULL;
@@ -22,8 +21,8 @@ static int (*raw_sem_wait)(sem_t*)                                         = NUL
 static int (*raw_sem_post)(sem_t*)                                         = NULL;
 static void intercepter_init()
 {
-  raw_pthread_create =
-      (int (*)(pthread_t*, const pthread_attr_t*, void* (*)(void*), void*))dlsym(RTLD_NEXT, "pthread_create");
+  raw_pthread_create = (typeof(raw_pthread_create))dlsym(RTLD_NEXT, "pthread_create");
+  raw_pthread_join   = (typeof(raw_pthread_join))dlsym(RTLD_NEXT, "pthread_join");
   raw_mutex_init    = (int (*)(pthread_mutex_t*, const pthread_mutexattr_t*))dlsym(RTLD_NEXT, "pthread_mutex_init");
   raw_mutex_lock    = (int (*)(pthread_mutex_t*))dlsym(RTLD_NEXT, "pthread_mutex_lock");
   raw_mutex_trylock = (int (*)(pthread_mutex_t*))dlsym(RTLD_NEXT, "pthread_mutex_trylock");
@@ -36,6 +35,15 @@ static void intercepter_init()
   raw_sem_post = (int (*)(sem_t*))dlsym(RTLD_NEXT, "sem_post");
 }
 
+static int sthread_inside_simgrid = 1;
+void sthread_enable(void)
+{ // Start intercepting all pthread calls
+  sthread_inside_simgrid = 0;
+}
+void sthread_disable(void)
+{ // Stop intercepting all pthread calls
+  sthread_inside_simgrid = 1;
+}
 int pthread_create(pthread_t* thread, const pthread_attr_t* attr, void* (*start_routine)(void*), void* arg)
 {
   if (raw_pthread_create == NULL)
@@ -49,6 +57,19 @@ int pthread_create(pthread_t* thread, const pthread_attr_t* attr, void* (*start_
   sthread_inside_simgrid = 0;
   return res;
 }
+int pthread_join(pthread_t thread, void** retval)
+{
+  if (raw_pthread_join == NULL)
+    intercepter_init();
+
+  if (sthread_inside_simgrid)
+    return raw_pthread_join(thread, retval);
+
+  sthread_inside_simgrid = 1;
+  int res                = sthread_join(thread, retval);
+  sthread_inside_simgrid = 0;
+  return res;
+}
 
 int pthread_mutex_init(pthread_mutex_t* mutex, const pthread_mutexattr_t* attr)
 {
@@ -56,7 +77,7 @@ int pthread_mutex_init(pthread_mutex_t* mutex, const pthread_mutexattr_t* attr)
     intercepter_init();
 
   if (sthread_inside_simgrid)
-    raw_mutex_init(mutex, attr);
+    return raw_mutex_init(mutex, attr);
 
   sthread_inside_simgrid = 1;
   int res                = sthread_mutex_init((sthread_mutex_t*)mutex, attr);
@@ -193,4 +214,4 @@ int __libc_start_main(int (*main)(int, char**, char**), int argc, char** argv, i
   fprintf(stderr, "__libc_start_main\n");
   /* ... and call it with our custom main function */
   return orig(main_hook, argc, argv, init, fini, rtld_fini, stack_end);
-}
\ No newline at end of file
+}