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;
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);
}
* \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);
}
(*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;
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;
}
}
-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;
smx_ctx_java_resume(smx_context_t old_context, smx_context_t new_context)
{
jprocess_schedule(new_context);
-}
\ No newline at end of file
+}
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);
(*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;
/* 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;i<context->argc;i++)
+ lua_pushstring(context->state,context->argv[i]);
+
+ // Call the function (in resume)
+ context->nargs = context->argc-1;
+
} else {
INFO0("Created context for maestro");
}
}
}
-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;i<context->argc;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;
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;
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
(*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;
}
}
-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;
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);
(*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;
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;
}
}
-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;
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
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;
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)
{
{
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
+}
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);