Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Let the model-checker decide if the wait transitions should timeout or not.
[simgrid.git] / src / simix / smx_context_sysv.c
index b13220e..e5b66e1 100644 (file)
@@ -6,9 +6,12 @@
  /* 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. */
 
+#include <stdarg.h>
+
 #include "smx_context_sysv_private.h"
 #include "xbt/parmap.h"
 #include "simix/private.h"
+#include "gras_config.h"
 
 #ifdef HAVE_VALGRIND_VALGRIND_H
 #  include <valgrind/valgrind.h>
@@ -29,11 +32,27 @@ static smx_context_t
 smx_ctx_sysv_create_context(xbt_main_func_t code, int argc, char **argv,
     void_pfn_smxprocess_t cleanup_func, void* data);
 
-static void smx_ctx_sysv_wrapper(smx_ctx_sysv_t context);
+static void smx_ctx_sysv_wrapper(int count, ...);
+
+/* This is a bit paranoid about SIZEOF_VOIDP not being a multiple of SIZEOF_INT,
+ * but it doesn't harm. */
+#define CTX_ADDR_LEN (SIZEOF_VOIDP / SIZEOF_INT + !!(SIZEOF_VOIDP % SIZEOF_INT))
+union u_ctx_addr {
+  void *addr;
+  int intv[CTX_ADDR_LEN];
+};
+#if (CTX_ADDR_LEN == 1)
+#  define CTX_ADDR_SPLIT(u) (u).intv[0]
+#elif (CTX_ADDR_LEN == 2)
+#  define CTX_ADDR_SPLIT(u) (u).intv[0], (u).intv[1]
+#else
+#  error Your architecture is not supported yet
+#endif
 
 void SIMIX_ctx_sysv_factory_init(smx_context_factory_t *factory)
 {
   smx_ctx_base_factory_init(factory);
+  VERB0("Activating SYSV context factory");
 
   (*factory)->finalize = smx_ctx_sysv_factory_finalize;
   (*factory)->create_context = smx_ctx_sysv_create_context;
@@ -43,7 +62,7 @@ void SIMIX_ctx_sysv_factory_init(smx_context_factory_t *factory)
   (*factory)->suspend = smx_ctx_sysv_suspend;
   (*factory)->name = "smx_sysv_context_factory";
 
-  if(_surf_parallel_contexts){
+  if (smx_parallel_contexts) {
 #ifdef CONTEXT_THREADS /* To use parallel ucontexts a thread pool is needed */
     parmap = xbt_parmap_new(2);
     (*factory)->runall = smx_ctx_sysv_runall_parallel;
@@ -69,7 +88,7 @@ smx_ctx_sysv_create_context_sized(size_t size, xbt_main_func_t code,
                                   void_pfn_smxprocess_t cleanup_func,
                                   void *data)
 {
-
+  union u_ctx_addr ctx_addr;
   smx_ctx_sysv_t context =
       (smx_ctx_sysv_t) smx_ctx_base_factory_create_context_sized(size,
                                                                  code,
@@ -100,9 +119,9 @@ smx_ctx_sysv_create_context_sized(size_t size, xbt_main_func_t code,
                                 ((char *) context->uc.uc_stack.ss_sp) +
                                 context->uc.uc_stack.ss_size);
 #endif                          /* HAVE_VALGRIND_VALGRIND_H */
-
-    makecontext(&((smx_ctx_sysv_t) context)->uc, (void (*)())smx_ctx_sysv_wrapper,
-                sizeof(void*)/sizeof(int), context);
+    ctx_addr.addr = context;
+    makecontext(&context->uc, (void (*)())smx_ctx_sysv_wrapper,
+                CTX_ADDR_LEN, CTX_ADDR_SPLIT(ctx_addr));
   }else{
     maestro_context = context;
   }
@@ -143,8 +162,21 @@ void smx_ctx_sysv_stop(smx_context_t context)
   smx_ctx_sysv_suspend(context);
 }
 
-void smx_ctx_sysv_wrapper(smx_ctx_sysv_t context)
+void smx_ctx_sysv_wrapper(int first, ...)
 { 
+  union u_ctx_addr ctx_addr;
+  smx_ctx_sysv_t context;
+
+  ctx_addr.intv[0] = first;
+  if (CTX_ADDR_LEN > 1) {
+    va_list ap;
+    int i;
+    va_start(ap, first);
+    for(i = 1; i < CTX_ADDR_LEN; i++)
+      ctx_addr.intv[i] = va_arg(ap, int);
+    va_end(ap);
+  }
+  context = ctx_addr.addr;
   (context->super.code) (context->super.argc, context->super.argv);
 
   smx_ctx_sysv_stop((smx_context_t) context);
@@ -169,11 +201,13 @@ void smx_ctx_sysv_resume(smx_context_t context)
 void smx_ctx_sysv_runall(xbt_dynar_t processes)
 {
   smx_process_t process;
-  
-  while (xbt_dynar_length(processes)){
-    process = xbt_dynar_pop_as(processes,smx_process_t);
+  unsigned int cursor;
+
+  xbt_dynar_foreach(processes, cursor, process) {
+    DEBUG2("Schedule item %u of %lu",cursor,xbt_dynar_length(processes));
     smx_ctx_sysv_resume(process->context);
   }
+  xbt_dynar_reset(processes);
 }
 
 void smx_ctx_sysv_resume_parallel(smx_process_t process)