Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
First step into moving the context subsystem into simix. Still segfaults because...
authormquinson <mquinson@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Mon, 13 Jul 2009 18:04:03 +0000 (18:04 +0000)
committermquinson <mquinson@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Mon, 13 Jul 2009 18:04:03 +0000 (18:04 +0000)
git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@6495 48e7efb5-ca39-0410-a469-dd3cf9ba447f

src/gras/rl_stubs.c
src/include/simix/datatypes.h
src/simix/private.h
src/simix/smx_global.c
src/simix/smx_process.c
src/simix/smx_synchro.c
src/simix/xbt_context.c
src/simix/xbt_context_private.h
src/simix/xbt_context_sysv.c
src/xbt/xbt_main.c
src/xbt_modinter.h

index 05f1535..6f46445 100644 (file)
@@ -18,16 +18,16 @@ XBT_LOG_EXTERNAL_CATEGORY(gras_trp);
 XBT_LOG_EXTERNAL_CATEGORY(gras_trp_file);
 XBT_LOG_EXTERNAL_CATEGORY(gras_trp_tcp);
 
-void xbt_context_mod_init(void)
+/*void xbt_context_mod_init(void)
 {
   XBT_LOG_CONNECT(xbt_sync_rl, xbt);
   XBT_LOG_CONNECT(gras_trp_file, gras_trp);
   XBT_LOG_CONNECT(gras_trp_tcp, gras_trp);
-}
+}*/
 
-void xbt_context_mod_exit(void)
+/*void xbt_context_mod_exit(void)
 {
-}
+}*/
 
 void SIMIX_display_process_status(void)
 {
index 28e1be2..859727e 100644 (file)
@@ -33,15 +33,12 @@ SG_BEGIN_DECL()
 
 
 /* ******************************** Syncro ************************************ */
-
      typedef struct s_smx_mutex *smx_mutex_t;
      typedef struct s_smx_cond *smx_cond_t;
 
-
 /********************************** Action *************************************/
      typedef struct s_smx_action *smx_action_t;
 
-
 /* ****************************** Process *********************************** */
 /** @brief Agent datatype  
     @ingroup m_datatypes_management 
index bb65a42..202f3f4 100644 (file)
-/*     $Id$     */
-
-/* Copyright (c) 2007 Arnaud Legrand, Bruno Donnassolo.
-   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. */
-
-#ifndef SIMIX_PRIVATE_H
-#define SIMIX_PRIVATE_H
-
-#include <stdio.h>
-#include "simix/simix.h"
-#include "surf/surf.h"
-#include "xbt/fifo.h"
-#include "xbt/swag.h"
-#include "xbt/dict.h"
-#include "simix/context.h"
-#include "xbt/config.h"
-#include "xbt/function_types.h"
-
-/******************************* Datatypes **********************************/
-
-
-/********************************** Host ************************************/
-
-/** @brief Host datatype 
-    @ingroup m_datatypes_management_details */
-typedef struct s_smx_host {
-  char *name;              /**< @brief host name if any */
-  void *host;              /* SURF modeling */
-  xbt_swag_t process_list;
-  void *data;              /**< @brief user data */
-} s_smx_host_t;
-
-/********************************* Simix Global ******************************/
-
-typedef struct SIMIX_Global {
-  xbt_dict_t host;
-  xbt_swag_t process_to_run;
-  xbt_swag_t process_list;
-
-  smx_process_t current_process;
-  xbt_dict_t registered_functions;
-  smx_creation_func_t create_process_function;
-  void_f_pvoid_t kill_process_function;
-  void_f_pvoid_t cleanup_process_function;
-} s_SIMIX_Global_t, *SIMIX_Global_t;
-
-extern SIMIX_Global_t simix_global;
-
-/******************************* Process *************************************/
-
-/** @brief Process datatype 
-    @ingroup m_datatypes_management_details @{ */
-     typedef struct s_smx_process {
-       s_xbt_swag_hookup_t process_hookup;
-       s_xbt_swag_hookup_t synchro_hookup;
-       s_xbt_swag_hookup_t host_proc_hookup;
-
-       char *name;              /**< @brief process name if any */
-       smx_host_t smx_host;     /* the host on which the process is running */
-       xbt_context_t context;   /* the context that executes the scheduler function */
-       int argc;                /* arguments number if any */
-       char **argv;             /* arguments table if any */
-       int blocked : 1;
-       int suspended : 1;
-       int iwannadie : 1;
-       smx_mutex_t mutex;       /* mutex on which the process is blocked  */
-       smx_cond_t cond;         /* cond on which the process is blocked  */
-       xbt_dict_t properties;
-       void *data;              /* kept for compatibility, it should be replaced with moddata */
-
-     } s_smx_process_t;
-/** @} */
-
-typedef struct s_smx_process_arg {
-  const char *name;
-  xbt_main_func_t code;
-  void *data;
-  char *hostname;
-  int argc;
-  char **argv;
-  double kill_time;
-  xbt_dict_t properties;
-} s_smx_process_arg_t, *smx_process_arg_t;
-
-/********************************* Mutex and Conditional ****************************/
-
-typedef struct s_smx_mutex {
-
-  /* KEEP IT IN SYNC WITH src/xbt_sg_thread.c::struct s_xbt_mutex */
-  xbt_swag_t sleeping;          /* list of sleeping process */
-  int refcount;
-  /* KEEP IT IN SYNC WITH src/xbt_sg_thread.c::struct s_xbt_mutex */
-
-} s_smx_mutex_t;
-
-typedef struct s_smx_cond {
-
-  /* KEEP IT IN SYNC WITH src/xbt_sg_thread.c::struct s_xbt_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/xbt_sg_thread.c::struct s_xbt_cond */
-
-} s_smx_cond_t;
-
-/********************************* Action **************************************/
-
-/** @brief Action datatype 
-    @ingroup m_datatypes_management_details */
-typedef struct s_smx_action {
-  char *name;              /**< @brief action name if any */
-  xbt_fifo_t cond_list;    /*< conditional variables that must be signaled when the action finish. */
-  void *data;              /**< @brief user data */
-  int refcount;            /**< @brief reference counter */
-  surf_action_t surf_action;    /* SURF modeling of computation  */
-  smx_host_t source;
-} s_smx_action_t;
-
-/******************************* Other **********************************/
-
-
-#define SIMIX_CHECK_HOST()  xbt_assert0(surf_workstation_model->extension.workstation. \
-                                 get_state(SIMIX_host_self()->host)==SURF_RESOURCE_ON,\
-                                  "Host failed, you cannot call this function.")
-
-smx_host_t __SIMIX_host_create(const char *name, void *workstation,
-                               void *data);
-void __SIMIX_host_destroy(void *host);
-
-void __SIMIX_cond_wait(smx_cond_t cond);
-
-void __SIMIX_cond_display_actions(smx_cond_t cond);
-void __SIMIX_action_display_conditions(smx_action_t action);
-
-#endif
+/*     $Id$     */\r
+\r
+/* Copyright (c) 2007 Arnaud Legrand, Bruno Donnassolo.\r
+   All rights reserved.                                          */\r
+\r
+/* This program is free software; you can redistribute it and/or modify it\r
+ * under the terms of the license (GNU LGPL) which comes with this package. */\r
+\r
+#ifndef SIMIX_PRIVATE_H\r
+#define SIMIX_PRIVATE_H\r
+\r
+#include <stdio.h>\r
+#include "simix/simix.h"\r
+#include "surf/surf.h"\r
+#include "xbt/fifo.h"\r
+#include "xbt/swag.h"\r
+#include "xbt/dict.h"\r
+#include "xbt/config.h"\r
+#include "xbt/function_types.h"\r
+\r
+/******************************** Datatypes ***********************************/\r
+\r
+\r
+/*********************************** Host *************************************/\r
+\r
+/** @brief Host datatype \r
+    @ingroup m_datatypes_management_details */\r
+typedef struct s_smx_host {\r
+  char *name;              /**< @brief host name if any */\r
+  void *host;              /* SURF modeling */\r
+  xbt_swag_t process_list;\r
+  void *data;              /**< @brief user data */\r
+} s_smx_host_t;\r
+\r
+/********************************** Simix Global ******************************/\r
+\r
+typedef struct s_smx_context_factory *smx_context_factory_t;\r
+\r
+typedef struct SIMIX_Global {\r
+  smx_context_factory_t context_factory;\r
+  xbt_dict_t host;\r
+  xbt_swag_t process_to_run;\r
+  xbt_swag_t process_list;\r
+  xbt_swag_t process_to_destroy;\r
+  smx_process_t current_process;\r
+  smx_process_t maestro_process;\r
+  xbt_dict_t registered_functions;\r
+  smx_creation_func_t create_process_function;\r
+  void_f_pvoid_t kill_process_function;\r
+  void_f_pvoid_t cleanup_process_function;\r
+} s_SIMIX_Global_t, *SIMIX_Global_t;\r
+\r
+extern SIMIX_Global_t simix_global;\r
+\r
+/******************************** Process *************************************/\r
+\r
+typedef struct s_xbt_context *xbt_context_t;\r
+\r
+/** @brief Process datatype \r
+    @ingroup m_datatypes_management_details @{ */\r
+     typedef struct s_smx_process {\r
+       s_xbt_swag_hookup_t process_hookup;\r
+       s_xbt_swag_hookup_t synchro_hookup;\r
+       s_xbt_swag_hookup_t host_proc_hookup;\r
+       s_xbt_swag_hookup_t destroy_hookup;\r
+\r
+       char *name;              /**< @brief process name if any */\r
+       smx_host_t smx_host;     /* the host on which the process is running */\r
+       xbt_context_t context;   /* the context that executes the scheduler function */\r
+       int argc;                /* arguments number if any */\r
+       char **argv;             /* arguments table if any */\r
+       int blocked : 1;\r
+       int suspended : 1;\r
+       int iwannadie : 1;\r
+       smx_mutex_t mutex;       /* mutex on which the process is blocked  */\r
+       smx_cond_t cond;         /* cond on which the process is blocked  */\r
+       xbt_dict_t properties;\r
+       void *data;              /* kept for compatibility, it should be replaced with moddata */\r
+       void_f_pvoid_t cleanup_func;\r
+       void *cleanup_arg;\r
+\r
+     } s_smx_process_t;\r
+/** @} */\r
+\r
+typedef struct s_smx_process_arg {\r
+  const char *name;\r
+  xbt_main_func_t code;\r
+  void *data;\r
+  char *hostname;\r
+  int argc;\r
+  char **argv;\r
+  double kill_time;\r
+  xbt_dict_t properties;\r
+} s_smx_process_arg_t, *smx_process_arg_t;\r
+\r
+/*************************** Mutex and Conditional ****************************/\r
+\r
+typedef struct s_smx_mutex {\r
+\r
+  /* KEEP IT IN SYNC WITH src/xbt_sg_thread.c::struct s_xbt_mutex */\r
+  xbt_swag_t sleeping;          /* list of sleeping process */\r
+  int refcount;\r
+  /* KEEP IT IN SYNC WITH src/xbt_sg_thread.c::struct s_xbt_mutex */\r
+\r
+} s_smx_mutex_t;\r
+\r
+typedef struct s_smx_cond {\r
+\r
+  /* KEEP IT IN SYNC WITH src/xbt_sg_thread.c::struct s_xbt_cond */\r
+  xbt_swag_t sleeping;          /* list of sleeping process */\r
+  smx_mutex_t mutex;\r
+  xbt_fifo_t actions;           /* list of actions */\r
+  /* KEEP IT IN SYNC WITH src/xbt_sg_thread.c::struct s_xbt_cond */\r
+\r
+} s_smx_cond_t;\r
+\r
+/********************************* Action *************************************/\r
+\r
+/** @brief Action datatype \r
+    @ingroup m_datatypes_management_details */\r
+typedef struct s_smx_action {\r
+  char *name;              /**< @brief action name if any */\r
+  xbt_fifo_t cond_list;    /*< conditional variables that must be signaled when the action finish. */\r
+  void *data;              /**< @brief user data */\r
+  int refcount;            /**< @brief reference counter */\r
+  surf_action_t surf_action;    /* SURF modeling of computation  */\r
+  smx_host_t source;\r
+} s_smx_action_t;\r
+\r
+/******************************* Other **********************************/\r
+\r
+\r
+#define SIMIX_CHECK_HOST()  xbt_assert0(surf_workstation_model->extension.workstation. \\r
+                                 get_state(SIMIX_host_self()->host)==SURF_RESOURCE_ON,\\r
+                                  "Host failed, you cannot call this function.")\r
+\r
+smx_host_t __SIMIX_host_create(const char *name, void *workstation, void *data);\r
+void __SIMIX_host_destroy(void *host);\r
+void __SIMIX_cond_wait(smx_cond_t cond);\r
+void __SIMIX_cond_display_actions(smx_cond_t cond);\r
+void __SIMIX_action_display_conditions(smx_action_t action);\r
+void __SIMIX_create_maestro_process(void);\r
+\r
+/******************************** Context *************************************/\r
+\r
+int SIMIX_context_create_maestro(smx_process_t *process);\r
+\r
+int SIMIX_context_new(smx_process_t *process, xbt_main_func_t code);\r
+\rvoid SIMIX_context_kill(smx_process_t process);\r
+\rvoid SIMIX_context_start(smx_process_t process);\r
+\rvoid SIMIX_context_yield(void);\r
+\rvoid SIMIX_context_schedule(smx_process_t process);\r
+     \rvoid SIMIX_context_empty_trash(void);\r
+\r
+void SIMIX_context_stop(int exit_code);\r
+     \rvoid SIMIX_context_free(smx_process_t process);\r
+\r
+void SIMIX_context_mod_init(void);\r
+\r
+void SIMIX_context_mod_exit(void);\r
+#endif\r
index 3c45e55..6433680 100644 (file)
@@ -45,7 +45,7 @@ static void _XBT_CALL inthandler(int ignored)
 void SIMIX_global_init(int *argc, char **argv)
 {
   s_smx_process_t proc;
-
+  
   if (!simix_global) {
     /* Connect our log channels: that must be done manually under windows */
     XBT_LOG_CONNECT(simix_action, simix);
@@ -63,13 +63,20 @@ void SIMIX_global_init(int *argc, char **argv)
       xbt_swag_new(xbt_swag_offset(proc, synchro_hookup));
     simix_global->process_list =
       xbt_swag_new(xbt_swag_offset(proc, process_hookup));
+    simix_global->process_to_destroy =
+      xbt_swag_new(xbt_swag_offset(proc, destroy_hookup));
+
     simix_global->current_process = NULL;
+    simix_global->maestro_process = NULL;
     simix_global->registered_functions = xbt_dict_new();
 
     simix_global->create_process_function = NULL;
     simix_global->kill_process_function = NULL;
     simix_global->cleanup_process_function = SIMIX_process_cleanup;
 
+    SIMIX_context_mod_init();
+    __SIMIX_create_maestro_process();
+    
     /* Prepare to display some more info when dying on Ctrl-C pressing */
     signal(SIGINT, inthandler);
     surf_init(argc, argv);      /* Initialize SURF structures */
@@ -202,10 +209,10 @@ void SIMIX_process_killall()
       SIMIX_process_kill(p);
   }
 
-  xbt_context_empty_trash();
+  SIMIX_context_empty_trash();
 
   if (self) {
-    xbt_context_yield();
+    SIMIX_context_yield();
   }
 
   return;
@@ -226,13 +233,22 @@ void SIMIX_clean(void)
 
   xbt_dict_free(&(simix_global->host));
   xbt_swag_free(simix_global->process_to_run);
-  xbt_swag_free(simix_global->process_list);
   xbt_dict_free(&(simix_global->registered_functions));
   free(simix_global);
   simix_global = NULL;
 
   surf_exit();
 
+  /*FIXME Remove maestro's smx_process from the process_list before calling
+    SIMIX_context_mod_exit() and delete it afterwards (it should be the last one) */
+  SIMIX_context_mod_exit();
+  xbt_swag_free(simix_global->process_list);
+  xbt_swag_free(simix_global->process_to_destroy);
+
+  /* Let's free maestro */
+  SIMIX_context_free(simix_global->maestro_process);
+  free(simix_global->maestro_process);
+  
   return;
 }
 
@@ -273,7 +289,7 @@ double SIMIX_solve(xbt_fifo_t actions_done, xbt_fifo_t actions_failed)
   double elapsed_time = 0.0;
   static int state_modifications = 1;
 
-  xbt_context_empty_trash();
+  SIMIX_context_empty_trash();
   if (xbt_swag_size(simix_global->process_to_run) && (elapsed_time > 0)) {
     DEBUG0("**************************************************");
   }
@@ -282,7 +298,7 @@ double SIMIX_solve(xbt_fifo_t actions_done, xbt_fifo_t actions_failed)
     DEBUG2("Scheduling %s on %s",
            process->name, process->smx_host->name);
     simix_global->current_process = process;
-    xbt_context_schedule(process->context);
+    SIMIX_context_schedule(process);
     /*       fflush(NULL); */
     simix_global->current_process = NULL;
   }
index cd0487e..fd4a7df 100644 (file)
@@ -23,19 +23,41 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_process, simix,
  * \see SIMIX_process_create_with_arguments
  */
 
-
 void SIMIX_process_cleanup(void *arg)
 {
-  xbt_swag_remove(arg, simix_global->process_list);
   xbt_swag_remove(arg, simix_global->process_to_run);
-  xbt_swag_remove(arg,((smx_process_t) arg)->smx_host->process_list);
-  free(((smx_process_t) arg)->name);
-  ((smx_process_t) arg)->name = NULL;
-
-  free(arg);
+  xbt_swag_remove(arg, simix_global->process_list);
+  xbt_swag_insert(arg, simix_global->process_to_destroy);
 }
 
+
 /**
+ * \brief Creates and runs the maestro process
+ *
+ */
+
+void __SIMIX_create_maestro_process()
+{
+  smx_process_t process = NULL;
+  process = xbt_new0(s_smx_process_t, 1);
+
+  /* Process data */
+  process->name = (char *)"maestro";
+
+  /*Create the right context type (FIXME: check the return value for success)*/
+  SIMIX_context_create_maestro(&process);
+
+  /* Set it as the maestro process */
+  simix_global->maestro_process = process;
+  
+  /* Now insert it in the global process list and in the process to run list */
+  /* FIXME should it be included in the process_list ??? */
+  xbt_swag_insert(process, simix_global->process_list);
+
+  return;
+}
+
+/** 
  * \brief Creates and runs a new #smx_process_t.
  *
  * A constructor for #m_process_t taking four arguments and returning the corresponding object. The structure (and the corresponding thread) is created, and put in the list of ready process.
@@ -65,8 +87,6 @@ smx_process_t SIMIX_process_create(const char *name,
     return NULL;
   }
   process = xbt_new0(s_smx_process_t, 1);
-  /*char alias[MAX_ALIAS_NAME + 1] = {0};
-     msg_mailbox_t mailbox; */
 
   xbt_assert0(((code != NULL) && (host != NULL)), "Invalid parameters");
 
@@ -77,10 +97,13 @@ smx_process_t SIMIX_process_create(const char *name,
   process->argv = argv;
   process->mutex = NULL;
   process->cond = NULL;
-  process->context = xbt_context_new(name, code, NULL, NULL,
-                                     simix_global->cleanup_process_function,
-                                     process, process->argc, process->argv);
+
+  /*Create the right context type (FIXME: check the return value for success)*/
+  SIMIX_context_new(&process, code);
+
   process->data = data;
+  process->cleanup_func = simix_global->cleanup_process_function;
+  process->cleanup_arg = process;
 
   /* Add properties */
   process->properties = properties;
@@ -88,21 +111,16 @@ smx_process_t SIMIX_process_create(const char *name,
   /* Add the process to it's host process list */
   xbt_swag_insert(process, host->process_list);
 
-  /* fix current_process, about which xbt_context_start mocks around */
+  /* fix current_process, about which SIMIX_context_start mocks around */
   self = simix_global->current_process;
-  xbt_context_start(process->context);
+  SIMIX_context_start(process);
   simix_global->current_process = self;
 
-  /* Now insert it in the global process list */
+  /* Now insert it in the global process list and in the process to run list */
   xbt_swag_insert(process, simix_global->process_list);
   DEBUG2("Inserting %s(%s) in the to_run list", process->name, host->name);
   xbt_swag_insert(process, simix_global->process_to_run);
 
-  /*sprintf(alias,"%s:%s",hostname,process->name);
-
-     mailbox = MSG_mailbox_new(alias);
-     MSG_mailbox_set_hostname(mailbox, hostname); */
-
   return process;
 }
 
@@ -143,19 +161,18 @@ void SIMIX_jprocess_create(const char *name, smx_host_t host,
   process->argv = NULL;
   process->mutex = NULL;
   process->cond = NULL;
-  process->context = xbt_context_new(name, NULL, NULL, jprocess,
-                                     simix_global->cleanup_process_function,
-                                     process, 0, NULL);
+  SIMIX_context_new(&process, jprocess);
   process->data = data;
 
   /* Add the process to it's host process list */
-  xbt_swag_insert(process, host->process_list);
+  xbt_swag_insert(&process, host->process_list);
 
   /* fix current_process, about which xbt_context_start mocks around */
   self = simix_global->current_process;
-  xbt_context_start(process->context);
+  SIMIX_context_start(process);
   simix_global->current_process = self;
 
+  /* Now insert it in the global process list and in the process to run list */
   xbt_swag_insert(process, simix_global->process_list);
   DEBUG2("Inserting %s(%s) in the to_run list", process->name, host->name);
   xbt_swag_insert(process, simix_global->process_to_run);
@@ -181,12 +198,13 @@ void SIMIX_process_kill(smx_process_t process)
 
   xbt_swag_remove(process, simix_global->process_to_run);
   xbt_swag_remove(process, simix_global->process_list);
+
   DEBUG2("%p here! killing %p", simix_global->current_process, process);
-  xbt_context_kill(process->context);
+  SIMIX_context_kill(process);
 
   if (process == SIMIX_process_self()) {
     /* I just killed myself */
-    xbt_context_yield();
+    SIMIX_context_yield();
   }
 }
 
index 9a4cde6..46bb6b6 100644 (file)
@@ -51,12 +51,12 @@ void SIMIX_mutex_lock(smx_mutex_t mutex)
     xbt_swag_insert(self, mutex->sleeping);
     self->mutex = mutex;
     /* wait for some process make the unlock and wake up me from mutex->sleeping */
-    xbt_context_yield();
+    SIMIX_context_yield();
     self->mutex = NULL;
 
     /* verify if the process was suspended */
     while (self->suspended) {
-      xbt_context_yield();
+      SIMIX_context_yield();
     }
 
     mutex->refcount = 1;
@@ -213,10 +213,10 @@ void __SIMIX_cond_wait(smx_cond_t cond)
 
   self->cond = cond;
   xbt_swag_insert(self, cond->sleeping);
-  xbt_context_yield();
+  SIMIX_context_yield();
   self->cond = NULL;
   while (self->suspended) {
-    xbt_context_yield();
+    SIMIX_context_yield();
   }
   return;
 
index 8e1a7ae..da0da65 100644 (file)
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(xbt_context, xbt,
                                 "Context switching mecanism");
 
-/* the context associated with the current process                             */
-xbt_context_t current_context = NULL;
-
-/* the context associated with the maestro                                             */
-xbt_context_t maestro_context = NULL;
-
-/* this list contains the contexts to destroy                                  */
-xbt_swag_t context_to_destroy = NULL;
-
-/* this list contains the contexts in use                                              */
-xbt_swag_t context_living = NULL;
-
 /* the context factory used to create the appropriate context
  * each context implementation define its own context factory
  * a context factory is responsable of the creation of the context
@@ -36,83 +24,49 @@ xbt_swag_t context_living = NULL;
  * java implementation of the context and the java factory build
  * the context depending of this implementation.
  */
-static xbt_context_factory_t context_factory = NULL;
 
 /**
- * This function is call by the xbt_init() function to initialize the context module.
+ * This function is call by SIMIX_global_init() to initialize the context module.
  */
-void xbt_context_mod_init(void)
+void SIMIX_context_mod_init(void)
 {
-  if (!context_factory) {
+  if (!simix_global->context_factory) {
     /* select context factory to use to create the context(depends of the macro definitions) */
 
 #ifdef CONTEXT_THREADS
     /* context switch based os thread */
-    xbt_ctx_thread_factory_init(&context_factory);
+    SIMIX_ctx_thread_factory_init(&simix_global->context_factory);
 #elif !defined(WIN32)
     /* context switch based ucontext */
-    xbt_ctx_sysv_factory_init(&context_factory);
+    SIMIX_ctx_sysv_factory_init(&simix_global->context_factory);
 #else
     /* context switch is not allowed on Windows */
 #error ERROR [__FILE__, line __LINE__]: no context based implementation specified.
 #endif
-
-    /* maestro context specialisation (this create the maestro with the good implementation */
-    (*(context_factory->create_maestro_context)) (&maestro_context);
-
-    /* the current context is the context of the maestro */
-    current_context = maestro_context;
-
-    /* the current context doesn't want to die */
-    current_context->iwannadie = 0;
-
-    /* intantiation of the lists containing the contexts to destroy and the contexts in use */
-    context_to_destroy =
-      xbt_swag_new(xbt_swag_offset(*current_context, hookup));
-    context_living = xbt_swag_new(xbt_swag_offset(*current_context, hookup));
-
-    /* insert the current context in the list of the contexts in use */
-    xbt_swag_insert(current_context, context_living);
-
   }
 }
 
 /**
- * This function is call by the xbt_exit() function to finalize the context module.
+ * This function is call by SIMIX_clean() to finalize the context module.
  */
-void xbt_context_mod_exit(void)
+void SIMIX_context_mod_exit(void)
 {
-  if (context_factory) {
-    xbt_context_t context = NULL;
-    xbt_pfn_context_factory_finalize_t finalize_factory;
+  if (simix_global->context_factory) {
+    smx_process_t process = NULL;
+    smx_pfn_context_factory_finalize_t finalize_factory;
 
-    /* destroy all contexts in the list of contexts to destroy */
-    xbt_context_empty_trash();
-
-    /* remove the context of the scheduler from the list of the contexts in use */
-    xbt_swag_remove(maestro_context, context_living);
-
-    /*
-     * kill all the contexts in use :
-     * the killed contexts are added in the list of the contexts to destroy
-     */
-    while ((context = xbt_swag_extract(context_living)))
-      (*(context_factory->kill)) (context);
+    /* kill all the processes (except maestro)
+     * the killed processes are added in the list of the processes to destroy */
+    
+    while ((process = xbt_swag_extract(simix_global->process_list)))
+      (*(simix_global->context_factory->kill)) (process);
 
-    /* destroy all contexts in the list of contexts to destroy */
-    xbt_context_empty_trash();
+    /* destroy all processes in the list of process to destroy */
+    SIMIX_context_empty_trash();
 
     /* finalize the context factory */
-    finalize_factory = context_factory->finalize;
-
-    (*finalize_factory) (&context_factory);
-    
-    free(maestro_context);
-    maestro_context = current_context = NULL;
-
-    /* destroy the lists */
-    xbt_swag_free(context_to_destroy);    
-    xbt_swag_free(context_living);
+    finalize_factory = simix_global->context_factory->finalize;
+    (*finalize_factory) (&simix_global->context_factory);
   }
 }
 
@@ -120,35 +74,19 @@ void xbt_context_mod_exit(void)
 /* Object creation/destruction */
 /*******************************/
 /**
+ * \param smx_process the simix process that contains this context
  * \param code a main function
- * \param startup_func a function to call when running the context for
- *      the first time and just before the main function \a code
- * \param startup_arg the argument passed to the previous function (\a startup_func)
- * \param cleanup_func a function to call when running the context, just after
-        the termination of the main function \a code
- * \param cleanup_arg the argument passed to the previous function (\a cleanup_func)
- * \param argc first argument of function \a code
- * \param argv seconde argument of function \a code
  */
-xbt_context_t
-xbt_context_new(const char *name,
-                xbt_main_func_t code,
-                void_f_pvoid_t startup_func,
-                void *startup_arg,
-                void_f_pvoid_t cleanup_func,
-                void *cleanup_arg, int argc, char *argv[]
-  )
+int SIMIX_context_new(smx_process_t *process, xbt_main_func_t code)
 {
   /* use the appropriate context factory to create the appropriate context */
-  xbt_context_t context =
-    (*(context_factory->create_context)) (name, code, startup_func,
-                                          startup_arg, cleanup_func,
-                                          cleanup_arg, argc, argv);
+    return (*(simix_global->context_factory->create_context)) (process, code);
+}
 
-  /* add the context in the list of the contexts in use */
-  xbt_swag_insert(context, context_living);
 
-  return context;
+int SIMIX_context_create_maestro(smx_process_t *process)
+{
+  return (*(simix_global->context_factory->create_maestro_context)) (process);
 }
 
 /* Scenario for the end of a context:
@@ -174,117 +112,110 @@ xbt_context_new(const char *name,
 
 
 /* Argument must be stopped first -- runs in maestro context */
-void xbt_context_free(xbt_context_t context)
+void SIMIX_context_free(smx_process_t process)
 {
-  (*(context_factory->free)) (context);
+  (*(simix_global->context_factory->free)) (process);
 }
 
-
-void xbt_context_kill(xbt_context_t context)
+void SIMIX_context_kill(smx_process_t process)
 {
-  (*(context_factory->kill)) (context);
+  (*(simix_global->context_factory->kill)) (process);
 }
 
 /**
  * \param context the context to start
  *
- * Calling this function prepares \a context to be run. It will
-   however run effectively only when calling #xbt_context_schedule
+ * Calling this function prepares \a process to be run. It will
+   however run effectively only when calling #SIMIX_context_schedule
  */
-void xbt_context_start(xbt_context_t context)
+void SIMIX_context_start(smx_process_t process)
 {
-  (*(context_factory->start)) (context);
+  (*(simix_global->context_factory->start)) (process);
 }
 
 /**
- * Calling this function makes the current context yield. The context
- * that scheduled it returns from xbt_context_schedule as if nothing
+ * Calling this function makes the current process yield. The process
+ * that scheduled it returns from SIMIX_context_schedule as if nothing
  * had happened.
  *
  * Only the processes can call this function, giving back the control
  * to the maestro
  */
-void xbt_context_yield(void)
+void SIMIX_context_yield(void)
 {
-  (*(context_factory->yield)) ();
+  (*(simix_global->context_factory->yield)) ();
 }
 
 /**
- * \param context the winner
+ * \param process to be scheduled
  *
- * Calling this function blocks the current context and schedule \a context.
- * When \a context will call xbt_context_yield, it will return
+ * Calling this function blocks the current process and schedule \a process.
+ * When \a process would call SIMIX_context_yield, it will return
  * to this function as if nothing had happened.
  *
  * Only the maestro can call this function to run a given process.
  */
-void xbt_context_schedule(xbt_context_t context)
+void SIMIX_context_schedule(smx_process_t process)
 {
-  (*(context_factory->schedule)) (context);
+  (*(simix_global->context_factory->schedule)) (process);
 }
 
-void xbt_context_stop(int exit_code)
+void SIMIX_context_stop(int exit_code)
 {
-
-  (*(context_factory->stop)) (exit_code);
+  (*(simix_global->context_factory->stop)) (exit_code);
 }
 
-int xbt_context_select_factory(const char *name)
+int SIMIX_context_select_factory(const char *name)
 {
-  /* if a factory is already instantiated (xbt_context_mod_init() was called) */
-  if (NULL != context_factory) {
-    /* if the desired factory is different of the current factory, call xbt_context_mod_exit() */
-    if (strcmp(context_factory->name, name))
-      xbt_context_mod_exit();
+  /* if a factory is already instantiated (SIMIX_context_mod_init() was called) */
+  if (simix_global->context_factory != NULL) {
+    /* if the desired factory is different of the current factory, call SIMIX_context_mod_exit() */
+    if (strcmp(simix_global->context_factory->name, name))
+      SIMIX_context_mod_exit();
     else
       /* the same context factory is requested return directly */
       return 0;
   }
 
   /* get the desired factory */
-  xbt_context_init_factory_by_name(&context_factory, name);
+  SIMIX_context_init_factory_by_name(&simix_global->context_factory, name);
 
-  /* maestro context specialisation */
-  (*(context_factory->create_maestro_context)) (&maestro_context);
+  /* maestro process specialisation */
+  (*(simix_global->context_factory->create_maestro_context)) (&simix_global->maestro_process);
 
-  /* the current context is the context of the maestro */
-  current_context = maestro_context;
+  /* the current process is the process of the maestro */
+  simix_global->current_process = simix_global->maestro_process;
 
   /* the current context doesn't want to die */
-  current_context->iwannadie = 0;
-
-  /* intantiation of the lists containing the contexts to destroy and the contexts in use */
-  context_to_destroy =
-    xbt_swag_new(xbt_swag_offset(*current_context, hookup));
-  context_living = xbt_swag_new(xbt_swag_offset(*current_context, hookup));
+  simix_global->current_process->iwannadie = 0;
 
   /* insert the current context in the list of the contexts in use */
-  xbt_swag_insert(current_context, context_living);
+  xbt_swag_insert(simix_global->current_process, simix_global->process_list);
 
   return 0;
 }
 
 void
-xbt_context_init_factory_by_name(xbt_context_factory_t * factory,
-                                 const char *name)
+SIMIX_context_init_factory_by_name(smx_context_factory_t * factory,
+                                   const char *name)
 {
   if (!strcmp(name, "java"))
 #ifdef HAVE_JAVA     
-    xbt_ctx_java_factory_init(factory);
+    SIMIX_ctx_java_factory_init(factory);
 #else
     THROW0(not_found_error, 0, "Factory 'Java' does not exist: Java support was not compiled in the SimGrid library");
 #endif /* HAVE_JAVA */
    
   else if (!strcmp(name, "thread"))
 #ifdef CONTEXT_THREADS
-    xbt_ctx_thread_factory_init(factory);
+    SIMIX_ctx_thread_factory_init(factory);
 #else
     THROW0(not_found_error, 0, "Factory 'thread' does not exist: thread support was not compiled in the SimGrid library");
 #endif /* CONTEXT_THREADS */
    
   else if (!strcmp(name, "sysv"))
 #if !defined(WIN32) && !defined(CONTEXT_THREADS)
-    xbt_ctx_sysv_factory_init(factory);
+    SIMIX_ctx_sysv_factory_init(factory);
 #else
     THROW0(not_found_error, 0, "Factory 'sysv' does not exist: no System V thread support under Windows");
 #endif   
@@ -294,13 +225,27 @@ xbt_context_init_factory_by_name(xbt_context_factory_t * factory,
 
 /** Garbage collection
  *
- * Should be called some time to time to free the memory allocated for contexts
- * that have finished executing their main functions.
+ * Should be called some time to time to free the memory allocated for processes
+ * that have finished (or killed).
  */
-void xbt_context_empty_trash(void)
-{
-  xbt_context_t context = NULL;
-
-  while ((context = xbt_swag_extract(context_to_destroy)))
-    (*(context_factory->free)) (context);
-}
+void SIMIX_context_empty_trash(void)
+{ 
+  smx_process_t process = NULL;
+  int i;  
+
+  while ((process = xbt_swag_extract(simix_global->process_to_destroy))){
+
+    free(process->name);
+    process->name = NULL;
+  
+    if (process->argv) {
+      for (i = 0; i < process->argc; i++)
+        if (process->argv[i])
+          free(process->argv[i]);
+
+      free(process->argv);
+    }
+  
+    free(process);
+  }
+}
\ No newline at end of file
index c5a7693..a76e489 100644 (file)
@@ -9,8 +9,8 @@
 #ifndef _XBT_CONTEXT_PRIVATE_H
 #define _XBT_CONTEXT_PRIVATE_H
 
-#include "xbt/sysdep.h"
-#include "simix/context.h"
+/*#include "xbt/sysdep.h"*/
+#include "simix/private.h"
 #include "xbt/swag.h"
 
 SG_BEGIN_DECL()
@@ -24,101 +24,78 @@ SG_BEGIN_DECL()
 /* each context type must contain this macro at its begining -- OOP in C :/ */
 #define XBT_CTX_BASE_T \
   s_xbt_swag_hookup_t hookup; \
-  char *name; \
-  void_f_pvoid_t cleanup_func; \
-  void *cleanup_arg; \
   ex_ctx_t *exception; \
-  int iwannadie; \
   xbt_main_func_t code; \
-  int argc; \
-  char **argv; \
-  void_f_pvoid_t startup_func; \
-  void *startup_arg;
 
 /* all other context types derive from this structure */
 typedef struct s_xbt_context {
   XBT_CTX_BASE_T;
 } s_xbt_context_t;
 
-/* ****************** */
-/* Globals definition */
-/* ****************** */
-
-/* Important guys */
-extern xbt_context_t current_context;
-extern xbt_context_t maestro_context;
-
-/* All dudes lists */
-extern xbt_swag_t context_living;
-extern xbt_swag_t context_to_destroy;
-
 /* *********************** */
 /* factory type definition */
 /* *********************** */
 
-typedef struct s_xbt_context_factory *xbt_context_factory_t;
-
 /* The following function pointer types describe the interface that any context 
    factory should implement */
 
 /* function used to create a new context */
-typedef xbt_context_t (*xbt_pfn_context_factory_create_context_t)
-  (const char *, xbt_main_func_t, void_f_pvoid_t, void *, void_f_pvoid_t, void *, int, char **);
+typedef int (*smx_pfn_context_factory_create_context_t) (smx_process_t *, xbt_main_func_t);
 
 /* function used to create the context for the maestro process */
-typedef int (*xbt_pfn_context_factory_create_maestro_context_t) (xbt_context_t*);
+typedef int (*smx_pfn_context_factory_create_maestro_context_t) (smx_process_t*);
 
 /* this function finalize the specified context factory */
-typedef int (*xbt_pfn_context_factory_finalize_t) (xbt_context_factory_t*);
+typedef int (*smx_pfn_context_factory_finalize_t) (smx_context_factory_t*);
 
 /* function used to destroy the specified context */
-typedef void (*xbt_pfn_context_free_t) (xbt_context_t);
+typedef void (*smx_pfn_context_free_t) (smx_process_t);
 
 /* function used to kill the specified context */
-typedef void (*xbt_pfn_context_kill_t) (xbt_context_t);
+typedef void (*smx_pfn_context_kill_t) (smx_process_t);
 
 /* function used to resume the specified context */
-typedef void (*xbt_pfn_context_schedule_t) (xbt_context_t);
+typedef void (*smx_pfn_context_schedule_t) (smx_process_t);
 
 /* function used to yield the specified context */
-typedef void (*xbt_pfn_context_yield_t) (void);
+typedef void (*smx_pfn_context_yield_t) (void);
 
 /* function used to start the specified context */
-typedef void (*xbt_pfn_context_start_t) (xbt_context_t);
+typedef void (*smx_pfn_context_start_t) (smx_process_t);
 
 /* function used to stop the current context */
-typedef void (*xbt_pfn_context_stop_t) (int);
+typedef void (*smx_pfn_context_stop_t) (int);
 
 /* interface of the context factories */
-typedef struct s_xbt_context_factory {
-  xbt_pfn_context_factory_create_maestro_context_t create_maestro_context;
-  xbt_pfn_context_factory_create_context_t create_context;
-  xbt_pfn_context_factory_finalize_t finalize;
-  xbt_pfn_context_free_t free;
-  xbt_pfn_context_kill_t kill;
-  xbt_pfn_context_schedule_t schedule;
-  xbt_pfn_context_yield_t yield;
-  xbt_pfn_context_start_t start;
-  xbt_pfn_context_stop_t stop;
+typedef struct s_smx_context_factory {
+  smx_pfn_context_factory_create_maestro_context_t create_maestro_context;
+  smx_pfn_context_factory_create_context_t create_context;
+  smx_pfn_context_factory_finalize_t finalize;
+  smx_pfn_context_free_t free;
+  smx_pfn_context_kill_t kill;
+  smx_pfn_context_schedule_t schedule;
+  smx_pfn_context_yield_t yield;
+  smx_pfn_context_start_t start;
+  smx_pfn_context_stop_t stop;
   const char *name;
-} s_xbt_context_factory_t;
+} s_smx_context_factory_t;
 
 /* Selects a context factory associated with the name specified by the parameter name.
  * If successful the function returns 0. Otherwise the function returns the error code.
  */
-int xbt_context_select_factory(const char *name);
+int SIMIX_context_select_factory(const char *name);
 
 /* Initializes a context factory from the name specified by the parameter name.
  * If the factory cannot be found, an exception is raised.
  */
-void xbt_context_init_factory_by_name(xbt_context_factory_t * factory, const char *name);
+void SIMIX_context_init_factory_by_name(smx_context_factory_t * factory, const char *name);
 
 /* All factories init */
-void xbt_ctx_thread_factory_init(xbt_context_factory_t * factory);
+void SIMIX_ctx_thread_factory_init(smx_context_factory_t * factory);
 
-void xbt_ctx_sysv_factory_init(xbt_context_factory_t * factory);
+void SIMIX_ctx_sysv_factory_init(smx_context_factory_t * factory);
 
-void xbt_ctx_java_factory_init(xbt_context_factory_t * factory);
+void SIMIX_ctx_java_factory_init(smx_context_factory_t * factory);
 
 SG_END_DECL()
 #endif /* !_XBT_CONTEXT_PRIVATE_H */
\ No newline at end of file
index 28f5a9f..c091538 100644 (file)
@@ -22,12 +22,12 @@ XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(xbt_context);
 
 typedef struct s_xbt_ctx_sysv {
   XBT_CTX_BASE_T;
-  ucontext_t uc;                /* the thread that execute the code                             */
-  char stack[STACK_SIZE];       /* the thread stack size                                        */
-  struct s_xbt_ctx_sysv *prev;  /* the previous thread                                          */
+  ucontext_t uc;                /* the thread that execute the code */
+  char stack[STACK_SIZE];       /* the thread stack size */
+  smx_process_t prev;           /* the previous process */
 #ifdef HAVE_VALGRIND_VALGRIND_H
-  unsigned int valgrind_stack_id;       /* the valgrind stack id.       */
-#endif                          /* HAVE_VALGRIND_VALGRIND_H */
+  unsigned int valgrind_stack_id;       /* the valgrind stack id */
+#endif                          
 } s_xbt_ctx_sysv_t, *xbt_ctx_sysv_t;
 
 
@@ -37,46 +37,41 @@ static ex_ctx_t *xbt_jcontext_ex_ctx(void);
 /* callback: termination */
 static void xbt_jcontext_ex_terminate(xbt_ex_t * e);
 
-static xbt_context_t
-xbt_ctx_sysv_factory_create_context(const char *name, xbt_main_func_t code,
-                                    void_f_pvoid_t startup_func,
-                                    void *startup_arg,
-                                    void_f_pvoid_t cleanup_func,
-                                    void *cleanup_arg, int argc, char **argv);
+static int
+smx_ctx_sysv_factory_create_context(smx_process_t *smx_process, xbt_main_func_t code);
 
-static int xbt_ctx_sysv_factory_finalize(xbt_context_factory_t * factory);
+static int smx_ctx_sysv_factory_finalize(smx_context_factory_t * factory);
 
-static int
-xbt_ctx_sysv_factory_create_maestro_context(xbt_context_t * maestro);
+static int smx_ctx_sysv_factory_create_maestro_context(smx_process_t * maestro);
 
-static void xbt_ctx_sysv_free(xbt_context_t context);
+static void smx_ctx_sysv_free(smx_process_t process);
 
-static void xbt_ctx_sysv_kill(xbt_context_t context);
+static void smx_ctx_sysv_kill(smx_process_t process);
 
-static void xbt_ctx_sysv_schedule(xbt_context_t context);
+static void smx_ctx_sysv_schedule(smx_process_t process);
 
-static void xbt_ctx_sysv_yield(void);
+static void smx_ctx_sysv_yield(void);
 
-static void xbt_ctx_sysv_start(xbt_context_t context);
+static void smx_ctx_sysv_start(smx_process_t process);
 
-static void xbt_ctx_sysv_stop(int exit_code);
+static void smx_ctx_sysv_stop(int exit_code);
 
-static void xbt_ctx_sysv_swap(xbt_context_t context);
+static void smx_ctx_sysv_swap(smx_process_t process);
 
-static void xbt_ctx_sysv_schedule(xbt_context_t context);
+static void smx_ctx_sysv_schedule(smx_process_t process);
 
-static void xbt_ctx_sysv_yield(void);
+static void smx_ctx_sysv_yield(void);
 
-static void xbt_ctx_sysv_suspend(xbt_context_t context);
+static void smx_ctx_sysv_suspend(smx_process_t process);
 
-static void xbt_ctx_sysv_resume(xbt_context_t context);
+static void smx_ctx_sysv_resume(smx_process_t process);
 
-static void xbt_ctx_sysv_wrapper(void);
+static void smx_ctx_sysv_wrapper(void);
 
 /* callback: context fetching */
 static ex_ctx_t *xbt_ctx_sysv_ex_ctx(void)
 {
-  return current_context->exception;
+  return simix_global->current_process->context->exception;
 }
 
 /* callback: termination */
@@ -86,65 +81,55 @@ static void xbt_ctx_sysv_ex_terminate(xbt_ex_t * e)
   abort();
 }
 
-
-void xbt_ctx_sysv_factory_init(xbt_context_factory_t * factory)
+void SIMIX_ctx_sysv_factory_init(smx_context_factory_t * factory)
 {
-  *factory = xbt_new0(s_xbt_context_factory_t, 1);
-
-  (*factory)->create_context = xbt_ctx_sysv_factory_create_context;
-  (*factory)->finalize = xbt_ctx_sysv_factory_finalize;
-  (*factory)->create_maestro_context = xbt_ctx_sysv_factory_create_maestro_context;
-  (*factory)->free = xbt_ctx_sysv_free;
-  (*factory)->kill = xbt_ctx_sysv_kill;
-  (*factory)->schedule = xbt_ctx_sysv_schedule;
-  (*factory)->yield = xbt_ctx_sysv_yield;
-  (*factory)->start = xbt_ctx_sysv_start;
-  (*factory)->stop = xbt_ctx_sysv_stop;
-  (*factory)->name = "ctx_sysv_context_factory";
+  *factory = xbt_new0(s_smx_context_factory_t, 1);
+
+  (*factory)->create_context = smx_ctx_sysv_factory_create_context;
+  (*factory)->finalize = smx_ctx_sysv_factory_finalize;
+  (*factory)->create_maestro_context = smx_ctx_sysv_factory_create_maestro_context;
+  (*factory)->free = smx_ctx_sysv_free;
+  (*factory)->kill = smx_ctx_sysv_kill;
+  (*factory)->schedule = smx_ctx_sysv_schedule;
+  (*factory)->yield = smx_ctx_sysv_yield;
+  (*factory)->start = smx_ctx_sysv_start;
+  (*factory)->stop = smx_ctx_sysv_stop;
+  (*factory)->name = "smx_sysv_context_factory";
 
   /* context exception handlers */
   __xbt_ex_ctx = xbt_ctx_sysv_ex_ctx;
   __xbt_ex_terminate = xbt_ctx_sysv_ex_terminate;
 }
 
-static int
-xbt_ctx_sysv_factory_create_maestro_context(xbt_context_t * maestro)
+static int smx_ctx_sysv_factory_create_maestro_context(smx_process_t *maestro)
 {
-
   xbt_ctx_sysv_t context = xbt_new0(s_xbt_ctx_sysv_t, 1);
 
-  context->name = (char *) "maestro";
-
   context->exception = xbt_new(ex_ctx_t, 1);
   XBT_CTX_INITIALIZE(context->exception);
 
-  *maestro = (xbt_context_t) context;
+  (*maestro)->context = (xbt_context_t) context;
 
   return 0;
 
 }
 
 
-static int xbt_ctx_sysv_factory_finalize(xbt_context_factory_t * factory)
+static int smx_ctx_sysv_factory_finalize(smx_context_factory_t * factory)
 {
-  free(maestro_context->exception);
+  /*FIXME free(maestro_context->exception);*/
   free(*factory);
   *factory = NULL;
   return 0;
 }
 
-static xbt_context_t
-xbt_ctx_sysv_factory_create_context(const char *name, xbt_main_func_t code,
-                                    void_f_pvoid_t startup_func,
-                                    void *startup_arg,
-                                    void_f_pvoid_t cleanup_func,
-                                    void *cleanup_arg, int argc, char **argv)
+static int
+smx_ctx_sysv_factory_create_context(smx_process_t *smx_process, xbt_main_func_t code)
 {
-  VERB1("Create context %s", name);
+  VERB1("Create context %s", (*smx_process)->name);
   xbt_ctx_sysv_t context = xbt_new0(s_xbt_ctx_sysv_t, 1);
 
   context->code = code;
-  context->name = xbt_strdup(name);
 
   xbt_assert2(getcontext(&(context->uc)) == 0,
               "Error in context saving: %d (%s)", errno, strerror(errno));
@@ -162,31 +147,17 @@ xbt_ctx_sysv_factory_create_context(const char *name, xbt_main_func_t code,
 
   context->exception = xbt_new(ex_ctx_t, 1);
   XBT_CTX_INITIALIZE(context->exception);
-  context->iwannadie = 0;       /* useless but makes valgrind happy */
-  context->argc = argc;
-  context->argv = argv;
-  context->startup_func = startup_func;
-  context->startup_arg = startup_arg;
-  context->cleanup_func = cleanup_func;
-  context->cleanup_arg = cleanup_arg;
-
-  return (xbt_context_t) context;
+  (*smx_process)->context = (xbt_context_t)context;
+  (*smx_process)->iwannadie = 0;
+
+  /* FIXME: Check what should return */
+  return 1;
 }
 
-static void xbt_ctx_sysv_free(xbt_context_t context)
+static void smx_ctx_sysv_free(smx_process_t process)
 {
-  if (context) {
-    free(context->name);
-
-    if (context->argv) {
-      int i;
-
-      for (i = 0; i < context->argc; i++)
-        if (context->argv[i])
-          free(context->argv[i]);
-
-      free(context->argv);
-    }
+  xbt_ctx_sysv_t context = (xbt_ctx_sysv_t)process->context;   
+  if (context){
 
     if (context->exception)
       free(context->exception);
@@ -195,17 +166,17 @@ static void xbt_ctx_sysv_free(xbt_context_t context)
     VALGRIND_STACK_DEREGISTER(((xbt_ctx_sysv_t) context)->valgrind_stack_id);
 #endif /* HAVE_VALGRIND_VALGRIND_H */
 
-    /* finally destroy the context */
+    /* destroy the context */
     free(context);
   }
 }
 
-static void xbt_ctx_sysv_kill(xbt_context_t context)
+static void smx_ctx_sysv_kill(smx_process_t process)
 {
-  DEBUG2("Kill context '%s' (from '%s')", context->name,
-         current_context->name);
-  context->iwannadie = 1;
-  xbt_ctx_sysv_swap(context);
+  DEBUG2("Kill process '%s' (from '%s')", process->name,
+         simix_global->current_process->name);
+  process->iwannadie = 1;
+  smx_ctx_sysv_swap(process);
 }
 
 /** 
@@ -217,12 +188,12 @@ static void xbt_ctx_sysv_kill(xbt_context_t context)
  * 
  * Only the maestro can call this function to run a given process.
  */
-static void xbt_ctx_sysv_schedule(xbt_context_t context)
+static void smx_ctx_sysv_schedule(smx_process_t process)
 {
-  DEBUG1("Schedule context '%s'", context->name);
-  xbt_assert0((current_context == maestro_context),
+  DEBUG1("Schedule process '%s'", process->name);
+  xbt_assert0((simix_global->current_process == simix_global->maestro_process),
               "You are not supposed to run this function here!");
-  xbt_ctx_sysv_swap(context);
+  smx_ctx_sysv_swap(process);
 }
 
 /** 
@@ -233,84 +204,80 @@ static void xbt_ctx_sysv_schedule(xbt_context_t context)
  * Only the processes can call this function, giving back the control
  * to the maestro
  */
-static void xbt_ctx_sysv_yield(void)
+static void smx_ctx_sysv_yield(void)
 {
-  DEBUG1("Yielding context '%s'", current_context->name);
-  xbt_assert0((current_context != maestro_context),
+  DEBUG1("Yielding context '%s'", simix_global->current_process->name);
+  xbt_assert0((simix_global->current_process != simix_global->maestro_process),
               "You are not supposed to run this function here!");
-  xbt_ctx_sysv_swap(current_context);
+  smx_ctx_sysv_swap(simix_global->current_process);
 }
 
-static void xbt_ctx_sysv_start(xbt_context_t context)
+static void smx_ctx_sysv_start(smx_process_t process)
 {
-  DEBUG1("Start context '%s'", context->name);
-  makecontext(&(((xbt_ctx_sysv_t) context)->uc), xbt_ctx_sysv_wrapper, 0);
+  /*DEBUG1("Start context '%s'", context->name);*/
+  makecontext(&(((xbt_ctx_sysv_t) process->context)->uc), smx_ctx_sysv_wrapper, 0);
 }
 
-static void xbt_ctx_sysv_stop(int exit_code)
+static void smx_ctx_sysv_stop(int exit_code)
 {
   /* please no debug here: our procdata was already free'd */
-  if (current_context->cleanup_func)
-    ((*current_context->cleanup_func)) (current_context->cleanup_arg);
+  if (simix_global->current_process->cleanup_func)
+    ((*simix_global->current_process->cleanup_func)) (simix_global->current_process->cleanup_arg);
 
-  xbt_swag_remove(current_context, context_living);
-  xbt_swag_insert(current_context, context_to_destroy);
-
-  xbt_ctx_sysv_swap(current_context);
+  smx_ctx_sysv_swap(simix_global->current_process);
 }
 
-static void xbt_ctx_sysv_swap(xbt_context_t context)
+static void smx_ctx_sysv_swap(smx_process_t process)
 {
-  DEBUG2("Swap context: '%s' -> '%s'", current_context->name, context->name);
-  xbt_assert0(current_context, "You have to call context_init() first.");
-  xbt_assert0(context, "Invalid argument");
+  DEBUG2("Swap context: '%s' -> '%s'", simix_global->current_process->name, process->name);
+  xbt_assert0(simix_global->current_process, "You have to call context_init() first.");
+  xbt_assert0(process, "Invalid argument");
 
-  if (((xbt_ctx_sysv_t) context)->prev == NULL)
-    xbt_ctx_sysv_resume(context);
+  if (((xbt_ctx_sysv_t) process->context)->prev == NULL)
+    smx_ctx_sysv_resume(process);
   else
-    xbt_ctx_sysv_suspend(context);
+    smx_ctx_sysv_suspend(process);
 
-  if (current_context->iwannadie)
-    xbt_ctx_sysv_stop(1);
+  if (simix_global->current_process->iwannadie)
+    smx_ctx_sysv_stop(1);
 }
 
-static void xbt_ctx_sysv_wrapper(void)
+static void smx_ctx_sysv_wrapper(void)
 {
-  if (current_context->startup_func)
-    (*current_context->startup_func) (current_context->startup_arg);
-
-  xbt_ctx_sysv_stop((*(current_context->code))
-                    (current_context->argc, current_context->argv));
+  smx_ctx_sysv_stop((*(simix_global->current_process->context->code))
+                    (simix_global->current_process->argc, simix_global->current_process->argv));
 }
 
-static void xbt_ctx_sysv_suspend(xbt_context_t context)
+static void smx_ctx_sysv_suspend(smx_process_t process)
 {
   int rv;
 
-  DEBUG1("Suspend context: '%s'", current_context->name);
-  xbt_ctx_sysv_t prev_context = ((xbt_ctx_sysv_t) context)->prev;
+  DEBUG1("Suspend context: '%s'", simix_global->current_process->name);
+  smx_process_t prev_process = ((xbt_ctx_sysv_t) process->context)->prev;
 
-  current_context = (xbt_context_t) (((xbt_ctx_sysv_t) context)->prev);
+  simix_global->current_process = (smx_process_t) (((xbt_ctx_sysv_t) process->context)->prev);
 
-  ((xbt_ctx_sysv_t) context)->prev = NULL;
+  ((xbt_ctx_sysv_t) process->context)->prev = NULL;
 
-  rv = swapcontext(&(((xbt_ctx_sysv_t) context)->uc), &(prev_context->uc));
+  rv = swapcontext(&(((xbt_ctx_sysv_t) process->context)->uc), &(((xbt_ctx_sysv_t)prev_process->context)->uc));
 
   xbt_assert0((rv == 0), "Context swapping failure");
 }
 
-static void xbt_ctx_sysv_resume(xbt_context_t context)
+static void smx_ctx_sysv_resume(smx_process_t process)
 {
   int rv;
+  xbt_ctx_sysv_t new_context = (xbt_ctx_sysv_t)process->context;
+  xbt_ctx_sysv_t prev_context = (xbt_ctx_sysv_t)simix_global->current_process->context;
+
+  DEBUG2("Resume context: '%s' (from '%s')", process->name,
+         simix_global->current_process->name);
 
-  DEBUG2("Resume context: '%s' (from '%s')", context->name,
-         current_context->name);
-  ((xbt_ctx_sysv_t) context)->prev = (xbt_ctx_sysv_t) current_context;
+  ((xbt_ctx_sysv_t) process->context)->prev = simix_global->current_process;
 
-  current_context = context;
+  simix_global->current_process = process;
 
-  rv = swapcontext(&(((xbt_ctx_sysv_t) context)->prev->uc),
-                   &(((xbt_ctx_sysv_t) context)->uc));
+  rv = swapcontext(&prev_context->uc, &new_context->uc);
 
   xbt_assert0((rv == 0), "Context swapping failure");
 }
index a533533..123f4df 100644 (file)
@@ -85,7 +85,6 @@ void xbt_init(int *argc, char **argv)
   xbt_backtrace_init();
   xbt_log_init(argc, argv);
   xbt_os_thread_mod_init();
-  xbt_context_mod_init();
 }
 
 /** @brief Finalize the xbt mechanisms. */
@@ -95,7 +94,6 @@ void xbt_exit()
   if (xbt_initialized == 0) {
     xbt_fifo_exit();
     xbt_dict_exit();
-    xbt_context_mod_exit();
     xbt_os_thread_mod_exit();
     xbt_log_exit();
     xbt_backtrace_exit();
index ab2be1f..eed7105 100644 (file)
@@ -20,9 +20,6 @@ void xbt_log_exit(void);
 void xbt_fifo_exit(void);
 void xbt_dict_exit(void);
 
-void xbt_context_mod_init(void);
-void xbt_context_mod_exit(void);
-
 void xbt_os_thread_mod_init(void);
 void xbt_os_thread_mod_exit(void);