Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Completely remove surfxml_callback.
authornavarro <navarro@caraja.(none)>
Tue, 7 Aug 2012 14:32:00 +0000 (16:32 +0200)
committernavarro <navarro@caraja.(none)>
Tue, 7 Aug 2012 14:32:20 +0000 (16:32 +0200)
Clean the way to create arg for the process.

include/simgrid/platf.h
include/surf/surfxml_parse.h
src/include/simgrid/platf_interface.h
src/simix/smx_deployment.c
src/surf/sg_platf.c
src/surf/surfxml_parse.c
tools/gras/stub_generator.c

index 53b3986..00c9192 100644 (file)
@@ -65,6 +65,12 @@ typedef enum {
   SURF_TRACE_CONNECT_KIND_BANDWIDTH = 1,
   SURF_TRACE_CONNECT_KIND_LATENCY = 0
 } e_surf_trace_connect_kin_t;
+
+typedef enum {
+  SURF_PROCESS_ON_FAILURE_DIE = 1,
+  SURF_PROCESS_ON_FAILURE_RESTART = 0
+} e_surf_process_on_failure_t;
+
 /*
  * Platform creation functions. Instead of passing 123 arguments to the creation functions
  * (one for each possible XML attribute), we pass structures containing them all. It removes the
@@ -234,6 +240,23 @@ typedef struct s_sg_platf_trace_connect_cbarg {
   const char *element;
 } s_sg_platf_trace_connect_cbarg_t;
 
+typedef struct s_sg_platf_arg_cbarg *sg_platf_arg_cbarg_t;
+typedef struct s_sg_platf_arg_cbarg {
+  const char *value;
+} s_sg_platf_arg_cbarg_t;
+
+typedef struct s_sg_platf_process_cbarg *sg_platf_process_cbarg_t;
+typedef struct s_sg_platf_process_cbarg {
+  const char **argv;
+  int argc;
+  xbt_dict_t properties;
+  const char *host;
+  const char *function;
+  double start_time;
+  double kill_time;
+  e_surf_process_on_failure_t on_failure;
+} s_sg_platf_process_cbarg_t;
+
 XBT_PUBLIC(void) sg_platf_begin(void);  // Start a new platform
 XBT_PUBLIC(void) sg_platf_end(void); // Finish the creation of the platform
 
@@ -264,4 +287,7 @@ XBT_PUBLIC(void) sg_platf_new_mstorage(sg_platf_mstorage_cbarg_t mstorage);
 XBT_PUBLIC(void) sg_platf_new_storage_type(sg_platf_storage_type_cbarg_t storage_type);
 XBT_PUBLIC(void) sg_platf_new_mount(sg_platf_mount_cbarg_t mount);
 
+XBT_PUBLIC(void) sg_platf_new_process(sg_platf_process_cbarg_t process);
+XBT_PUBLIC(void) sg_platf_new_arg(sg_platf_arg_cbarg_t arg);
+
 #endif                          /* SG_PLATF_H */
index 031041d..3564ab7 100644 (file)
 
 SG_BEGIN_DECL()
 
-/* Hook for the different tags. All the functions which pointer to are push into here are run when the tag is encountered */
-XBT_PUBLIC_DATA(xbt_dynar_t) STag_surfxml_process_cb_list;
-XBT_PUBLIC_DATA(xbt_dynar_t) ETag_surfxml_process_cb_list;
-XBT_PUBLIC_DATA(xbt_dynar_t) STag_surfxml_argument_cb_list;
-XBT_PUBLIC_DATA(xbt_dynar_t) ETag_surfxml_argument_cb_list;
-
 XBT_PUBLIC(void) surf_parse_open(const char *file);
 XBT_PUBLIC(void) surf_parse_close(void);
 XBT_PUBLIC(void) surf_parse_init_callbacks(void);
@@ -74,10 +68,5 @@ extern unsigned int surfxml_buffer_stack_stack[1024];
     ETag_surfxml_##tag();                                               \
   } while(0)
 
-XBT_PUBLIC(void) surfxml_add_callback(xbt_dynar_t cb_list,
-                                      void_f_void_t function);
-XBT_PUBLIC(void) surfxml_del_callback(xbt_dynar_t cb_list,
-                                      void_f_void_t function);
-
 SG_END_DECL()
 #endif
index 9767ced..b424cdd 100644 (file)
@@ -42,6 +42,9 @@ typedef void (*sg_platf_storage_type_cb_t)(sg_platf_storage_type_cbarg_t);
 typedef void (*sg_platf_mount_cb_t)(sg_platf_mount_cbarg_t);
 typedef void (*sg_platf_mstorage_cb_t)(sg_platf_mstorage_cbarg_t);
 
+typedef void (*sg_platf_process_cb_t)(sg_platf_process_cbarg_t);
+typedef void (*sg_platf_arg_cb_t)(sg_platf_arg_cbarg_t);
+
 void sg_platf_host_add_cb(sg_platf_host_cb_t);
 void sg_platf_host_link_add_cb(sg_platf_host_link_cb_t);
 void sg_platf_router_add_cb(sg_platf_router_cb_t);
@@ -68,6 +71,8 @@ void sg_platf_mstorage_add_cb(sg_platf_mstorage_cb_t fct);
 void sg_platf_storage_type_add_cb(sg_platf_storage_type_cb_t fct);
 void sg_platf_mount_add_cb(sg_platf_mount_cb_t fct);
 
+void sg_platf_process_add_cb(sg_platf_process_cb_t fct);
+
 /** \brief Pick the right models for CPU, net and workstation, and call their model_init_preparse
  *
  * Must be called within parsing/creating the environment (after the <config>s, if any, and before <AS> or friends such as <cluster>)
index 6b17613..5cb246b 100644 (file)
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_deployment, simix,
                                 "Logging specific to SIMIX (deployment)");
-static int parse_argc = -1;
-static char **parse_argv = NULL;
+
 static xbt_main_func_t parse_code = NULL;
-static char *parse_host = NULL;
 static double start_time = 0.0;
 static double kill_time = -1.0;
 
@@ -23,42 +21,29 @@ static int auto_restart = 0;
 
 extern int surf_parse_lineno;
 
-static void parse_process_init(void)
+static void parse_process(sg_platf_process_cbarg_t process)
 {
-  smx_host_t host = SIMIX_host_get_by_name(A_surfxml_process_host);
+  smx_host_t host = SIMIX_host_get_by_name(process->host);
   if (!host)
-    THROWF(arg_error, 0, "Host '%s' unknown", A_surfxml_process_host);
-  parse_host = host->name;
-  parse_code = SIMIX_get_registered_function(A_surfxml_process_function);
-  xbt_assert(parse_code, "Function '%s' unknown",
-              A_surfxml_process_function);
-  parse_argv = xbt_new(char *, 2);
-  parse_argv[0] = xbt_strdup(A_surfxml_process_function);
-  parse_argc = 1;
-  start_time = surf_parse_get_double(A_surfxml_process_start_time);
-  kill_time  = surf_parse_get_double(A_surfxml_process_kill_time);
-  auto_restart = A_surfxml_process_on_failure == A_surfxml_process_on_failure_DIE ? 0 : 1;
-}
-static void parse_argument(void)
-{
-  parse_argv = xbt_realloc(parse_argv, (parse_argc + 2) * sizeof(char *));
-  parse_argv[parse_argc++] = xbt_strdup(A_surfxml_argument_value);
-}
+    THROWF(arg_error, 0, "Host '%s' unknown", process->host);
+  parse_code = SIMIX_get_registered_function(process->function);
+  xbt_assert(parse_code, "Function '%s' unknown", process->function);
+
+  start_time = process->start_time;
+  kill_time  = process->kill_time;
+  auto_restart = process->on_failure == SURF_PROCESS_ON_FAILURE_DIE ? 0 : 1;
 
-static void parse_process_finalize(void)
-{
   smx_process_arg_t arg = NULL;
-  smx_process_t process = NULL;
-  parse_argv[parse_argc] = NULL;
+  smx_process_t process_created = NULL;
 
   if (start_time > SIMIX_get_clock()) {
     arg = xbt_new0(s_smx_process_arg_t, 1);
-    arg->name = parse_argv[0];
+    arg->name = (char*)(process->argv)[0];
     arg->code = parse_code;
     arg->data = NULL;
-    arg->hostname = parse_host;
-    arg->argc = parse_argc;
-    arg->argv = parse_argv;
+    arg->hostname = host->name;
+    arg->argc = process->argc;
+    arg->argv = (char**)(process->argv);
     arg->kill_time = kill_time;
     arg->properties = current_property_set;
 
@@ -66,25 +51,25 @@ static void parse_process_finalize(void)
            arg->hostname, start_time);
     SIMIX_timer_set(start_time, &SIMIX_process_create_from_wrapper, arg);
   } else {                      // start_time <= SIMIX_get_clock()
-    XBT_DEBUG("Starting Process %s(%s) right now", parse_argv[0], parse_host);
+    XBT_DEBUG("Starting Process %s(%s) right now", process->argv[0], host->name);
 
     if (simix_global->create_process_function)
-      simix_global->create_process_function(&process,
-                                            parse_argv[0],
+      simix_global->create_process_function(&process_created,
+                                            (char*)(process->argv)[0],
                                             parse_code,
                                             NULL,
-                                            parse_host,
+                                            host->name,
                                             kill_time,
-                                            parse_argc,
-                                            parse_argv,
+                                            process->argc,
+                                            (char**)(process->argv),
                                             current_property_set,
                                             auto_restart);
     else
-      simcall_process_create(&process, parse_argv[0], parse_code, NULL, parse_host, kill_time, parse_argc, parse_argv,
-                               current_property_set,auto_restart);
+      simcall_process_create(&process_created, (char*)(process->argv)[0], parse_code, NULL, host->name, kill_time, process->argc,
+          (char**)process->argv, current_property_set,auto_restart);
 
     /* verify if process has been created (won't be the case if the host is currently dead, but that's fine) */
-    if (!process) {
+    if (!process_created) {
       return;
     }
   }
@@ -115,10 +100,7 @@ void SIMIX_launch_application(const char *file)
 
   surf_parse_reset_callbacks();
 
-  surfxml_add_callback(STag_surfxml_process_cb_list, parse_process_init);
-  surfxml_add_callback(ETag_surfxml_argument_cb_list, parse_argument);
-  surfxml_add_callback(ETag_surfxml_process_cb_list,
-                       parse_process_finalize);
+  sg_platf_process_add_cb(parse_process);
 
   surf_parse_open(file);
   TRY {
@@ -193,30 +175,34 @@ void SIMIX_process_set_function(const char *process_host,
                                 double process_start_time,
                                 double process_kill_time)
 {
-  unsigned int i;
-  char *arg;
+  s_sg_platf_process_cbarg_t process;
+  memset(&process,0,sizeof(process));
 
-  /* init process */
   smx_host_t host = SIMIX_host_get_by_name(process_host);
   if (!host)
     THROWF(arg_error, 0, "Host '%s' unknown", process_host);
-  parse_host = host->name;
-  parse_code = SIMIX_get_registered_function(process_function);
-  xbt_assert(parse_code, "Function '%s' unknown", process_function);
-
-  parse_argc = 1 + xbt_dynar_length(arguments);
-  parse_argv = xbt_new(char *, parse_argc + 1);
-  parse_argv[0] = xbt_strdup(process_function);
+  process.host = host->name;
 
+  process.argc = 1 + xbt_dynar_length(arguments);
+  process.argv = (const char**)xbt_new(char *, process.argc + 1);
+  process.argv[0] = xbt_strdup(process_function);
   /* add arguments */
+  unsigned int i;
+  char *arg;
   xbt_dynar_foreach(arguments, i, arg) {
-    parse_argv[i + 1] = xbt_strdup(arg);
+    process.argv[i + 1] = xbt_strdup(arg);
   }
-  parse_argv[parse_argc] = NULL;
+  process.argv[process.argc] = NULL;
+
+  parse_code = SIMIX_get_registered_function(process_function);
+  xbt_assert(parse_code, "Function '%s' unknown", process_function);
+  process.function = process_function;
 
-  start_time = process_start_time;
-  kill_time = process_kill_time;
+  process.host = process_host;
+  process.kill_time = process_kill_time;
+  process.start_time = process_start_time;
+  process.on_failure = SURF_PROCESS_ON_FAILURE_DIE;
+  process.properties = NULL;
 
-  /* finalize */
-  parse_process_finalize();
+  sg_platf_new_process(&process);
 }
index 87a6fd4..114c427 100644 (file)
@@ -38,6 +38,8 @@ xbt_dynar_t sg_platf_storage_type_cb_list = NULL; // of sg_platf_storage_cb_t
 xbt_dynar_t sg_platf_mstorage_cb_list = NULL; // of sg_platf_storage_cb_t
 xbt_dynar_t sg_platf_mount_cb_list = NULL; // of sg_platf_storage_cb_t
 
+xbt_dynar_t sg_platf_process_cb_list = NULL;
+
 static int surf_parse_models_setup_already_called;
 
 /* one RngStream for the platform, to respect some statistic rules */
@@ -75,6 +77,8 @@ void sg_platf_init(void) {
   sg_platf_storage_type_cb_list = xbt_dynar_new(sizeof(sg_platf_storage_cb_t), NULL);
   sg_platf_mstorage_cb_list = xbt_dynar_new(sizeof(sg_platf_storage_cb_t), NULL);
   sg_platf_mount_cb_list = xbt_dynar_new(sizeof(sg_platf_storage_cb_t), NULL);
+
+  sg_platf_process_cb_list = xbt_dynar_new(sizeof(sg_platf_process_cb_t), NULL);
 }
 /** Module management function: frees all internal data structures */
 void sg_platf_exit(void) {
@@ -104,6 +108,8 @@ void sg_platf_exit(void) {
   xbt_dynar_free(&sg_platf_mstorage_cb_list);
   xbt_dynar_free(&sg_platf_mount_cb_list);
 
+  xbt_dynar_free(&sg_platf_process_cb_list);
+
   /* make sure that we will reinit the models while loading the platf once reinited */
   surf_parse_models_setup_already_called = 0;
 }
@@ -240,6 +246,14 @@ void sg_platf_new_trace_connect(sg_platf_trace_connect_cbarg_t trace_connect) {
     fun(trace_connect);
   }
 }
+void sg_platf_new_process(sg_platf_process_cbarg_t process){
+  unsigned int iterator;
+  sg_platf_process_cb_t fun;
+  xbt_dynar_foreach(sg_platf_process_cb_list, iterator, fun) {
+    fun(process);
+  }
+}
+
 void sg_platf_begin() { /* Do nothing: just for symmetry of user code */ }
 
 void sg_platf_end() {
@@ -357,6 +371,9 @@ void sg_platf_rng_stream_init(unsigned long seed[6]) {
   RngStream_SetPackageSeed(seed);
   sg_platf_rng_stream = RngStream_CreateStream(NULL);
 }
+void sg_platf_process_add_cb(sg_platf_process_cb_t fct) {
+  xbt_dynar_push(sg_platf_process_cb_list, &fct);
+}
 
 RngStream sg_platf_rng_stream_get(const char* id) {
   RngStream stream = NULL;
index 69a1b6c..041ed3b 100644 (file)
@@ -64,10 +64,6 @@ int surf_parse_get_int(const char *string) {
  */
 
 /* make sure these symbols are defined as strong ones in this file so that the linker can resolve them */
-xbt_dynar_t STag_surfxml_process_cb_list = NULL;
-xbt_dynar_t ETag_surfxml_process_cb_list = NULL;
-xbt_dynar_t STag_surfxml_argument_cb_list = NULL;
-xbt_dynar_t ETag_surfxml_argument_cb_list = NULL;
 
 /* The default current property receiver. Setup in the corresponding opening callbacks. */
 xbt_dict_t current_property_set = NULL;
@@ -210,15 +206,7 @@ int ETag_surfxml_include_state(void)
 
 void surf_parse_init_callbacks(void)
 {
-    sg_platf_init(); // FIXME: move to a proper place?
-    STag_surfxml_process_cb_list =
-        xbt_dynar_new(sizeof(void_f_void_t), NULL);
-    ETag_surfxml_process_cb_list =
-        xbt_dynar_new(sizeof(void_f_void_t), NULL);
-    STag_surfxml_argument_cb_list =
-        xbt_dynar_new(sizeof(void_f_void_t), NULL);
-    ETag_surfxml_argument_cb_list =
-        xbt_dynar_new(sizeof(void_f_void_t), NULL);
+    sg_platf_init();
 }
 
 void surf_parse_reset_callbacks(void)
@@ -229,12 +217,7 @@ void surf_parse_reset_callbacks(void)
 
 void surf_parse_free_callbacks(void)
 {
-  sg_platf_exit(); // FIXME: better place?
-
-  xbt_dynar_free(&STag_surfxml_process_cb_list);
-  xbt_dynar_free(&ETag_surfxml_process_cb_list);
-  xbt_dynar_free(&STag_surfxml_argument_cb_list);
-  xbt_dynar_free(&ETag_surfxml_argument_cb_list);
+  sg_platf_exit();
 }
 
 /* Stag and Etag parse functions */
@@ -649,6 +632,47 @@ void ETag_surfxml_config(void){
   xbt_dict_free(&current_property_set);
 }
 
+static int argc;
+static char **argv;
+
+void STag_surfxml_process(void){
+  argc = 1;
+  argv = xbt_new(char *, 1);
+  argv[0] = xbt_strdup(A_surfxml_process_function);
+}
+
+void ETag_surfxml_process(void){
+  s_sg_platf_process_cbarg_t process;
+  memset(&process,0,sizeof(process));
+
+  process.argc = argc;
+  process.argv = (const char **)argv;
+  process.properties = current_property_set;
+  process.host = A_surfxml_process_host;
+  process.function = A_surfxml_process_function;
+  process.start_time = surf_parse_get_double(A_surfxml_process_start_time);
+  process.kill_time = surf_parse_get_double(A_surfxml_process_kill_time);
+
+  switch (A_surfxml_process_on_failure) {
+  case AU_surfxml_process_on_failure:
+  case A_surfxml_process_on_failure_DIE:
+    process.on_failure =  SURF_PROCESS_ON_FAILURE_DIE;
+    break;
+  case A_surfxml_process_on_failure_RESTART:
+    process.on_failure =  SURF_PROCESS_ON_FAILURE_RESTART;
+    break;
+  }
+
+  sg_platf_new_process(&process);
+  current_property_set = NULL;
+}
+
+void STag_surfxml_argument(void){
+  argc++;
+  argv = xbt_realloc(argv, (argc) * sizeof(char *));
+  argv[(argc) - 1] = xbt_strdup(A_surfxml_argument_value);
+}
+
 /* nothing to do in those functions */
 void ETag_surfxml_prop(void){}
 void STag_surfxml_random(void){}
@@ -662,22 +686,7 @@ void ETag_surfxml_cabinet(void){}
 void ETag_surfxml_peer(void){}
 void STag_surfxml_backbone(void){}
 void ETag_surfxml_link_ctn(void){}
-
-// FIXME should not call surfxml_call_cb_functions
-void STag_surfxml_process(void){
-  surfxml_call_cb_functions(STag_surfxml_process_cb_list);
-}
-void STag_surfxml_argument(void){
-  surfxml_call_cb_functions(STag_surfxml_argument_cb_list);
-}
-
-#define parse_method(type,name)                                         \
-  void type##Tag_surfxml_##name(void)                                   \
-  { surfxml_call_cb_functions(type##Tag_surfxml_##name##_cb_list); }    \
-  void type##Tag_surfxml_##name(void)
-
-parse_method(E, process);
-parse_method(E, argument);
+void ETag_surfxml_argument(void){}
 
 /* Open and Close parse file */
 
@@ -733,43 +742,6 @@ static int _surf_parse(void) {
 int_f_void_t surf_parse = _surf_parse;
 
 
-/* Aux parse functions */
-
-void surfxml_add_callback(xbt_dynar_t cb_list, void_f_void_t function)
-{
-  xbt_dynar_push(cb_list, &function);
-}
-
-void surfxml_del_callback(xbt_dynar_t cb_list, void_f_void_t function)
-{
-  xbt_ex_t e;
-  unsigned int it=0;
-  void_f_void_t null_f=NULL;
-
-  TRY {
-    it = xbt_dynar_search(cb_list,&function);
-  }
-  CATCH(e) {
-    if (e.category == not_found_error) {
-      xbt_ex_free(e);
-      xbt_die("Trying to remove a callback that is not here! This should not happen");
-    }
-    RETHROW;
-  }
-
-  xbt_dynar_replace(cb_list, it,&null_f);
-}
-
-static XBT_INLINE void surfxml_call_cb_functions(xbt_dynar_t cb_list)
-{
-  unsigned int iterator;
-  void_f_void_t fun;
-  xbt_dynar_foreach(cb_list, iterator, fun) {
-    if (fun) fun();
-  }
-}
-
-
 /* Prop tag functions */
 
 /**
index 1cd58ee..bdd5613 100644 (file)
@@ -46,49 +46,22 @@ char *warning = NULL;
 void s_process_free(void *process)
 {
   s_process_t *p = (s_process_t *) process;
-  int i;
-  for (i = 0; i < p->argc; i++)
-    free(p->argv[i]);
-  free(p->argv);
   free(p->host);
 }
 
 static s_process_t process;
 
-static void parse_process_init(void)
+static void parse_process(sg_platf_process_cbarg_t process_arg)
 {
-  xbt_dict_set(process_function_set, A_surfxml_process_function, NULL, NULL);
-  xbt_dict_set(machine_set, A_surfxml_process_host, NULL, NULL);
-  process.argc = 1;
-  process.argv = xbt_new(char *, 1);
-  process.argv[0] = xbt_strdup(A_surfxml_process_function);
-  process.host = strdup(A_surfxml_process_host);
+  xbt_dict_set(process_function_set, process_arg->function, NULL, NULL);
+  xbt_dict_set(machine_set, process_arg->host, NULL, NULL);
+  process.argc = process_arg->argc;
+  process.argv = (char**)(process_arg->argv);
+  process.host = strdup(process_arg->host);
   /*XBT_VERB("Function: %s",A_surfxml_process_function); */
-}
-
-static void parse_argument(void)
-{
-  process.argc++;
-  process.argv =
-      xbt_realloc(process.argv, (process.argc) * sizeof(char *));
-  process.argv[(process.argc) - 1] = xbt_strdup(A_surfxml_argument_value);
-}
-
-static void parse_process_finalize(void)
-{
   xbt_dynar_push(process_list, &process);
-  /*XBT_VERB("Function: %s",process.argv[0]); */
 }
 
-/*FIXME Defined in surfxml_parse.c*/
-#ifndef WIN32
-void surfxml_add_callback(xbt_dynar_t cb_list, void_f_void_t function)
-{
-  xbt_dynar_push(cb_list, &function);
-}
-#endif
-
-
 int main(int argc, char *argv[])
 {
   char *project_name = NULL;
@@ -131,11 +104,7 @@ int main(int argc, char *argv[])
   project_name = argv[1];
 
   surf_parse_reset_callbacks();
-  XBT_DEBUG("%p %p", parse_process_init, &parse_process_init);
-  surfxml_add_callback(STag_surfxml_process_cb_list, &parse_process_init);
-  surfxml_add_callback(ETag_surfxml_argument_cb_list, &parse_argument);
-  surfxml_add_callback(ETag_surfxml_process_cb_list,
-                       &parse_process_finalize);
+  sg_platf_process_add_cb(parse_process);
 
   for (i = 2; i < argc; i++) {
     deployment_file = argv[i];
@@ -178,6 +147,9 @@ int main(int argc, char *argv[])
 
   free(warning);
 
+
+  xbt_free(process.argv);
+
   xbt_dict_free(&process_function_set);
   xbt_dynar_free(&process_list);
   xbt_dict_free(&machine_set);