Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
I forgot to update my tree before commiting (once again), and got conflicts as punishment
[simgrid.git] / src / xbt / xbt_sg_synchro.c
index 518d19a..d485ba3 100644 (file)
@@ -3,8 +3,8 @@
 
 /* This is the simulation implementation, using simix.                      */
 
-/* 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. */
@@ -13,8 +13,8 @@
 
 #include "xbt/synchro.h"        /* This module */
 
-#include "simix/simix.h"        /* used implementation */
-#include "simix/datatypes.h"
+#include "simgrid/simix.h"        /* used implementation */
+#include "../simix/smx_private.h" /* FIXME */
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(xbt_sync, xbt,
                                 "Synchronization mechanism");
@@ -22,25 +22,26 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(xbt_sync, xbt,
 /* the implementation would be cleaner (and faster) with ELF symbol aliasing */
 
 typedef struct s_xbt_thread_ {
+  smx_process_t s_process; /* keep this first, gras_socket_im_the_server() does funky transtyping in sg_msg.c */
   char *name;
-  smx_process_t s_process;
   void_f_pvoid_t code;
   void *userparam;
   void *father_data;
   /* stuff to allow other people to wait on me with xbt_thread_join */
-  int joinable:1,done:1;
+  int joinable:1, done:1;
   xbt_cond_t cond;
   xbt_mutex_t mutex;
 } s_xbt_thread_t;
 
 static int xbt_thread_create_wrapper(int argc, char *argv[])
 {
+  smx_process_t self = SIMIX_process_self();
   xbt_thread_t t =
-    (xbt_thread_t) SIMIX_process_get_data(SIMIX_process_self());
-  SIMIX_process_set_data(SIMIX_process_self(), t->father_data);
-  (*t->code) (t->userparam);
+      (xbt_thread_t) SIMIX_process_self_get_data(self);
+  simcall_process_set_data(self, t->father_data);
+  t->code(t->userparam);
   if (t->joinable) {
-    t->done=1;
+    t->done = 1;
     xbt_mutex_acquire(t->mutex);
     xbt_cond_broadcast(t->cond);
     xbt_mutex_release(t->mutex);
@@ -54,19 +55,18 @@ static int xbt_thread_create_wrapper(int argc, char *argv[])
 }
 
 xbt_thread_t xbt_thread_create(const char *name, void_f_pvoid_t code,
-                               void *param,int joinable)
+                               void *param, int joinable)
 {
   xbt_thread_t res = xbt_new0(s_xbt_thread_t, 1);
   res->name = xbt_strdup(name);
   res->userparam = param;
   res->code = code;
-  res->father_data = SIMIX_process_get_data(SIMIX_process_self());
-  //   char*name = bprintf("%s#%p",SIMIX_process_get_name(SIMIX_process_self()), param);
-  res->s_process = SIMIX_process_create(name,
-                                        xbt_thread_create_wrapper, res,
-                                        SIMIX_host_get_name(SIMIX_host_self
-                                                            ()), 0, NULL,
-                                        /*props */ NULL);
+  res->father_data = SIMIX_process_self_get_data(SIMIX_process_self());
+  /*   char*name = bprintf("%s#%p",SIMIX_process_self_get_name(), param); */
+  simcall_process_create(&res->s_process, name,
+                           xbt_thread_create_wrapper, res,
+                           SIMIX_host_self_get_name(), -1.0, 0, NULL,
+                           /*props */ NULL);
   res->joinable = joinable;
   res->done = 0;
   res->cond = xbt_cond_init();
@@ -90,9 +90,10 @@ const char *xbt_thread_self_name(void)
 void xbt_thread_join(xbt_thread_t thread)
 {
   xbt_mutex_acquire(thread->mutex);
-  xbt_assert1(thread->joinable,"Cannot join on %p: wasn't created joinable",thread);
+  xbt_assert(thread->joinable,
+              "Cannot join on %p: wasn't created joinable", thread);
   if (!thread->done) {
-    xbt_cond_wait(thread->cond,thread->mutex);
+    xbt_cond_wait(thread->cond, thread->mutex);
     xbt_mutex_release(thread->mutex);
   }
 
@@ -105,93 +106,82 @@ void xbt_thread_join(xbt_thread_t thread)
 
 void xbt_thread_cancel(xbt_thread_t thread)
 {
-  SIMIX_process_kill(thread->s_process);
+  simcall_process_kill(thread->s_process);
   free(thread->name);
   free(thread);
 }
 
 void xbt_thread_exit()
 {
-  SIMIX_process_kill(SIMIX_process_self());
+  simcall_process_kill(SIMIX_process_self());
 }
 
 xbt_thread_t xbt_thread_self(void)
 {
-  smx_process_t p = SIMIX_process_self();
-  return p ? SIMIX_process_get_data(p) : NULL;
+  return SIMIX_process_self_get_data(SIMIX_process_self());
 }
 
-void xbt_thread_yield(void) {
-  SIMIX_process_yield();
+void xbt_thread_yield(void)
+{
+  SIMIX_process_yield(SIMIX_process_self());
 }
 
 /****** mutex related functions ******/
 struct s_xbt_mutex_ {
-
-  /* KEEP IT IN SYNC WITH src/simix/private.h::struct s_smx_mutex */
-  xbt_swag_t sleeping;          /* list of sleeping process */
-  int refcount;
-  /* KEEP IT IN SYNC WITH src/simix/private.h::struct s_smx_mutex */
-
+  s_smx_mutex_t mutex;
 };
 
 xbt_mutex_t xbt_mutex_init(void)
 {
-  return (xbt_mutex_t) SIMIX_mutex_init();
+  return (xbt_mutex_t) simcall_mutex_init();
 }
 
 void xbt_mutex_acquire(xbt_mutex_t mutex)
 {
-  SIMIX_mutex_lock((smx_mutex_t) mutex);
+  simcall_mutex_lock((smx_mutex_t) mutex);
 }
 
 void xbt_mutex_release(xbt_mutex_t mutex)
 {
-  SIMIX_mutex_unlock((smx_mutex_t) mutex);
+  simcall_mutex_unlock((smx_mutex_t) mutex);
 }
 
 void xbt_mutex_destroy(xbt_mutex_t mutex)
 {
-  SIMIX_mutex_destroy((smx_mutex_t) mutex);
+  simcall_mutex_destroy((smx_mutex_t) mutex);
 }
 
 /***** condition related functions *****/
 struct s_xbt_cond_ {
-
-  /* KEEP IT IN SYNC WITH src/simix/private.h::struct s_smx_cond */
-  xbt_swag_t sleeping;          /* list of sleeping process */
-  smx_mutex_t mutex;
-  xbt_fifo_t actions;           /* list of actions */
-  /* KEEP IT IN SYNC WITH src/simix/private.h::struct s_smx_cond */
-
+  s_smx_cond_t cond;
 };
 
 xbt_cond_t xbt_cond_init(void)
 {
-  return (xbt_cond_t) SIMIX_cond_init();
+  return (xbt_cond_t) simcall_cond_init();
 }
 
 void xbt_cond_wait(xbt_cond_t cond, xbt_mutex_t mutex)
 {
-  SIMIX_cond_wait((smx_cond_t) cond, (smx_mutex_t) mutex);
+  simcall_cond_wait((smx_cond_t) cond, (smx_mutex_t) mutex);
 }
 
 void xbt_cond_timedwait(xbt_cond_t cond, xbt_mutex_t mutex, double delay)
 {
-  SIMIX_cond_wait_timeout((smx_cond_t) cond, (smx_mutex_t) mutex, delay);
+  simcall_cond_wait_timeout((smx_cond_t) cond, (smx_mutex_t) mutex, delay);
 }
 
 void xbt_cond_signal(xbt_cond_t cond)
 {
-  SIMIX_cond_signal((smx_cond_t) cond);
+  simcall_cond_signal((smx_cond_t) cond);
 }
 
 void xbt_cond_broadcast(xbt_cond_t cond)
 {
-  SIMIX_cond_broadcast((smx_cond_t) cond);
+  simcall_cond_broadcast((smx_cond_t) cond);
 }
 
 void xbt_cond_destroy(xbt_cond_t cond)
 {
-  SIMIX_cond_destroy((smx_cond_t) cond);
+  simcall_cond_destroy((smx_cond_t) cond);
 }