From: mquinson Date: Mon, 17 Aug 2009 10:22:32 +0000 (+0000) Subject: Context factory's API simplification: the function for creating the X-Git-Tag: SVN~1102 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/496721993cb6a1a41c1b9402a274b5d143aa373a Context factory's API simplification: the function for creating the context for maestro was merged with the function for the creation of standard contexts. The functions for managing the context module where simplified. git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@6566 48e7efb5-ca39-0410-a469-dd3cf9ba447f --- diff --git a/examples/msg/masterslave/masterslave_failure.tesh b/examples/msg/masterslave/masterslave_failure.tesh index 404f31b648..45a737baf7 100644 --- a/examples/msg/masterslave/masterslave_failure.tesh +++ b/examples/msg/masterslave/masterslave_failure.tesh @@ -3,7 +3,7 @@ p Testing a simple master/slave example application handling failures $ masterslave/masterslave_failure$EXEEXT small_platform_with_failures.xml masterslave/deployment_masterslave.xml -> [0.000000] simix/smx_process.c:92: [simix_process/WARNING] Cannot launch process 'slave' on failed host 'Fafard' +> [0.000000] simix/smx_process.c:91: [simix_process/WARNING] Cannot launch process 'slave' on failed host 'Fafard' > [Tremblay:master:(1) 0.000000] [msg_test/INFO] Got 5 slave(s) : > [Tremblay:master:(1) 0.000000] [msg_test/INFO] Jupiter > [Tremblay:master:(1) 0.000000] [msg_test/INFO] Fafard diff --git a/src/simix/private.h b/src/simix/private.h index 4fd9db7783..4de05ad4a9 100644 --- a/src/simix/private.h +++ b/src/simix/private.h @@ -190,9 +190,6 @@ typedef struct s_smx_context { typedef smx_context_t (*smx_pfn_context_factory_create_context_t) (xbt_main_func_t, int, char**, void_f_pvoid_t, void*); -/* function used to create the context for the maestro process */ -typedef smx_context_t (*smx_pfn_context_factory_create_maestro_context_t) (void); - /* this function finalize the specified context factory */ typedef int (*smx_pfn_context_factory_finalize_t) (smx_context_factory_t*); @@ -214,7 +211,6 @@ typedef void (*smx_pfn_context_resume_t) (smx_context_t old_context, /* interface of the context factories */ typedef struct s_smx_context_factory { - smx_pfn_context_factory_create_maestro_context_t create_maestro_context; smx_pfn_context_factory_create_context_t create_context; smx_pfn_context_factory_finalize_t finalize; smx_pfn_context_free_t free; @@ -263,14 +259,6 @@ void SIMIX_ctx_java_factory_init(smx_context_factory_t * factory); * iwannadie == 1, and call SIMIX_context_stop(same than first case afterward) */ -/** - * \brief creates the context for the maestro process - */ -static inline smx_context_t SIMIX_context_create_maestro() -{ - return (*(simix_global->context_factory->create_maestro_context)) (); -} - /** * \brief creates a new context for a user level process * \param code a main function diff --git a/src/simix/smx_context.c b/src/simix/smx_context.c index 7101a1ab19..314b988361 100644 --- a/src/simix/smx_context.c +++ b/src/simix/smx_context.c @@ -43,9 +43,15 @@ void SIMIX_context_mod_exit(void) if (simix_global->context_factory) { smx_pfn_context_factory_finalize_t finalize_factory; - /* if there are living processes then kill them (except maestro) */ - if(simix_global->process_list != NULL) - SIMIX_process_killall(); + /* Check that there are no living process or to destroy */ + xbt_assert0((simix_global->process_list == NULL), + "There are living process!"); + + xbt_assert0((simix_global->process_to_destroy == NULL), + "There are process to destroy!"); + + xbt_assert0((simix_global->maestro_process == NULL), + "The maestro process is alive!"); /* finalize the context factory */ finalize_factory = simix_global->context_factory->finalize; @@ -55,35 +61,37 @@ void SIMIX_context_mod_exit(void) /** * This function is used to change the context factory. - * Warning: it destroy all the existing contexts + * Warning: it destroy all the existing processes (even for maestro), and it + * will create a new maestro process using the new context factory. */ int SIMIX_context_select_factory(const char *name) { - /* if a factory is already instantiated (SIMIX_context_mod_init() was called) */ + /* if a context factory is already instantiated and it is different from the + newly selected one, then kill all the processes, exit the context module + and initialize the new factory. + */ if (simix_global->context_factory != NULL) { - /* if the desired factory is different of the current factory, call SIMIX_context_mod_exit() */ - if (strcmp(simix_global->context_factory->name, name)) + if (strcmp(simix_global->context_factory->name, name)){ + + SIMIX_process_killall(); + + /* kill maestro process */ + SIMIX_context_free(simix_global->maestro_process->context); + free(simix_global->maestro_process); + simix_global->maestro_process = NULL; + SIMIX_context_mod_exit(); + } else /* the same context factory is requested return directly */ return 0; } - /* get the desired factory */ + /* init the desired factory */ SIMIX_context_init_factory_by_name(&simix_global->context_factory, name); - /* maestro process specialisation */ - simix_global->maestro_process->context = SIMIX_context_create_maestro (); - - /* the current process is the process of the maestro */ - simix_global->current_process = simix_global->maestro_process; - - /* the current context doesn't want to die */ - simix_global->current_process->iwannadie = 0; - - /* insert the current context in the list of the contexts in use */ - xbt_swag_insert(simix_global->current_process, simix_global->process_list); - + __SIMIX_create_maestro_process (); + return 0; } diff --git a/src/simix/smx_context_java.c b/src/simix/smx_context_java.c index ed5758bdbc..c304b9ca15 100644 --- a/src/simix/smx_context_java.c +++ b/src/simix/smx_context_java.c @@ -25,8 +25,6 @@ static smx_context_t smx_ctx_java_factory_create_context(xbt_main_func_t code, int argc, char** argv, void_f_pvoid_t cleanup_func, void* cleanup_arg); -static smx_context_t smx_ctx_java_factory_create_maestro_context(void); - static int smx_ctx_java_factory_finalize(smx_context_factory_t * factory); static void smx_ctx_java_free(smx_context_t context); @@ -65,7 +63,6 @@ void SIMIX_ctx_java_factory_init(smx_context_factory_t * factory) (*factory)->create_context = smx_ctx_java_factory_create_context; (*factory)->finalize = smx_ctx_java_factory_finalize; - (*factory)->create_maestro_context = smx_ctx_java_factory_create_maestro_context; (*factory)->free = smx_ctx_java_free; (*factory)->start = smx_ctx_java_start; (*factory)->stop = smx_ctx_java_stop; @@ -75,16 +72,6 @@ void SIMIX_ctx_java_factory_init(smx_context_factory_t * factory) (*factory)->name = "ctx_java_factory"; } -static smx_context_t smx_ctx_java_factory_create_maestro_context(void) -{ - smx_ctx_java_t context = xbt_new0(s_smx_ctx_java_t, 1); - - context->exception = xbt_new(ex_ctx_t, 1); - XBT_CTX_INITIALIZE(context->exception); - - return (smx_context_t) context; -} - static int smx_ctx_java_factory_finalize(smx_context_factory_t * factory) { /*FIXME: free(maestro_context->exception);*/ @@ -100,13 +87,18 @@ smx_ctx_java_factory_create_context(xbt_main_func_t code, int argc, char** argv, { smx_ctx_java_t context = xbt_new0(s_smx_ctx_java_t, 1); - context->cleanup_func = cleanup_func; - context->cleanup_arg = cleanup_arg; context->exception = xbt_new(ex_ctx_t, 1); XBT_CTX_INITIALIZE(context->exception); - context->jprocess = (jobject) code; - context->jenv = get_current_thread_env(); + /* If the user provided a function for the process then use it + otherwise is the context for maestro */ + if(code){ + context->cleanup_func = cleanup_func; + context->cleanup_arg = cleanup_arg; + context->jprocess = (jobject) code; + context->jenv = get_current_thread_env(); + } + return (smx_context_t) context; } diff --git a/src/simix/smx_context_sysv.c b/src/simix/smx_context_sysv.c index 5834354e0b..f0bd8aa463 100644 --- a/src/simix/smx_context_sysv.c +++ b/src/simix/smx_context_sysv.c @@ -45,8 +45,6 @@ smx_ctx_sysv_factory_create_context(xbt_main_func_t code, int argc, char** argv, static int smx_ctx_sysv_factory_finalize(smx_context_factory_t *factory); -static smx_context_t smx_ctx_sysv_factory_create_maestro_context(void); - static void smx_ctx_sysv_free(smx_context_t context); static void smx_ctx_sysv_start(smx_context_t context); @@ -80,7 +78,6 @@ void SIMIX_ctx_sysv_factory_init(smx_context_factory_t *factory) (*factory)->create_context = smx_ctx_sysv_factory_create_context; (*factory)->finalize = smx_ctx_sysv_factory_finalize; - (*factory)->create_maestro_context = smx_ctx_sysv_factory_create_maestro_context; (*factory)->free = smx_ctx_sysv_free; (*factory)->start = smx_ctx_sysv_start; (*factory)->stop = smx_ctx_sysv_stop; @@ -93,16 +90,6 @@ void SIMIX_ctx_sysv_factory_init(smx_context_factory_t *factory) __xbt_ex_terminate = xbt_ctx_sysv_ex_terminate; } -static smx_context_t smx_ctx_sysv_factory_create_maestro_context() -{ - smx_ctx_sysv_t context = xbt_new0(s_smx_ctx_sysv_t, 1); - - context->exception = xbt_new(ex_ctx_t, 1); - XBT_CTX_INITIALIZE(context->exception); - - return (smx_context_t)context; -} - static int smx_ctx_sysv_factory_finalize(smx_context_factory_t * factory) { /*FIXME free(maestro_context->exception);*/ @@ -117,28 +104,38 @@ smx_ctx_sysv_factory_create_context(xbt_main_func_t code, int argc, char** argv, { smx_ctx_sysv_t context = xbt_new0(s_smx_ctx_sysv_t, 1); - context->code = code; + context->exception = xbt_new(ex_ctx_t, 1); + XBT_CTX_INITIALIZE(context->exception); + + /* If the user provided a function for the process then use it + otherwise is the context for maestro */ + if(code){ + context->code = code; + + xbt_assert2(getcontext(&(context->uc)) == 0, + "Error in context saving: %d (%s)", errno, strerror(errno)); + + context->uc.uc_link = NULL; + + context->uc.uc_stack.ss_sp = + pth_skaddr_makecontext(context->stack, STACK_SIZE); + + context->uc.uc_stack.ss_size = + pth_sksize_makecontext(context->stack, STACK_SIZE); - xbt_assert2(getcontext(&(context->uc)) == 0, - "Error in context saving: %d (%s)", errno, strerror(errno)); - context->uc.uc_link = NULL; - context->uc.uc_stack.ss_sp = - pth_skaddr_makecontext(context->stack, STACK_SIZE); - context->uc.uc_stack.ss_size = - pth_sksize_makecontext(context->stack, STACK_SIZE); #ifdef HAVE_VALGRIND_VALGRIND_H - context->valgrind_stack_id = - VALGRIND_STACK_REGISTER(context->uc.uc_stack.ss_sp, - ((char *) context->uc.uc_stack.ss_sp) + - context->uc.uc_stack.ss_size); + context->valgrind_stack_id = + VALGRIND_STACK_REGISTER(context->uc.uc_stack.ss_sp, + ((char *) context->uc.uc_stack.ss_sp) + + context->uc.uc_stack.ss_size); #endif /* HAVE_VALGRIND_VALGRIND_H */ - context->exception = xbt_new(ex_ctx_t, 1); - XBT_CTX_INITIALIZE(context->exception); - context->argc = argc; - context->argv = argv; - context->cleanup_func = cleanup_func; - context->cleanup_arg = cleanup_arg; + context->argc = argc; + context->argv = argv; + context->cleanup_func = cleanup_func; + context->cleanup_arg = cleanup_arg; + } + return (smx_context_t)context; } diff --git a/src/simix/smx_context_thread.c b/src/simix/smx_context_thread.c index 0c1d543cab..7f6c139575 100644 --- a/src/simix/smx_context_thread.c +++ b/src/simix/smx_context_thread.c @@ -13,6 +13,7 @@ #include "portable.h" /* loads context system definitions */ #include "xbt/swag.h" #include "xbt/xbt_os_thread.h" +#include "xbt_modinter.h" /* prototype of os thread module's init/exit in XBT */ XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(simix_context); @@ -27,8 +28,6 @@ static smx_context_t smx_ctx_thread_factory_create_context(xbt_main_func_t code, int argc, char** argv, void_f_pvoid_t cleanup_func, void* cleanup_arg); -static smx_context_t smx_ctx_thread_factory_create_master_context(void); - static int smx_ctx_thread_factory_finalize(smx_context_factory_t * factory); static void smx_ctx_thread_free(smx_context_t context); @@ -46,11 +45,13 @@ static void *smx_ctx_thread_wrapper(void *param); void SIMIX_ctx_thread_factory_init(smx_context_factory_t * factory) { + /* Initialize the thread portability layer + xbt_os_thread_mod_init();*/ + *factory = xbt_new0(s_smx_context_factory_t, 1); (*factory)->create_context = smx_ctx_thread_factory_create_context; (*factory)->finalize = smx_ctx_thread_factory_finalize; - (*factory)->create_maestro_context = smx_ctx_thread_factory_create_master_context; (*factory)->free = smx_ctx_thread_free; (*factory)->start = smx_ctx_thread_start; (*factory)->stop = smx_ctx_thread_stop; @@ -59,13 +60,10 @@ void SIMIX_ctx_thread_factory_init(smx_context_factory_t * factory) (*factory)->name = "ctx_thread_factory"; } -static smx_context_t smx_ctx_thread_factory_create_master_context(void) -{ - return (smx_context_t) xbt_new0(s_smx_ctx_thread_t, 1); -} - static int smx_ctx_thread_factory_finalize(smx_context_factory_t * factory) { + /* Stop the thread portability layer + xbt_os_thread_mod_exit();*/ free(*factory); *factory = NULL; return 0; @@ -77,14 +75,18 @@ smx_ctx_thread_factory_create_context(xbt_main_func_t code, int argc, char** arg { smx_ctx_thread_t context = xbt_new0(s_smx_ctx_thread_t, 1); - context->code = code; - context->argc = argc; - context->argv = argv; - context->cleanup_func = cleanup_func; - context->cleanup_arg = cleanup_arg; - context->begin = xbt_os_sem_init(0); - context->end = xbt_os_sem_init(0); - + /* If the user provided a function for the process then use it + otherwise is the context for maestro */ + if(code){ + context->code = code; + context->argc = argc; + context->argv = argv; + context->cleanup_func = cleanup_func; + context->cleanup_arg = cleanup_arg; + context->begin = xbt_os_sem_init(0); + context->end = xbt_os_sem_init(0); + } + return (smx_context_t)context; } diff --git a/src/simix/smx_global.c b/src/simix/smx_global.c index c04067bc0f..5a3ed08eae 100644 --- a/src/simix/smx_global.c +++ b/src/simix/smx_global.c @@ -199,24 +199,19 @@ void __SIMIX_main(void) /** * \brief Kill all running process - * + * Only maestro can kill everyone :) */ void SIMIX_process_killall() { smx_process_t p = NULL; - smx_process_t self = SIMIX_process_self(); + xbt_assert0((simix_global->current_process == simix_global->maestro_process), + "You are not supposed to run this function here!"); - while ((p = xbt_swag_extract(simix_global->process_list))) { - if (p != self) - SIMIX_process_kill(p); - } + while ((p = xbt_swag_extract(simix_global->process_list))) + SIMIX_process_kill(p); SIMIX_process_empty_trash(); - if (self != simix_global->maestro_process) { - __SIMIX_process_yield(); - } - return; } @@ -235,13 +230,15 @@ void SIMIX_clean(void) xbt_swag_free(simix_global->process_to_destroy); xbt_swag_free(simix_global->process_list); simix_global->process_list = NULL; + simix_global->process_to_destroy = NULL; xbt_dict_free(&(simix_global->registered_functions)); xbt_dict_free(&(simix_global->host)); /* Let's free maestro now */ SIMIX_context_free(simix_global->maestro_process->context); free(simix_global->maestro_process); - + simix_global->maestro_process = NULL; + /* Finish context module and SURF */ SIMIX_context_mod_exit(); surf_exit(); diff --git a/src/simix/smx_process.c b/src/simix/smx_process.c index 728cb372da..0c3caf8be0 100644 --- a/src/simix/smx_process.c +++ b/src/simix/smx_process.c @@ -54,8 +54,8 @@ void __SIMIX_create_maestro_process() /* Process data */ process->name = (char *)""; - /* Create the right context type */ - process->context = SIMIX_context_create_maestro(); + /* Create a dummy context for maestro */ + process->context = SIMIX_context_new(NULL, 0, NULL, NULL, NULL); /* Set it as the maestro process */ simix_global->maestro_process = process; diff --git a/src/xbt/xbt_sg_stubs.c b/src/xbt/xbt_sg_stubs.c index ba565a6911..8c854c90ba 100644 --- a/src/xbt/xbt_sg_stubs.c +++ b/src/xbt/xbt_sg_stubs.c @@ -133,12 +133,4 @@ void xbt_os_cond_destroy(xbt_os_cond_t cond) xbt_die ("No pthread in SG when compiled against the ucontext (xbt_os_cond_destroy)"); } -#endif - - -/*#ifndef HAVE_JAVA -#include "xbt/xbt_context_private.h" -void xbt_ctx_java_factory_init(xbt_context_factory_t * factory) -{ -} -#endif*/ +#endif \ No newline at end of file