Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Usefull function to "kill" a context before the function it was executing has terminated.
authoralegrand <alegrand@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Wed, 26 Jan 2005 17:08:36 +0000 (17:08 +0000)
committeralegrand <alegrand@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Wed, 26 Jan 2005 17:08:36 +0000 (17:08 +0000)
git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@767 48e7efb5-ca39-0410-a469-dd3cf9ba447f

include/xbt/context.h
src/xbt/context.c

index e035c7b..ea8a6f5 100644 (file)
@@ -20,6 +20,7 @@ xbt_context_t xbt_context_new(xbt_context_function_t code,
                              void_f_pvoid_t startup_func, void *startup_arg,
                              void_f_pvoid_t cleanup_func, void *cleanup_arg,
                              int argc, char *argv[]);
+void xbt_context_free(xbt_context_t context);
 void xbt_context_start(xbt_context_t context);
 void xbt_context_yield(void);
 void xbt_context_schedule(xbt_context_t context);
index d371757..6ee1726 100644 (file)
@@ -187,9 +187,25 @@ void xbt_context_exit(void) {
   xbt_swag_free(context_to_destroy);
 
   while((context=xbt_swag_extract(context_living)))
-    xbt_context_destroy(context);
+    xbt_context_free(context);
 
   xbt_swag_free(context_living);
 
   init_context = current_context = NULL ;
 }
+
+void xbt_context_free(xbt_context_t context)
+{
+  int i ;
+
+  xbt_swag_remove(context, context_living);  
+  for(i=0;i<context->argc; i++) 
+    if(context->argv[i]) xbt_free(context->argv[i]);
+  if(context->argv) xbt_free(context->argv);
+  
+  if(context->cleanup_func)
+    context->cleanup_func(context->cleanup_arg);
+  xbt_context_destroy(context);
+
+  return;
+}