Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Gcc is *very* permissive with pointers to functions. If we declare them as function...
[simgrid.git] / src / xbt / xbt_os_thread.c
index f34821d..4a793e4 100644 (file)
@@ -29,7 +29,7 @@ typedef struct xbt_os_thread_ {
    pthread_t t;
    char *name;
    void *param;
-   pvoid_f_pvoid_t *start_routine;
+   pvoid_f_pvoid_t start_routine;
    ex_ctx_t *exception;
 } s_xbt_os_thread_t ;
 static xbt_os_thread_t main_thread = NULL;
@@ -93,7 +93,7 @@ static void * wrapper_start_routine(void *s) {
   if ((errcode=pthread_setspecific(xbt_self_thread_key,t)))
     THROW0(system_error,errcode,
           "pthread_setspecific failed for xbt_self_thread_key");   
-  return t->start_routine(t->param);
+  return (*t->start_routine)(t->param);
 }
 xbt_os_thread_t xbt_os_thread_create(const char*name,
                                     pvoid_f_pvoid_t start_routine,
@@ -237,19 +237,24 @@ void xbt_os_cond_timedwait(xbt_os_cond_t cond, xbt_os_mutex_t mutex, double dela
    int errcode;
    struct timespec ts_end;
    double end = delay + xbt_os_time();
-   ts_end.tv_sec = (time_t) floor(end);
-   ts_end.tv_nsec = (long)  ( ( end - ts_end.tv_sec) * 1000000000);
-   DEBUG3("pthread_cond_timedwait(%p,%p,%p)",&(cond->c),&(mutex->m), &ts_end);
-   switch ( (errcode=pthread_cond_timedwait(&(cond->c),&(mutex->m), &ts_end)) ) {
-    case 0:
-      return;
-    case ETIMEDOUT:
-     THROW3(timeout_error,errcode,"condition %p (mutex %p) wasn't signaled before timeout (%f)",
-           cond,mutex, delay);
-    default:
-     THROW4(system_error,errcode,"pthread_cond_timedwait(%p,%p,%f) failed: %s",
-           cond,mutex, delay, strerror(errcode));
-   }   
+   
+   if (delay < 0) {
+      xbt_os_cond_wait(cond,mutex);
+   } else {
+      ts_end.tv_sec = (time_t) floor(end);
+      ts_end.tv_nsec = (long)  ( ( end - ts_end.tv_sec) * 1000000000);
+      DEBUG3("pthread_cond_timedwait(%p,%p,%p)",&(cond->c),&(mutex->m), &ts_end);
+      switch ( (errcode=pthread_cond_timedwait(&(cond->c),&(mutex->m), &ts_end)) ) {
+       case 0:
+        return;
+       case ETIMEDOUT:
+        THROW3(timeout_error,errcode,"condition %p (mutex %p) wasn't signaled before timeout (%f)",
+               cond,mutex, delay);
+       default:
+        THROW4(system_error,errcode,"pthread_cond_timedwait(%p,%p,%f) failed: %s",
+               cond,mutex, delay, strerror(errcode));
+      }   
+   }
 }
 
 void xbt_os_cond_signal(xbt_os_cond_t cond) {
@@ -289,7 +294,7 @@ typedef struct xbt_os_thread_ {
   char *name;
   HANDLE handle;                  /* the win thread handle        */
   unsigned long id;               /* the win thread id            */
-  pvoid_f_pvoid_t *start_routine;
+  pvoid_f_pvoid_t start_routine;
   void* param;
 } s_xbt_os_thread_t ;