From 28800061ff3b3913fc2e1cfbdc9d15211cf3a3f2 Mon Sep 17 00:00:00 2001 From: alegrand Date: Wed, 26 Jan 2005 17:08:36 +0000 Subject: [PATCH] Usefull function to "kill" a context before the function it was executing has terminated. git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@767 48e7efb5-ca39-0410-a469-dd3cf9ba447f --- include/xbt/context.h | 1 + src/xbt/context.c | 18 +++++++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/include/xbt/context.h b/include/xbt/context.h index e035c7bae4..ea8a6f55ba 100644 --- a/include/xbt/context.h +++ b/include/xbt/context.h @@ -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); diff --git a/src/xbt/context.c b/src/xbt/context.c index d371757b8f..6ee172610e 100644 --- a/src/xbt/context.c +++ b/src/xbt/context.c @@ -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;iargc; 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; +} -- 2.20.1