X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/c0cd1012b35aa6e68298c5a0f590e43ca958b005..c9915805944cfa61187e82d2139703b99716fbf9:/src/simix/smx_context_ruby.c diff --git a/src/simix/smx_context_ruby.c b/src/simix/smx_context_ruby.c index 653dd56e2f..f3361d11c8 100644 --- a/src/simix/smx_context_ruby.c +++ b/src/simix/smx_context_ruby.c @@ -1,16 +1,17 @@ /* context_Ruby - implementation of context switching with/for ruby */ -/* Copyright (c) 2010, the SimGrid team. All right reserved. */ +/* Copyright (c) 2010. The SimGrid Team. + * All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ -#include "private.h" #include "xbt/function_types.h" #include "xbt/sysdep.h" #include "xbt/log.h" #include "xbt/asserts.h" +#include "smx_context_private.h" #include "bindings/ruby_bindings.h" XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(ruby); @@ -19,23 +20,18 @@ static smx_context_t smx_ctx_ruby_create_context(xbt_main_func_t code,int argc,char** argv, void_f_pvoid_t cleanup_func,void *cleanup_arg); -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 -smx_ctx_ruby_resume(smx_context_t old_context,smx_context_t new_context); +static void smx_ctx_ruby_resume(smx_context_t new_context); static void smx_ctx_ruby_wrapper(void); void SIMIX_ctx_ruby_factory_init(smx_context_factory_t *factory) { - *factory = xbt_new0(s_smx_context_factory_t,1); + smx_ctx_base_factory_init(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; + /* Do not overload that method (*factory)->finalize */ + /* Do not overload that method (*factory)->free */ (*factory)->stop = smx_ctx_ruby_stop; (*factory)->suspend = smx_ctx_ruby_suspend; (*factory)->resume = smx_ctx_ruby_resume; @@ -44,75 +40,29 @@ void SIMIX_ctx_ruby_factory_init(smx_context_factory_t *factory) { ruby_init_loadpath(); } -static int smx_ctx_ruby_factory_finalize(smx_context_factory_t *factory) { - free(*factory); - *factory = NULL; - return 0; -} - static smx_context_t smx_ctx_ruby_create_context(xbt_main_func_t code,int argc,char** argv, void_f_pvoid_t cleanup_func,void* cleanup_arg) { - smx_ctx_ruby_t context = xbt_new0(s_smx_ctx_ruby_t,1); + smx_ctx_ruby_t context = (smx_ctx_ruby_t)smx_ctx_base_factory_create_context_sized + (sizeof(s_smx_ctx_ruby_t), code,argc,argv,cleanup_func,cleanup_arg); /* if the user provided a function for the process , then use it Otherwise it's the context for maestro */ if (code) { - context->cleanup_func = cleanup_func; - context->cleanup_arg = cleanup_arg; context->process = (VALUE)code; - context->argc=argc; - context->argv=argv; DEBUG1("smx_ctx_ruby_create_context(%s)...Done",argv[0]); } return (smx_context_t) context; } -// FIXME -static void smx_ctx_ruby_free(smx_context_t context) { - // DEBUG1("smx_ctx_ruby_free(%s)",context->argv[0]); - - //VALUE process; - /*if (context) - { - smx_ctx_ruby_t ctx_ruby = (smx_ctx_ruby_t) context; - rb_process_isProcess(ctx_ruby->process); - if (ctx_ruby->process){ - // if the Ruby Process is Alive , Join it - if ( rb_process_isAlive(ctx_ruby->process)) - { - process = ctx_ruby->process; - ctx_ruby->process = Qnil; - rb_process_join(process); - } - } - free(context); - context = NULL; - } */ - - if (context) { - DEBUG1("smx_ctx_ruby_free_context(%p)",context); - free (context); - context = NULL; - } -} - -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; smx_ctx_ruby_t ctx_ruby,current; - if ( context->cleanup_func) - (*(context->cleanup_func)) (context->cleanup_arg); + smx_ctx_base_stop(context); ctx_ruby = (smx_ctx_ruby_t) context; @@ -145,9 +95,8 @@ static void smx_ctx_ruby_suspend(smx_context_t context) { rb_process_unschedule(ctx_ruby->process); } -static void smx_ctx_ruby_resume(smx_context_t old_context,smx_context_t new_context) { - DEBUG2("smx_ctx_ruby_resume(%s,%s)", - (old_context->argc?old_context->argv[0]:"maestro"), +static void smx_ctx_ruby_resume(smx_context_t new_context) { + DEBUG1("smx_ctx_ruby_resume(%s)", (new_context->argc?new_context->argv[0]:"maestro")); smx_ctx_ruby_t ctx_ruby = (smx_ctx_ruby_t) new_context;