From 3a7bc2b51fce530a2664d62489a106ba66bb1227 Mon Sep 17 00:00:00 2001 From: donassbr Date: Tue, 27 Mar 2007 13:08:45 +0000 Subject: [PATCH] API changed. git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@3363 48e7efb5-ca39-0410-a469-dd3cf9ba447f --- src/include/simix/simix.h | 17 +++++++++++++++-- src/simix/private.h | 6 +++++- src/simix/smx_deployment.c | 36 +++++++++++++++++++++--------------- src/simix/smx_global.c | 26 +++++++++++++++++++++++--- src/simix/smx_process.c | 26 ++++++++++++++++++-------- 5 files changed, 82 insertions(+), 29 deletions(-) diff --git a/src/include/simix/simix.h b/src/include/simix/simix.h index d5effc7431..5ba522b131 100644 --- a/src/include/simix/simix.h +++ b/src/include/simix/simix.h @@ -35,6 +35,18 @@ XBT_PUBLIC(int) SIMIX_timer_get(void **function, void **arg); /* only for tests */ XBT_PUBLIC(void) __SIMIX_main(void); + +/* User create and kill process, the function must accept the folling parameters: + * const char *name: a name for the object. It is for user-level information and can be NULL + * smx_process_code_t code: is a function describing the behavior of the agent + * void *data: data a pointer to any data one may want to attach to the new object. + * smx_host_t host: the location where the new agent is executed + * int argc, char **argv: parameters passed to code + * + * */ +XBT_PUBLIC(void) SIMIX_function_register_process_create(void * function); +XBT_PUBLIC(void) SIMIX_function_register_process_kill(void * function); + /************************** Host handling ***********************************/ XBT_PUBLIC(void) SIMIX_host_set_data(smx_host_t host, void *data); @@ -57,11 +69,12 @@ XBT_PUBLIC(int) SIMIX_host_get_state(smx_host_t host); /************************** Process handling *********************************/ XBT_PUBLIC(smx_process_t) SIMIX_process_create(const char *name, smx_process_code_t code, void *data, - smx_host_t host); + const char * hostname, void * clean_process_function); XBT_PUBLIC(smx_process_t) SIMIX_process_create_with_arguments(const char *name, smx_process_code_t code, void *data, - smx_host_t host, int argc, char **argv); + const char * hostname, int argc, char **argv, void * clean_process_function); XBT_PUBLIC(void) SIMIX_process_kill(smx_process_t process); +XBT_PUBLIC(void) SIMIX_process_cleanup(void *arg); XBT_PUBLIC(void) SIMIX_process_killall(void); //above layer diff --git a/src/simix/private.h b/src/simix/private.h index 0018fd3288..2a15d93da7 100644 --- a/src/simix/private.h +++ b/src/simix/private.h @@ -9,6 +9,7 @@ #ifndef SIMIX_PRIVATE_H #define SIMIX_PRIVATE_H +#include #include "simix/simix.h" #include "surf/surf.h" #include "xbt/fifo.h" @@ -36,6 +37,8 @@ typedef struct SIMIX_Global { smx_process_t current_process; xbt_dict_t registered_functions; + void* (*create_process_function) (); + void* (*kill_process_function)(); } s_SIMIX_Global_t, *SIMIX_Global_t; extern SIMIX_Global_t simix_global; @@ -57,7 +60,7 @@ typedef struct process_arg { const char *name; smx_process_code_t code; void *data; - smx_host_t host; + char *hostname; int argc; char **argv; double kill_time; @@ -111,4 +114,5 @@ void __SIMIX_cond_wait(smx_cond_t cond); void __SIMIX_display_process_status(void); + #endif diff --git a/src/simix/smx_deployment.c b/src/simix/smx_deployment.c index e5a9f119d9..6df337638a 100644 --- a/src/simix/smx_deployment.c +++ b/src/simix/smx_deployment.c @@ -17,14 +17,14 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_deployment, simix, static int parse_argc = -1 ; static char **parse_argv = NULL; static smx_process_code_t parse_code = NULL; -static smx_host_t parse_host = NULL; +static char * parse_host = NULL; static double start_time = 0.0; static double kill_time = -1.0; static void parse_process_init(void) { - parse_host = SIMIX_host_get_by_name(A_surfxml_process_host); - xbt_assert1(parse_host, "Unknown host %s",A_surfxml_process_host); + parse_host = xbt_strdup(A_surfxml_process_host); + xbt_assert1(SIMIX_host_get_by_name(A_surfxml_process_host), "Unknown host %s",A_surfxml_process_host); parse_code = SIMIX_get_registered_function(A_surfxml_process_function); xbt_assert1(parse_code, "Unknown function %s",A_surfxml_process_function); parse_argc = 0 ; @@ -46,32 +46,38 @@ static void parse_argument(void) static void parse_process_finalize(void) { process_arg_t arg = NULL; - smx_process_t process = NULL; + void * process = NULL; if(start_time>SIMIX_get_clock()) { arg = xbt_new0(s_process_arg_t,1); arg->name = parse_argv[0]; arg->code = parse_code; arg->data = NULL; - arg->host = parse_host; + arg->hostname = parse_host; arg->argc = parse_argc; arg->argv = parse_argv; arg->kill_time = kill_time; DEBUG3("Process %s(%s) will be started at time %f", arg->name, - arg->host->name,start_time); - surf_timer_resource->extension_public->set(start_time, (void*) &SIMIX_process_create_with_arguments, - arg); + arg->hostname,start_time); + if (simix_global->create_process_function) + surf_timer_resource->extension_public->set(start_time, (void*) simix_global->create_process_function, arg); + else + surf_timer_resource->extension_public->set(start_time, (void*) &SIMIX_process_create_with_arguments, arg); + } if((start_time<0) || (start_time==SIMIX_get_clock())) { DEBUG2("Starting Process %s(%s) right now", parse_argv[0], - parse_host->name); - process = SIMIX_process_create_with_arguments(parse_argv[0], parse_code, - NULL, parse_host, - parse_argc,parse_argv); + parse_host); + if (simix_global->create_process_function) + process = simix_global->create_process_function(parse_argv[0], parse_code, NULL, parse_host, parse_argc,parse_argv); + else + process = SIMIX_process_create_with_arguments(parse_argv[0], parse_code, NULL, parse_host, parse_argc,parse_argv, NULL); + if(kill_time > SIMIX_get_clock()) { - surf_timer_resource->extension_public->set(kill_time, - (void*) &SIMIX_process_kill, - (void*) process); + if (simix_global->kill_process_function) + surf_timer_resource->extension_public->set(start_time, (void*) simix_global->kill_process_function, arg); + else + surf_timer_resource->extension_public->set(kill_time, (void*) &SIMIX_process_kill, (void*) process); } } } diff --git a/src/simix/smx_global.c b/src/simix/smx_global.c index cbf10cc979..06e8107521 100644 --- a/src/simix/smx_global.c +++ b/src/simix/smx_global.c @@ -270,10 +270,10 @@ double SIMIX_solve(xbt_fifo_t actions_done, xbt_fifo_t actions_failed) DEBUG2("got %p %p", fun, arg); if(fun==SIMIX_process_create_with_arguments) { process_arg_t args = arg; - DEBUG2("Launching %s on %s", args->name, args->host->name); + DEBUG2("Launching %s on %s", args->name, args->hostname); process = SIMIX_process_create_with_arguments(args->name, args->code, - args->data, args->host, - args->argc,args->argv); + args->data, args->hostname, + args->argc,args->argv,NULL); if(args->kill_time > SIMIX_get_clock()) { surf_timer_resource->extension_public->set(args->kill_time, (void*) &SIMIX_process_kill, @@ -333,3 +333,23 @@ int SIMIX_timer_get(void **function, void **arg) { return surf_timer_resource->extension_public->get(function, arg); } + + +void SIMIX_function_register_process_create(void * function) +{ + xbt_assert0((simix_global->create_process_function == NULL), "Data already set"); + + /* Assign create process */ + simix_global->create_process_function = function; + + return ; +} +void SIMIX_function_register_process_kill(void * function) +{ + xbt_assert0((simix_global->kill_process_function == NULL), "Data already set"); + + /* Assign kill process */ + simix_global->kill_process_function = function; + + return ; +} diff --git a/src/simix/smx_process.c b/src/simix/smx_process.c index 2fc9a93ec0..9d5949a76b 100644 --- a/src/simix/smx_process.c +++ b/src/simix/smx_process.c @@ -32,12 +32,12 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_process, simix, */ smx_process_t SIMIX_process_create(const char *name, smx_process_code_t code, void *data, - smx_host_t host) + const char * hostname, void * clean_process_function) { - return SIMIX_process_create_with_arguments(name, code, data, host, -1, NULL); + return SIMIX_process_create_with_arguments(name, code, data, hostname, -1, NULL, clean_process_function); } -static void SIMIX_process_cleanup(void *arg) +void SIMIX_process_cleanup(void *arg) { xbt_swag_remove(arg, simix_global->process_list); xbt_swag_remove(arg, simix_global->process_to_run); @@ -75,11 +75,12 @@ static void SIMIX_process_cleanup(void *arg) */ smx_process_t SIMIX_process_create_with_arguments(const char *name, smx_process_code_t code, void *data, - smx_host_t host, int argc, char **argv) + const char * hostname, int argc, char **argv, void * clean_process_function) { smx_simdata_process_t simdata = xbt_new0(s_smx_simdata_process_t,1); smx_process_t process = xbt_new0(s_smx_process_t,1); smx_process_t self = NULL; + smx_host_t host = SIMIX_host_get_by_name(hostname); xbt_assert0(((code != NULL) && (host != NULL)), "Invalid parameters"); /* Simulator Data */ @@ -87,10 +88,16 @@ smx_process_t SIMIX_process_create_with_arguments(const char *name, simdata->host = host; simdata->argc = argc; simdata->argv = argv; - simdata->context = xbt_context_new(code, NULL, NULL, - SIMIX_process_cleanup, process, - simdata->argc, simdata->argv); - + if (clean_process_function) { + simdata->context = xbt_context_new(code, NULL, NULL, + clean_process_function, process, + simdata->argc, simdata->argv); + } + else { + simdata->context = xbt_context_new(code, NULL, NULL, + SIMIX_process_cleanup, process, + simdata->argc, simdata->argv); + } //simdata->last_errno=SIMIX_OK; @@ -114,6 +121,9 @@ smx_process_t SIMIX_process_create_with_arguments(const char *name, return process; } + + + /** \ingroup m_process_management * \param process poor victim * -- 2.20.1