From 7e71d73eb6728d8d498d010976f038789049c131 Mon Sep 17 00:00:00 2001 From: mquinson Date: Tue, 23 Mar 2010 00:49:14 +0000 Subject: [PATCH] Merge context_start into context_new to simplify the soup git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@7301 48e7efb5-ca39-0410-a469-dd3cf9ba447f --- src/simix/private.h | 21 ++++--------------- src/simix/smx_context_java.c | 11 +++------- src/simix/smx_context_lua.c | 36 +++++++++++++-------------------- src/simix/smx_context_private.h | 1 - src/simix/smx_context_ruby.c | 9 --------- src/simix/smx_context_sysv.c | 10 ++------- src/simix/smx_context_thread.c | 31 ++++++++++------------------ src/simix/smx_process.c | 1 - 8 files changed, 34 insertions(+), 86 deletions(-) diff --git a/src/simix/private.h b/src/simix/private.h index b67a79460a..a21e458478 100644 --- a/src/simix/private.h +++ b/src/simix/private.h @@ -272,7 +272,6 @@ typedef struct s_smx_context_factory { smx_pfn_context_factory_create_context_t create_context; smx_pfn_context_factory_finalize_t finalize; smx_pfn_context_free_t free; - smx_pfn_context_start_t start; smx_pfn_context_stop_t stop; smx_pfn_context_suspend_t suspend; smx_pfn_context_resume_t resume; @@ -331,8 +330,8 @@ void SIMIX_ctx_java_factory_init(smx_context_factory_t * factory); static inline smx_context_t SIMIX_context_new(xbt_main_func_t code, int argc, char** argv, void_f_pvoid_t cleanup_func, - void* cleanup_arg) -{ + void* cleanup_arg) { + return (*(simix_global->context_factory->create_context)) (code, argc, argv, cleanup_func, cleanup_arg); } @@ -342,27 +341,15 @@ static inline smx_context_t SIMIX_context_new(xbt_main_func_t code, int argc, * \param context the context to destroy * Argument must be stopped first -- runs in maestro context */ -static inline void SIMIX_context_free(smx_context_t context) -{ +static inline void SIMIX_context_free(smx_context_t context) { (*(simix_global->context_factory->free)) (context); } -/** - * \brief prepares aa context to be run - * \param context the context to start - * It will however run effectively only when calling #SIMIX_process_schedule - */ -static inline void SIMIX_context_start(smx_context_t context) -{ - (*(simix_global->context_factory->start)) (context); -} - /** * \brief stops the execution of a context * \param context to stop */ -static inline void SIMIX_context_stop(smx_context_t context) -{ +static inline void SIMIX_context_stop(smx_context_t context) { (*(simix_global->context_factory->stop)) (context); } diff --git a/src/simix/smx_context_java.c b/src/simix/smx_context_java.c index 8389576698..8a64130bd7 100644 --- a/src/simix/smx_context_java.c +++ b/src/simix/smx_context_java.c @@ -39,7 +39,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)->free = smx_ctx_java_free; - (*factory)->start = smx_ctx_java_start; (*factory)->stop = smx_ctx_java_stop; (*factory)->suspend = smx_ctx_java_suspend; (*factory)->resume = smx_ctx_java_resume; @@ -67,6 +66,8 @@ smx_ctx_java_factory_create_context(xbt_main_func_t code, int argc, char** argv, context->cleanup_arg = cleanup_arg; context->jprocess = (jobject) code; context->jenv = get_current_thread_env(); + jprocess_start(((smx_ctx_java_t) context)->jprocess, + get_current_thread_env()); } return (smx_context_t) context; @@ -92,12 +93,6 @@ static void smx_ctx_java_free(smx_context_t context) } } -static void smx_ctx_java_start(smx_context_t context) -{ - jprocess_start(((smx_ctx_java_t) context)->jprocess, - get_current_thread_env()); -} - static void smx_ctx_java_stop(smx_context_t context) { jobject jprocess = NULL; @@ -159,4 +154,4 @@ static void smx_ctx_java_resume(smx_context_t old_context, smx_context_t new_context) { jprocess_schedule(new_context); -} \ No newline at end of file +} diff --git a/src/simix/smx_context_lua.c b/src/simix/smx_context_lua.c index 51ac850b00..a71dbba85b 100644 --- a/src/simix/smx_context_lua.c +++ b/src/simix/smx_context_lua.c @@ -49,7 +49,6 @@ smx_ctx_lua_create_context(xbt_main_func_t code, int argc, char** argv, static int smx_ctx_lua_factory_finalize(smx_context_factory_t *factory); static void smx_ctx_lua_free(smx_context_t context); -static void smx_ctx_lua_start(smx_context_t context); static void smx_ctx_lua_stop(smx_context_t context); static void smx_ctx_lua_suspend(smx_context_t context); @@ -70,7 +69,6 @@ void SIMIX_ctx_lua_factory_init(smx_context_factory_t *factory) { (*factory)->create_context = smx_ctx_lua_create_context; (*factory)->finalize = smx_ctx_lua_factory_finalize; (*factory)->free = smx_ctx_lua_free; - (*factory)->start = smx_ctx_lua_start; (*factory)->stop = smx_ctx_lua_stop; (*factory)->suspend = smx_ctx_lua_suspend; (*factory)->resume = smx_ctx_lua_resume; @@ -107,8 +105,20 @@ smx_ctx_lua_create_context(xbt_main_func_t code, int argc, char** argv, /* start the coroutine in charge of running that code */ context->state = lua_newthread(lua_state); context->ref = luaL_ref(lua_state, LUA_REGISTRYINDEX); // protect the thread from being garbage collected - /* the actual co-routine starting is done in smx_ctx_lua_start */ - context->nargs = argc-1; + + /* Start the co-routine */ + lua_getglobal(context->state,context->argv[0]); + xbt_assert1(lua_isfunction(context->state,-1), + "The lua function %s does not seem to exist",context->argv[0]); + + // push arguments onto the stack + int i; + for(i=1;iargc;i++) + lua_pushstring(context->state,context->argv[i]); + + // Call the function (in resume) + context->nargs = context->argc-1; + } else { INFO0("Created context for maestro"); } @@ -141,24 +151,6 @@ static void smx_ctx_lua_free(smx_context_t pcontext) } } -static void smx_ctx_lua_start(smx_context_t pcontext) { - smx_ctx_lua_t context = (smx_ctx_lua_t)pcontext; - - DEBUG1("Starting '%s'",context->argv[0]); - - lua_getglobal(context->state,context->argv[0]); - xbt_assert1(lua_isfunction(context->state,-1), - "The lua function %s does not seem to exist",context->argv[0]); - - // push arguments onto the stack - int i; - for(i=1;iargc;i++) - lua_pushstring(context->state,context->argv[i]); - - // Call the function - context->nargs = context->argc-1; -} - static void smx_ctx_lua_stop(smx_context_t pcontext) { smx_ctx_lua_t context = (smx_ctx_lua_t)pcontext; diff --git a/src/simix/smx_context_private.h b/src/simix/smx_context_private.h index bc7a147e6d..47afd85632 100644 --- a/src/simix/smx_context_private.h +++ b/src/simix/smx_context_private.h @@ -75,7 +75,6 @@ typedef struct s_smx_context_factory { smx_pfn_context_kill_t kill; smx_pfn_context_schedule_t schedule; smx_pfn_context_yield_t yield; - smx_pfn_context_start_t start; smx_pfn_context_stop_t stop; const char *name; } s_smx_context_factory_t; diff --git a/src/simix/smx_context_ruby.c b/src/simix/smx_context_ruby.c index 06783125b8..112ca360ee 100644 --- a/src/simix/smx_context_ruby.c +++ b/src/simix/smx_context_ruby.c @@ -21,7 +21,6 @@ smx_ctx_ruby_create_context(xbt_main_func_t code,int argc,char** argv, static int smx_ctx_ruby_factory_finalize(smx_context_factory_t *factory); static void smx_ctx_ruby_free(smx_context_t context); -static void smx_ctx_ruby_start(smx_context_t context); static void smx_ctx_ruby_stop(smx_context_t context); static void smx_ctx_ruby_suspend(smx_context_t context); static void @@ -35,7 +34,6 @@ void SIMIX_ctx_ruby_factory_init(smx_context_factory_t *factory) { (*factory)->create_context = smx_ctx_ruby_create_context; (*factory)->finalize = smx_ctx_ruby_factory_finalize; (*factory)->free = smx_ctx_ruby_free; - (*factory)->start = smx_ctx_ruby_start; (*factory)->stop = smx_ctx_ruby_stop; (*factory)->suspend = smx_ctx_ruby_suspend; (*factory)->resume = smx_ctx_ruby_resume; @@ -88,13 +86,6 @@ static void smx_ctx_ruby_free(smx_context_t context) { } } -static void smx_ctx_ruby_start(smx_context_t context) { - DEBUG1("smx_ctx_ruby_start(%s) (nothing to do)",context->argv[0]); - /* Already Done .. Since a Ruby process is launched within initialization - We Start it Within the Initializer ... We Use the Semaphore To Keep - the thread alive waiting for mutex signal to execute the main*/ -} - static void smx_ctx_ruby_stop(smx_context_t context) { DEBUG0("smx_ctx_ruby_stop()"); VALUE process = Qnil; diff --git a/src/simix/smx_context_sysv.c b/src/simix/smx_context_sysv.c index 163864bad6..a44593d9e0 100644 --- a/src/simix/smx_context_sysv.c +++ b/src/simix/smx_context_sysv.c @@ -39,8 +39,6 @@ static int smx_ctx_sysv_factory_finalize(smx_context_factory_t *factory); static void smx_ctx_sysv_free(smx_context_t context); -static void smx_ctx_sysv_start(smx_context_t context); - static void smx_ctx_sysv_stop(smx_context_t context); static void smx_ctx_sysv_suspend(smx_context_t context); @@ -57,7 +55,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)->free = smx_ctx_sysv_free; - (*factory)->start = smx_ctx_sysv_start; (*factory)->stop = smx_ctx_sysv_stop; (*factory)->suspend = smx_ctx_sysv_suspend; (*factory)->resume = smx_ctx_sysv_resume; @@ -104,6 +101,8 @@ smx_ctx_sysv_factory_create_context(xbt_main_func_t code, int argc, char** argv, context->argv = argv; context->cleanup_func = cleanup_func; context->cleanup_arg = cleanup_arg; + + makecontext(&((smx_ctx_sysv_t)context)->uc, smx_ctx_sysv_wrapper, 0); } return (smx_context_t)context; @@ -133,11 +132,6 @@ static void smx_ctx_sysv_free(smx_context_t pcontext) } } -static void smx_ctx_sysv_start(smx_context_t context) -{ - makecontext(&((smx_ctx_sysv_t)context)->uc, smx_ctx_sysv_wrapper, 0); -} - static void smx_ctx_sysv_stop(smx_context_t pcontext) { smx_ctx_sysv_t context = (smx_ctx_sysv_t)pcontext; diff --git a/src/simix/smx_context_thread.c b/src/simix/smx_context_thread.c index 6ffe15719e..30c66538fc 100644 --- a/src/simix/smx_context_thread.c +++ b/src/simix/smx_context_thread.c @@ -29,13 +29,8 @@ smx_ctx_thread_factory_create_context(xbt_main_func_t code, int argc, char** arg void_f_pvoid_t cleanup_func, void* cleanup_arg); static int smx_ctx_thread_factory_finalize(smx_context_factory_t * factory); - static void smx_ctx_thread_free(smx_context_t context); - -static void smx_ctx_thread_start(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 @@ -80,6 +75,16 @@ smx_ctx_thread_factory_create_context(xbt_main_func_t code, int argc, char** arg context->cleanup_arg = cleanup_arg; context->begin = xbt_os_sem_init(0); context->end = xbt_os_sem_init(0); + + + /* create and start the process */ + /* NOTE: The first argument to xbt_os_thread_create used to be the process * + * name, but now the name is stored at SIMIX level, so we pass a null */ + context->thread = + xbt_os_thread_create(NULL, smx_ctx_thread_wrapper, ctx_thread); + + /* wait the starting of the newly created process */ + xbt_os_sem_acquire(context->end); } return (smx_context_t)context; @@ -113,20 +118,6 @@ static void smx_ctx_thread_free(smx_context_t pcontext) free(context); } -static void smx_ctx_thread_start(smx_context_t context) -{ - smx_ctx_thread_t ctx_thread = (smx_ctx_thread_t)context; - - /* create and start the process */ - /* NOTE: The first argument to xbt_os_thread_create used to be the process * - * name, but now the name is stored at SIMIX level, so we pass a null */ - ctx_thread->thread = - xbt_os_thread_create(NULL, smx_ctx_thread_wrapper, ctx_thread); - - /* wait the starting of the newly created process */ - xbt_os_sem_acquire(ctx_thread->end); -} - static void smx_ctx_thread_stop(smx_context_t pcontext) { @@ -169,4 +160,4 @@ static void smx_ctx_thread_resume(smx_context_t not_used, { xbt_os_sem_release(((smx_ctx_thread_t) new_context)->begin); xbt_os_sem_acquire(((smx_ctx_thread_t) new_context)->end); -} \ No newline at end of file +} diff --git a/src/simix/smx_process.c b/src/simix/smx_process.c index 0e92bfc463..601f2c4268 100644 --- a/src/simix/smx_process.c +++ b/src/simix/smx_process.c @@ -129,7 +129,6 @@ smx_process_t SIMIX_process_create(const char *name, xbt_swag_insert(process, host->process_list); DEBUG1("Start context '%s'", process->name); - SIMIX_context_start(process->context); /* Now insert it in the global process list and in the process to run list */ xbt_swag_insert(process, simix_global->process_list); -- 2.20.1