Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Move the implementation of reentrant mutexes out of the pthread case
authorChristophe Thiéry <christopho128@gmail.com>
Fri, 22 Apr 2011 10:26:35 +0000 (12:26 +0200)
committerChristophe Thiéry <christopho128@gmail.com>
Fri, 22 Apr 2011 10:26:35 +0000 (12:26 +0200)
src/xbt/xbt_os_thread.c

index 781d471..c79377a 100644 (file)
@@ -358,45 +358,6 @@ void xbt_os_mutex_destroy(xbt_os_mutex_t mutex)
   free(mutex);
 }
 
   free(mutex);
 }
 
-xbt_os_rmutex_t xbt_os_rmutex_init(void)
-{
-  xbt_os_rmutex_t rmutex = xbt_new0(struct xbt_os_rmutex_, 0);
-  rmutex->mutex = xbt_os_mutex_init();
-  rmutex->owner = NULL;
-  rmutex->count = 0;
-  return rmutex;
-}
-
-void xbt_os_rmutex_acquire(xbt_os_rmutex_t rmutex)
-{
-  xbt_os_thread_t self = xbt_os_thread_self();
-  xbt_assert(self != NULL, "Cannot get my own thread object (is the thread module initialized?)");
-
-  if (self != rmutex->owner) {
-    xbt_os_mutex_acquire(rmutex->mutex);
-    rmutex->owner = self;
-    rmutex->count = 1;
-  } else {
-    rmutex->count++;
- }
-}
-
-void xbt_os_rmutex_release(xbt_os_rmutex_t rmutex)
-{
-  xbt_assert(rmutex->owner == xbt_os_thread_self());
-
-  if (--rmutex->count == 0) {
-    rmutex->owner = NULL;
-    xbt_os_mutex_release(rmutex->mutex);
-  }
-}
-
-void xbt_os_rmutex_destroy(xbt_os_rmutex_t rmutex)
-{
-  xbt_os_mutex_destroy(rmutex->mutex);
-  xbt_free(rmutex);
-}
-
 /***** condition related functions *****/
 typedef struct xbt_os_cond_ {
   /* KEEP IT IN SYNC WITH xbt_thread.c */
 /***** condition related functions *****/
 typedef struct xbt_os_cond_ {
   /* KEEP IT IN SYNC WITH xbt_thread.c */
@@ -1182,3 +1143,42 @@ void *xbt_os_thread_get_extra_data(void)
 {
   return xbt_os_thread_self()->extra_data;
 }
 {
   return xbt_os_thread_self()->extra_data;
 }
+
+xbt_os_rmutex_t xbt_os_rmutex_init(void)
+{
+  xbt_os_rmutex_t rmutex = xbt_new0(struct xbt_os_rmutex_, 0);
+  rmutex->mutex = xbt_os_mutex_init();
+  rmutex->owner = NULL;
+  rmutex->count = 0;
+  return rmutex;
+}
+
+void xbt_os_rmutex_acquire(xbt_os_rmutex_t rmutex)
+{
+  xbt_os_thread_t self = xbt_os_thread_self();
+  xbt_assert(self != NULL, "Cannot get my own thread object (is the thread module initialized?)");
+
+  if (self != rmutex->owner) {
+    xbt_os_mutex_acquire(rmutex->mutex);
+    rmutex->owner = self;
+    rmutex->count = 1;
+  } else {
+    rmutex->count++;
+ }
+}
+
+void xbt_os_rmutex_release(xbt_os_rmutex_t rmutex)
+{
+  xbt_assert(rmutex->owner == xbt_os_thread_self());
+
+  if (--rmutex->count == 0) {
+    rmutex->owner = NULL;
+    xbt_os_mutex_release(rmutex->mutex);
+  }
+}
+
+void xbt_os_rmutex_destroy(xbt_os_rmutex_t rmutex)
+{
+  xbt_os_mutex_destroy(rmutex->mutex);
+  xbt_free(rmutex);
+}