Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Use a dynar instead of a swag to implement the process_to_run list.
authorcristianrosa <cristianrosa@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Mon, 13 Dec 2010 08:58:22 +0000 (08:58 +0000)
committercristianrosa <cristianrosa@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Mon, 13 Dec 2010 08:58:22 +0000 (08:58 +0000)
git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@9143 48e7efb5-ca39-0410-a469-dd3cf9ba447f

12 files changed:
include/simix/context.h
src/mc/mc_global.c
src/replay/state_machine_context.c
src/simix/private.h
src/simix/smx_context_raw.c
src/simix/smx_context_ruby.c
src/simix/smx_context_sysv.c
src/simix/smx_context_sysv_private.h
src/simix/smx_context_thread.c
src/simix/smx_global.c
src/simix/smx_process.c
src/simix/smx_smurf.c

index c4af0a8..475ffbc 100644 (file)
@@ -32,7 +32,7 @@ typedef void (*smx_pfn_context_free_t) (smx_context_t);
 typedef void (*smx_pfn_context_start_t) (smx_context_t);
 typedef void (*smx_pfn_context_stop_t) (smx_context_t);
 typedef void (*smx_pfn_context_suspend_t) (smx_context_t context);
-typedef void (*smx_pfn_context_runall_t) (xbt_swag_t processes);
+typedef void (*smx_pfn_context_runall_t) (xbt_dynar_t processes);
 typedef smx_context_t (*smx_pfn_context_self_t) (void);
 typedef void* (*smx_pfn_context_get_data_t) (smx_context_t context);
 
index 2a72f31..42d1765 100644 (file)
@@ -181,7 +181,7 @@ void MC_wait_for_requests(void)
         xbt_free(req_str);
       }
     }
-  } while (xbt_swag_size(simix_global->process_to_run));
+  } while (xbt_dynar_length(simix_global->process_to_run));
 }
 
 /****************************** Statistics ************************************/
index dd2327e..ab48214 100644 (file)
@@ -22,7 +22,7 @@ statem_create_context(xbt_main_func_t code, int argc, char **argv,
 static void statem_ctx_free(smx_context_t context);
 static void statem_ctx_suspend(smx_context_t context);
 static void statem_ctx_resume(smx_context_t new_context);
-static void statem_ctx_runall(xbt_swag_t processes);
+static void statem_ctx_runall(xbt_dynar_t processes);
 static smx_context_t statem_ctx_self(void);
 
 void statem_factory_init(smx_context_factory_t * factory) {
@@ -73,12 +73,14 @@ static void statem_ctx_suspend(smx_context_t context) {
 static void statem_ctx_resume(smx_context_t new_context) {
   THROW_UNIMPLEMENTED;
 }
-static void statem_ctx_runall(xbt_swag_t processes) {
+static void statem_ctx_runall(xbt_dynar_t processes) {
   smx_context_t old_context;
   smx_process_t process;
 
   INFO0("Run all");
-  while ((process = xbt_swag_extract(processes))) {
+
+  while (xbt_dynar_length(processes)){
+    process = xbt_dynar_pop_as(processes,smx_process_t);
     statem_context_t ctx = (statem_context_t)SIMIX_process_get_context(process);
     old_context = smx_current_context;
     smx_current_context = SIMIX_process_get_context(process);
index ccbec1e..d69a163 100644 (file)
@@ -29,7 +29,7 @@
 typedef struct s_smx_global {
   smx_context_factory_t context_factory;
   xbt_dict_t host;
-  xbt_swag_t process_to_run;
+  xbt_dynar_t process_to_run;
   xbt_swag_t process_list;
   xbt_swag_t process_to_destroy;
   smx_process_t maestro_process;
@@ -227,9 +227,9 @@ static XBT_INLINE void SIMIX_context_suspend(smx_context_t context)
 
 /**
  \brief executes all the processes (in parallel if possible)
- \param processes the swag of processes to execute
+ \param processes the dynar of processes to execute
  */
-static XBT_INLINE void SIMIX_context_runall(xbt_swag_t processes)
+static XBT_INLINE void SIMIX_context_runall(xbt_dynar_t processes)
 {
   (*(simix_global->context_factory->runall)) (processes);
 }
index fb8c9a9..57f8c71 100644 (file)
@@ -257,12 +257,14 @@ static void smx_ctx_raw_resume(smx_context_t context)
       ((smx_ctx_raw_t) context)->stack_top);
 }
 
-static void smx_ctx_raw_runall(xbt_swag_t processes)
+static void smx_ctx_raw_runall(xbt_dynar_t processes)
 {
   smx_process_t process;
 
-  while ((process = xbt_swag_extract(processes)))
+  while (xbt_dynar_length(processes)){
+    process = xbt_dynar_pop_as(processes,smx_process_t);
     smx_ctx_raw_resume(process->context);
+  }
 }
 
 static void smx_ctx_raw_resume_parallel(smx_context_t context)
@@ -274,12 +276,9 @@ static void smx_ctx_raw_resume_parallel(smx_context_t context)
   xbt_os_thread_set_extra_data(NULL);
 }
 
-static void smx_ctx_raw_runall_parallel(xbt_swag_t processes)
+static void smx_ctx_raw_runall_parallel(xbt_dynar_t processes)
 {
-  smx_process_t process;
-  while((process = xbt_swag_extract(processes))){
-    /* FIXME */
-  }
+  return;
 }
 
 static smx_context_t smx_ctx_raw_self_parallel(void)
index f781020..ce1a50e 100644 (file)
@@ -23,7 +23,7 @@ smx_ctx_ruby_create_context(xbt_main_func_t code, int argc, char **argv,
 static void smx_ctx_ruby_stop(smx_context_t context);
 static void smx_ctx_ruby_suspend(smx_context_t context);
 static void smx_ctx_ruby_resume(smx_context_t new_context);
-static void smx_ctx_ruby_runall(xbt_swag_t processes);
+static void smx_ctx_ruby_runall(xbt_dynar_t processes);
 
 void SIMIX_ctx_ruby_factory_init(smx_context_factory_t * factory)
 {
@@ -110,11 +110,12 @@ static void smx_ctx_ruby_resume(smx_context_t new_context)
   rb_process_schedule(ctx_ruby->process);
 }
 
-static void smx_ctx_ruby_runall(xbt_swag_t processes)
+static void smx_ctx_ruby_runall(xbt_dynar_t processes)
 {
   smx_process_t process;
   smx_context_t old_context;
-  while ((process = xbt_swag_extract(processes))) {
+  while (xbt_dynar_length(processes)){
+    process = xbt_dynar_pop_as(processes,smx_process_t);
     old_context = smx_current_context;
     smx_current_context = process->context;
     smx_ctx_ruby_resume(smx_current_context);
index 27d0332..b13220e 100644 (file)
@@ -7,7 +7,7 @@
   * under the terms of the license (GNU LGPL) which comes with this package. */
 
 #include "smx_context_sysv_private.h"
-//#include "xbt/threadpool.h"
+#include "xbt/parmap.h"
 #include "simix/private.h"
 
 #ifdef HAVE_VALGRIND_VALGRIND_H
@@ -23,7 +23,7 @@
 
 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(simix_context);
 
-//static xbt_parmap_t tpool;
+static xbt_parmap_t parmap;
 
 static smx_context_t
 smx_ctx_sysv_create_context(xbt_main_func_t code, int argc, char **argv,
@@ -45,7 +45,7 @@ void SIMIX_ctx_sysv_factory_init(smx_context_factory_t *factory)
 
   if(_surf_parallel_contexts){
 #ifdef CONTEXT_THREADS /* To use parallel ucontexts a thread pool is needed */
-//    tpool = xbt_parmap_new(2, 10);
+    parmap = xbt_parmap_new(2);
     (*factory)->runall = smx_ctx_sysv_runall_parallel;
     (*factory)->self = smx_ctx_sysv_self_parallel;
 #else
@@ -58,8 +58,8 @@ void SIMIX_ctx_sysv_factory_init(smx_context_factory_t *factory)
 
 int smx_ctx_sysv_factory_finalize(smx_context_factory_t *factory)
 { 
-/*  if(tpool)
-    xbt_parmap_destroy(tpool);*/
+  if(parmap)
+    xbt_parmap_destroy(parmap);
   return smx_ctx_base_factory_finalize(factory);
 }
 
@@ -166,16 +166,19 @@ void smx_ctx_sysv_resume(smx_context_t context)
   xbt_assert0((rv == 0), "Context swapping failure");
 }
 
-void smx_ctx_sysv_runall(xbt_swag_t processes)
+void smx_ctx_sysv_runall(xbt_dynar_t processes)
 {
   smx_process_t process;
   
-  while ((process = xbt_swag_extract(processes)))
+  while (xbt_dynar_length(processes)){
+    process = xbt_dynar_pop_as(processes,smx_process_t);
     smx_ctx_sysv_resume(process->context);
+  }
 }
 
-void smx_ctx_sysv_resume_parallel(smx_context_t context)
+void smx_ctx_sysv_resume_parallel(smx_process_t process)
 {
+  smx_context_t context = process->context;
   xbt_os_thread_set_extra_data(context);
   int rv = swapcontext(&((smx_ctx_sysv_t)context)->old_uc, &((smx_ctx_sysv_t) context)->uc);
   xbt_os_thread_set_extra_data(NULL);
@@ -183,13 +186,10 @@ void smx_ctx_sysv_resume_parallel(smx_context_t context)
   xbt_assert0((rv == 0), "Context swapping failure");
 }
 
-void smx_ctx_sysv_runall_parallel(xbt_swag_t processes)
+void smx_ctx_sysv_runall_parallel(xbt_dynar_t processes)
 {
-  smx_process_t process;
-  while((process = xbt_swag_extract(processes))){
-  //  xbt_parmap_apply(tpool, (void_f_pvoid_t)smx_ctx_sysv_resume_parallel, process->context);
-  }
-  /*xbt_tpool_wait_all(tpool);*/
+  xbt_parmap_apply(parmap, (void_f_pvoid_t)smx_ctx_sysv_resume_parallel, processes);
+  xbt_dynar_reset(processes);
 }
 
 smx_context_t smx_ctx_sysv_self_parallel(void)
index 5660770..745df05 100644 (file)
@@ -51,9 +51,9 @@ void smx_ctx_sysv_free(smx_context_t context);
 void smx_ctx_sysv_stop(smx_context_t context);
 void smx_ctx_sysv_suspend(smx_context_t context);
 void smx_ctx_sysv_resume(smx_context_t new_context);
-void smx_ctx_sysv_runall(xbt_swag_t processes);
-void smx_ctx_sysv_resume_parallel(smx_context_t new_context);
-void smx_ctx_sysv_runall_parallel(xbt_swag_t processes);
+void smx_ctx_sysv_runall(xbt_dynar_t processes);
+void smx_ctx_sysv_resume_parallel(smx_process_t new_context);
+void smx_ctx_sysv_runall_parallel(xbt_dynar_t processes);
 smx_context_t smx_ctx_sysv_self_parallel(void);
 
 SG_END_DECL()
index f736475..e1fdecc 100644 (file)
@@ -33,8 +33,8 @@ static void smx_ctx_thread_free(smx_context_t context);
 static void smx_ctx_thread_stop(smx_context_t context);
 static void smx_ctx_thread_suspend(smx_context_t context);
 static void smx_ctx_thread_resume(smx_context_t new_context);
-static void smx_ctx_thread_runall_serial(xbt_swag_t processes);
-static void smx_ctx_thread_runall_parallel(xbt_swag_t processes);
+static void smx_ctx_thread_runall_serial(xbt_dynar_t processes);
+static void smx_ctx_thread_runall_parallel(xbt_dynar_t processes);
 static smx_context_t smx_ctx_thread_self(void);
 
 static void *smx_ctx_thread_wrapper(void *param);
@@ -142,23 +142,28 @@ static void smx_ctx_thread_suspend(smx_context_t context)
   xbt_os_sem_acquire(((smx_ctx_thread_t) context)->begin);
 }
 
-static void smx_ctx_thread_runall_serial(xbt_swag_t processes)
+static void smx_ctx_thread_runall_serial(xbt_dynar_t processes)
 {
   smx_process_t process;
-  while ((process = xbt_swag_extract(processes))) {
+  while (xbt_dynar_length(processes)){
+    process = xbt_dynar_pop_as(processes,smx_process_t);
     xbt_os_sem_release(((smx_ctx_thread_t) process->context)->begin);
     xbt_os_sem_acquire(((smx_ctx_thread_t) process->context)->end);
   }
 }
 
-static void smx_ctx_thread_runall_parallel(xbt_swag_t processes)
+static void smx_ctx_thread_runall_parallel(xbt_dynar_t processes)
 {
-  smx_process_t process, p_next;
-  xbt_swag_foreach_safe(process, p_next, processes)
+  unsigned int index;
+  smx_process_t process;
+
+  xbt_dynar_foreach(processes, index, process)
     xbt_os_sem_release(((smx_ctx_thread_t) process->context)->begin);
 
-  while ((process = xbt_swag_extract(processes)))
-    xbt_os_sem_acquire(((smx_ctx_thread_t) process->context)->end);
+  while(xbt_dynar_length(processes)){
+     process = xbt_dynar_pop_as(processes,smx_process_t);
+     xbt_os_sem_acquire(((smx_ctx_thread_t) process->context)->end);
+  }
 }
 
 static smx_context_t smx_ctx_thread_self(void)
index b3ba2f5..e72c470 100644 (file)
@@ -66,7 +66,7 @@ void SIMIX_global_init(int *argc, char **argv)
     simix_global = xbt_new0(s_smx_global_t, 1);
 
     simix_global->host = xbt_dict_new();
-    simix_global->process_to_run =
+    simix_global->process_to_run = xbt_dynar_new(sizeof(void *), NULL);
         xbt_swag_new(xbt_swag_offset(proc, synchro_hookup));
     simix_global->process_list =
         xbt_swag_new(xbt_swag_offset(proc, process_hookup));
@@ -124,7 +124,7 @@ void SIMIX_clean(void)
 
   xbt_heap_free(simix_timers);
   /* Free the remaining data structures */
-  xbt_swag_free(simix_global->process_to_run);
+  xbt_dynar_free(&simix_global->process_to_run);
   xbt_swag_free(simix_global->process_to_destroy);
   xbt_swag_free(simix_global->process_list);
   simix_global->process_list = NULL;
@@ -186,7 +186,7 @@ void SIMIX_run(void)
         DEBUG1("Handling request %p", req);
         SIMIX_request_pre(req);
       }
-    } while (xbt_swag_size(simix_global->process_to_run));
+    } while (xbt_dynar_length(simix_global->process_to_run));
 
     time = surf_solve(SIMIX_timer_next());
 
index d3353c2..1fb254d 100644 (file)
@@ -36,7 +36,7 @@ XBT_INLINE smx_process_t SIMIX_process_self(void)
 void SIMIX_process_cleanup(smx_process_t process)
 {
   DEBUG1("Cleanup process %s", process->name);
-  xbt_swag_remove(process, simix_global->process_to_run);
+  /*xbt_swag_remove(process, simix_global->process_to_run);*/
   xbt_swag_remove(process, simix_global->process_list);
   xbt_swag_remove(process, process->smx_host->process_list);
   xbt_swag_insert(process, simix_global->process_to_destroy);
@@ -173,7 +173,7 @@ smx_process_t SIMIX_process_create(const char *name,
     /* 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);
+    xbt_dynar_push_as(simix_global->process_to_run, smx_process_t, process);
   }
 
   return process;
@@ -229,7 +229,7 @@ void SIMIX_process_kill(smx_process_t process, smx_process_t killer) {
     SIMIX_context_stop(process->context);
   }
   else {
-    xbt_swag_insert(process, simix_global->process_to_run);
+    xbt_dynar_push_as(simix_global->process_to_run, smx_process_t, process);
   }
 }
 
@@ -338,7 +338,7 @@ void SIMIX_process_resume(smx_process_t process, smx_process_t issuer)
       }
     }
     else {
-      xbt_swag_insert(process, simix_global->process_to_run);
+      xbt_dynar_push_as(simix_global->process_to_run, smx_process_t, process);
     }
   }
 }
index 59297c5..906457c 100644 (file)
@@ -58,7 +58,7 @@ void SIMIX_request_answer(smx_req_t req)
 {
   if (req->issuer != simix_global->maestro_process){
     req->issuer->request.call = REQ_NO_REQ;
-    xbt_swag_insert(req->issuer, simix_global->process_to_run);
+    xbt_dynar_push_as(simix_global->process_to_run, smx_process_t, req->issuer);
   }
 }