Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Indent include and src using this command:
[simgrid.git] / src / xbt / xbt_rl_synchro.c
index 1a74c0b..12143a7 100644 (file)
@@ -1,13 +1,11 @@
-/* $Id$ */
-
 /* xbt_synchro -- Synchronization virtualized depending on whether we are   */
 /*                in simulation or real life (act on simulated processes)   */
 
 /* This is the real life implementation, using xbt_os_thread to be portable */
 /* to windows and linux.                                                    */
 
-/* Copyright 2006,2007 Malek Cherier, Martin Quinson
- * All right reserved.                                                      */
+/* Copyright (c) 2007, 2008, 2009, 2010. The SimGrid Team.
+ * All rights reserved.                                                     */
 
 /* This program is free software; you can redistribute it and/or modify it
  * under the terms of the license (GNU LGPL) which comes with this package. */
@@ -20,8 +18,8 @@
 #include "xbt/xbt_os_thread.h"  /* The implementation we use */
 
 /* the implementation would be cleaner (and faster) with ELF symbol aliasing */
-XBT_LOG_NEW_DEFAULT_SUBCATEGORY(xbt_sync_rl, xbt,
-                                "Synchronization mechanism (RL)");
+XBT_LOG_NEW_DEFAULT_SUBCATEGORY(xbt_sync, xbt,
+                                "Synchronization mechanism");
 
 typedef struct s_xbt_thread_ {
   xbt_os_thread_t os_thread;
@@ -39,14 +37,15 @@ static void *xbt_thread_create_wrapper(void *p)
 
 
 xbt_thread_t xbt_thread_create(const char *name, void_f_pvoid_t code,
-                               void *param)
+                               void *param, int joinable)
 {
 
   xbt_thread_t res = xbt_new0(s_xbt_thread_t, 1);
   res->userparam = param;
   res->code = code;
   DEBUG1("Create thread %p", res);
-  res->os_thread = xbt_os_thread_create(name, xbt_thread_create_wrapper, res);
+  res->os_thread =
+      xbt_os_thread_create(name, xbt_thread_create_wrapper, res);
   return res;
 }
 
@@ -64,6 +63,7 @@ void xbt_thread_join(xbt_thread_t thread)
 {
   DEBUG1("Join thread %p", thread);
   xbt_os_thread_join(thread->os_thread, NULL);
+  xbt_free(thread);
 }
 
 void xbt_thread_exit()
@@ -94,7 +94,7 @@ struct xbt_mutex_ {
   /* KEEP IT IN SYNC WITH OS IMPLEMENTATION (both win and lin) */
 #ifdef HAVE_PTHREAD_H
   pthread_mutex_t m;
-#elif defined(WIN32)
+#elif defined(_XBT_WIN32)
   CRITICAL_SECTION lock;
 #endif
 };
@@ -130,7 +130,7 @@ void xbt_mutex_destroy(xbt_mutex_t mutex)
   xbt_os_mutex_destroy((xbt_os_mutex_t) mutex);
 }
 
-#ifdef WIN32
+#ifdef _XBT_WIN32
 enum {                          /* KEEP IT IN SYNC WITH OS IMPLEM */
   SIGNAL = 0,
   BROADCAST = 1,
@@ -143,7 +143,7 @@ typedef struct xbt_cond_ {
   /* KEEP IT IN SYNC WITH OS IMPLEMENTATION (both win and lin) */
 #ifdef HAVE_PTHREAD_H
   pthread_cond_t c;
-#elif defined(WIN32)
+#elif defined(_XBT_WIN32)
   HANDLE events[MAX_EVENTS];
 
   unsigned int waiters_count;   /* the number of waiters                        */
@@ -167,7 +167,8 @@ void xbt_cond_wait(xbt_cond_t cond, xbt_mutex_t mutex)
 void xbt_cond_timedwait(xbt_cond_t cond, xbt_mutex_t mutex, double delay)
 {
   DEBUG3("Wait cond %p, mutex %p for %f sec", cond, mutex, delay);
-  xbt_os_cond_timedwait((xbt_os_cond_t) cond, (xbt_os_mutex_t) mutex, delay);
+  xbt_os_cond_timedwait((xbt_os_cond_t) cond, (xbt_os_mutex_t) mutex,
+                        delay);
   DEBUG3("Done waiting cond %p, mutex %p for %f sec", cond, mutex, delay);
 }