From: alegrand Date: Mon, 6 Aug 2007 12:23:37 +0000 (+0000) Subject: Reindent! X-Git-Tag: v3.3~1377 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/b69e984a013e4e9e2d98fc4013cd1721bf2f0245 Reindent! git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@3983 48e7efb5-ca39-0410-a469-dd3cf9ba447f --- diff --git a/src/simix/private.h b/src/simix/private.h index bafad3ecf9..a575278b73 100644 --- a/src/simix/private.h +++ b/src/simix/private.h @@ -39,8 +39,8 @@ typedef struct SIMIX_Global { smx_process_t current_process; xbt_dict_t registered_functions; smx_creation_func_t *create_process_function; - void_f_pvoid_t* kill_process_function; - void_f_pvoid_t* cleanup_process_function; + void_f_pvoid_t *kill_process_function; + void_f_pvoid_t *cleanup_process_function; } s_SIMIX_Global_t, *SIMIX_Global_t; extern SIMIX_Global_t simix_global; @@ -48,14 +48,14 @@ extern SIMIX_Global_t simix_global; /******************************* Process *************************************/ typedef struct s_smx_simdata_process { - smx_host_t s_host; /* the host on which the process is running */ - xbt_context_t context; /* the context that executes the scheduler fonction */ + smx_host_t s_host; /* the host on which the process is running */ + xbt_context_t context; /* the context that executes the scheduler fonction */ int blocked; int suspended; smx_mutex_t mutex; /* mutex on which the process is blocked */ smx_cond_t cond; /* cond on which the process is blocked */ - int argc; /* arguments number if any */ - char **argv; /* arguments table if any */ + int argc; /* arguments number if any */ + char **argv; /* arguments table if any */ } s_smx_simdata_process_t; typedef struct s_smx_process_arg { @@ -72,20 +72,20 @@ typedef struct s_smx_process_arg { typedef struct s_smx_mutex { - /* KEEP IT IN SYNC WITH src/xbt_sg_thread.c::struct s_xbt_mutex */ - xbt_swag_t sleeping; /* list of sleeping process */ - int using; - /* KEEP IT IN SYNC WITH src/xbt_sg_thread.c::struct s_xbt_mutex */ + /* KEEP IT IN SYNC WITH src/xbt_sg_thread.c::struct s_xbt_mutex */ + xbt_swag_t sleeping; /* list of sleeping process */ + int using; + /* KEEP IT IN SYNC WITH src/xbt_sg_thread.c::struct s_xbt_mutex */ } s_smx_mutex_t; typedef struct s_smx_cond { - - /* KEEP IT IN SYNC WITH src/xbt_sg_thread.c::struct s_xbt_cond */ - xbt_swag_t sleeping; /* list of sleeping process */ - smx_mutex_t mutex; - xbt_fifo_t actions; /* list of actions */ - /* KEEP IT IN SYNC WITH src/xbt_sg_thread.c::struct s_xbt_cond */ + + /* KEEP IT IN SYNC WITH src/xbt_sg_thread.c::struct s_xbt_cond */ + xbt_swag_t sleeping; /* list of sleeping process */ + smx_mutex_t mutex; + xbt_fifo_t actions; /* list of actions */ + /* KEEP IT IN SYNC WITH src/xbt_sg_thread.c::struct s_xbt_cond */ } s_smx_cond_t; @@ -93,8 +93,8 @@ typedef struct s_smx_cond { typedef struct s_smx_simdata_action { surf_action_t surf_action; /* SURF modeling of computation */ - - smx_host_t source; + + smx_host_t source; } s_smx_simdata_action_t; @@ -102,11 +102,11 @@ typedef struct s_smx_simdata_action { /******************************* Configuration support **********************************/ -void simix_config_init(void); /* create the config set, call this before use! */ -void simix_config_finalize(void); /* destroy the config set, call this at cleanup. */ -extern int _simix_init_status; /* 0: beginning of time; - 1: pre-inited (cfg_set created); - 2: inited (running) */ +void simix_config_init(void); /* create the config set, call this before use! */ +void simix_config_finalize(void); /* destroy the config set, call this at cleanup. */ +extern int _simix_init_status; /* 0: beginning of time; + 1: pre-inited (cfg_set created); + 2: inited (running) */ extern xbt_cfg_t _simix_cfg_set; @@ -114,7 +114,8 @@ extern xbt_cfg_t _simix_cfg_set; get_state(SIMIX_host_self()->simdata->host)==SURF_CPU_ON,\ "Host failed, you cannot call this function.") -smx_host_t __SIMIX_host_create(const char *name, void *workstation, void *data); +smx_host_t __SIMIX_host_create(const char *name, void *workstation, + void *data); void __SIMIX_host_destroy(smx_host_t host); void __SIMIX_cond_wait(smx_cond_t cond); diff --git a/src/simix/smx_action.c b/src/simix/smx_action.c index b136398bdb..31caeab5fe 100644 --- a/src/simix/smx_action.c +++ b/src/simix/smx_action.c @@ -24,34 +24,43 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_action, simix, * \param rate Communication rate between hosts. * \return A new SIMIX action * */ -smx_action_t SIMIX_action_communicate(smx_host_t sender,smx_host_t receiver,char * name, double size, double rate) +smx_action_t SIMIX_action_communicate(smx_host_t sender, + smx_host_t receiver, char *name, + double size, double rate) { - /* check if the host is active */ - if ( surf_workstation_resource->extension_public->get_state(sender->simdata->host)!=SURF_CPU_ON) { - THROW1(network_error,0,"Host %s failed, you cannot call this function",sender->name); - } - if ( surf_workstation_resource->extension_public->get_state(receiver->simdata->host)!=SURF_CPU_ON) { - THROW1(network_error,0,"Host %s failed, you cannot call this function",receiver->name); - } - - /* alloc structures */ - smx_action_t act = xbt_new0(s_smx_action_t,1); - act->simdata = xbt_new0(s_smx_simdata_action_t,1); - smx_simdata_action_t simdata = act->simdata; - act->cond_list = xbt_fifo_new(); - - /* initialize them */ - act->name = xbt_strdup(name); - simdata->source = sender; - - - simdata->surf_action = surf_workstation_resource->extension_public-> - communicate(sender->simdata->host, - receiver->simdata->host, size, rate); - surf_workstation_resource->common_public->action_set_data(simdata->surf_action,act); - - DEBUG1("Create communicate action %p",act); - return act; + /* check if the host is active */ + if (surf_workstation_resource->extension_public-> + get_state(sender->simdata->host) != SURF_CPU_ON) { + THROW1(network_error, 0, + "Host %s failed, you cannot call this function", sender->name); + } + if (surf_workstation_resource->extension_public-> + get_state(receiver->simdata->host) != SURF_CPU_ON) { + THROW1(network_error, 0, + "Host %s failed, you cannot call this function", + receiver->name); + } + + /* alloc structures */ + smx_action_t act = xbt_new0(s_smx_action_t, 1); + act->simdata = xbt_new0(s_smx_simdata_action_t, 1); + smx_simdata_action_t simdata = act->simdata; + act->cond_list = xbt_fifo_new(); + + /* initialize them */ + act->name = xbt_strdup(name); + simdata->source = sender; + + + simdata->surf_action = surf_workstation_resource->extension_public-> + communicate(sender->simdata->host, + receiver->simdata->host, size, rate); + surf_workstation_resource->common_public->action_set_data(simdata-> + surf_action, + act); + + DEBUG1("Create communicate action %p", act); + return act; } /** \brief Creates a new SIMIX action to execute an action. @@ -62,31 +71,36 @@ smx_action_t SIMIX_action_communicate(smx_host_t sender,smx_host_t receiver,char * \param amount Task amount (in bytes) * \return A new SIMIX action * */ -smx_action_t SIMIX_action_execute(smx_host_t host, char * name, double amount) +smx_action_t SIMIX_action_execute(smx_host_t host, char *name, + double amount) { - /* check if the host is active */ - if ( surf_workstation_resource->extension_public->get_state(host->simdata->host)!=SURF_CPU_ON) { - THROW1(host_error,0,"Host %s failed, you cannot call this function",host->name); - } - - /* alloc structures */ - smx_action_t act = xbt_new0(s_smx_action_t,1); - act->simdata = xbt_new0(s_smx_simdata_action_t,1); - smx_simdata_action_t simdata = act->simdata; - act->cond_list = xbt_fifo_new(); - - /* initialize them */ - simdata->source = host; - act-> name = xbt_strdup(name); - - /* set communication */ - simdata->surf_action = surf_workstation_resource->extension_public-> - execute(host->simdata->host, amount); - - surf_workstation_resource->common_public->action_set_data(simdata->surf_action,act); - - DEBUG1("Create execute action %p",act); - return act; + /* check if the host is active */ + if (surf_workstation_resource->extension_public-> + get_state(host->simdata->host) != SURF_CPU_ON) { + THROW1(host_error, 0, "Host %s failed, you cannot call this function", + host->name); + } + + /* alloc structures */ + smx_action_t act = xbt_new0(s_smx_action_t, 1); + act->simdata = xbt_new0(s_smx_simdata_action_t, 1); + smx_simdata_action_t simdata = act->simdata; + act->cond_list = xbt_fifo_new(); + + /* initialize them */ + simdata->source = host; + act->name = xbt_strdup(name); + + /* set communication */ + simdata->surf_action = surf_workstation_resource->extension_public-> + execute(host->simdata->host, amount); + + surf_workstation_resource->common_public->action_set_data(simdata-> + surf_action, + act); + + DEBUG1("Create execute action %p", act); + return act; } /** \brief Creates a new sleep SIMIX action. @@ -96,32 +110,36 @@ smx_action_t SIMIX_action_execute(smx_host_t host, char * name, double amount) * \param duration Time duration of the sleep. * \return A new SIMIX action * */ -smx_action_t SIMIX_action_sleep(smx_host_t host, double duration) -{ - char name[] = "sleep"; - - /* check if the host is active */ - if ( surf_workstation_resource->extension_public->get_state(host->simdata->host)!=SURF_CPU_ON) { - THROW1(host_error,0,"Host %s failed, you cannot call this function",host->name); - } - - /* alloc structures */ - smx_action_t act = xbt_new0(s_smx_action_t,1); - act->simdata = xbt_new0(s_smx_simdata_action_t,1); - smx_simdata_action_t simdata = act->simdata; - act->cond_list = xbt_fifo_new(); - - /* initialize them */ - simdata->source = host; - act->name = xbt_strdup(name); - - simdata->surf_action = surf_workstation_resource->extension_public-> - sleep(host->simdata->host, duration); - - surf_workstation_resource->common_public->action_set_data(simdata->surf_action,act); - - DEBUG1("Create sleep action %p",act); - return act; +smx_action_t SIMIX_action_sleep(smx_host_t host, double duration) +{ + char name[] = "sleep"; + + /* check if the host is active */ + if (surf_workstation_resource->extension_public-> + get_state(host->simdata->host) != SURF_CPU_ON) { + THROW1(host_error, 0, "Host %s failed, you cannot call this function", + host->name); + } + + /* alloc structures */ + smx_action_t act = xbt_new0(s_smx_action_t, 1); + act->simdata = xbt_new0(s_smx_simdata_action_t, 1); + smx_simdata_action_t simdata = act->simdata; + act->cond_list = xbt_fifo_new(); + + /* initialize them */ + simdata->source = host; + act->name = xbt_strdup(name); + + simdata->surf_action = surf_workstation_resource->extension_public-> + sleep(host->simdata->host, duration); + + surf_workstation_resource->common_public->action_set_data(simdata-> + surf_action, + act); + + DEBUG1("Create sleep action %p", act); + return act; } /** @@ -134,9 +152,11 @@ void SIMIX_action_cancel(smx_action_t action) { xbt_assert0((action != NULL), "Invalid parameter"); - DEBUG1("Cancel action %p",action); - if(action->simdata->surf_action) { - surf_workstation_resource->common_public->action_cancel(action->simdata->surf_action); + DEBUG1("Cancel action %p", action); + if (action->simdata->surf_action) { + surf_workstation_resource->common_public->action_cancel(action-> + simdata-> + surf_action); } return; } @@ -150,11 +170,12 @@ void SIMIX_action_cancel(smx_action_t action) */ void SIMIX_action_set_priority(smx_action_t action, double priority) { - xbt_assert0( (action != NULL) && (action->simdata != NULL), "Invalid parameter" ); + xbt_assert0((action != NULL) + && (action->simdata != NULL), "Invalid parameter"); - surf_workstation_resource->common_public-> - set_priority(action->simdata->surf_action, priority); - return; + surf_workstation_resource->common_public-> + set_priority(action->simdata->surf_action, priority); + return; } /** @@ -166,22 +187,25 @@ void SIMIX_action_set_priority(smx_action_t action, double priority) void SIMIX_action_destroy(smx_action_t action) { - xbt_assert0((action != NULL), "Invalid parameter"); + xbt_assert0((action != NULL), "Invalid parameter"); - xbt_assert1((xbt_fifo_size(action->cond_list)==0), - "Conditional list not empty %d. There is a problem. Cannot destroy it now!", xbt_fifo_size(action->cond_list)); + xbt_assert1((xbt_fifo_size(action->cond_list) == 0), + "Conditional list not empty %d. There is a problem. Cannot destroy it now!", + xbt_fifo_size(action->cond_list)); - DEBUG1("Destroy action %p",action); - if(action->name) xbt_free(action->name); + DEBUG1("Destroy action %p", action); + if (action->name) + xbt_free(action->name); - xbt_fifo_free(action->cond_list); + xbt_fifo_free(action->cond_list); - if(action->simdata->surf_action) - action->simdata->surf_action->resource_type->common_public->action_free(action->simdata->surf_action); + if (action->simdata->surf_action) + action->simdata->surf_action->resource_type->common_public-> + action_free(action->simdata->surf_action); - xbt_free(action->simdata); - xbt_free(action); - return; + xbt_free(action->simdata); + xbt_free(action); + return; } /** @@ -191,12 +215,13 @@ void SIMIX_action_destroy(smx_action_t action) * \param action SIMIX action * \param cond SIMIX cond */ -void SIMIX_register_action_to_condition(smx_action_t action, smx_cond_t cond) +void SIMIX_register_action_to_condition(smx_action_t action, + smx_cond_t cond) { - xbt_assert0( (action != NULL) && (cond != NULL), "Invalid parameters"); + xbt_assert0((action != NULL) && (cond != NULL), "Invalid parameters"); - DEBUG2("Register action %p to condtion %p",action,cond); - xbt_fifo_push(cond->actions,action); + DEBUG2("Register action %p to condtion %p", action, cond); + xbt_fifo_push(cond->actions, action); } /** @@ -205,35 +230,46 @@ void SIMIX_register_action_to_condition(smx_action_t action, smx_cond_t cond) * \param action The SIMIX action * \return Remains cost */ -double SIMIX_action_get_remains(smx_action_t action) +double SIMIX_action_get_remains(smx_action_t action) { xbt_assert0((action != NULL), "Invalid parameter"); - return action->simdata->surf_action->remains; + return action->simdata->surf_action->remains; } -smx_action_t SIMIX_action_parallel_execute(char *name, int workstation_nb, void **workstation_list, double *computation_amount, double *communication_amount, double amount, double rate) +smx_action_t SIMIX_action_parallel_execute(char *name, int workstation_nb, + void **workstation_list, + double *computation_amount, + double *communication_amount, + double amount, double rate) { - /* alloc structures */ - smx_action_t act = xbt_new0(s_smx_action_t,1); - act->simdata = xbt_new0(s_smx_simdata_action_t,1); - smx_simdata_action_t simdata = act->simdata; - act->cond_list = xbt_fifo_new(); - - /* initialize them */ - act-> name = xbt_strdup(name); + /* alloc structures */ + smx_action_t act = xbt_new0(s_smx_action_t, 1); + act->simdata = xbt_new0(s_smx_simdata_action_t, 1); + smx_simdata_action_t simdata = act->simdata; + act->cond_list = xbt_fifo_new(); + + /* initialize them */ + act->name = xbt_strdup(name); - /* set communication */ - simdata->surf_action = surf_workstation_resource->extension_public->execute_parallel_task(workstation_nb, workstation_list, computation_amount, communication_amount, amount, rate); + /* set communication */ + simdata->surf_action = + surf_workstation_resource->extension_public-> + execute_parallel_task(workstation_nb, workstation_list, + computation_amount, communication_amount, + amount, rate); - surf_workstation_resource->common_public->action_set_data(simdata->surf_action,act); + surf_workstation_resource->common_public->action_set_data(simdata-> + surf_action, + act); - return act; + return act; } e_surf_action_state_t SIMIX_action_get_state(smx_action_t action) { xbt_assert0((action != NULL), "Invalid parameter"); - return surf_workstation_resource->common_public->action_get_state(action->simdata->surf_action); + return surf_workstation_resource->common_public-> + action_get_state(action->simdata->surf_action); } diff --git a/src/simix/smx_config.c b/src/simix/smx_config.c index e6cc7becf8..0d4669318e 100644 --- a/src/simix/smx_config.c +++ b/src/simix/smx_config.c @@ -10,82 +10,84 @@ #include "xbt/sysdep.h" #include "xbt/log.h" -int _simix_init_status = 0; /* 0: beginning of time; - 1: pre-inited (cfg_set created); - 2: inited (running) */ +int _simix_init_status = 0; /* 0: beginning of time; + 1: pre-inited (cfg_set created); + 2: inited (running) */ xbt_cfg_t _simix_cfg_set = NULL; /* callback of the workstation_model variable */ -static void _simix_cfg_cb__workstation_model(const char *name, int pos) +static void _simix_cfg_cb__workstation_model(const char *name, int pos) { char *val; - xbt_assert0(_simix_init_status<2, "Cannot change the model after the initialization"); - - val = xbt_cfg_get_string (_simix_cfg_set, name); + xbt_assert0(_simix_init_status < 2, + "Cannot change the model after the initialization"); + + val = xbt_cfg_get_string(_simix_cfg_set, name); /* New Module missing */ - + find_resource_description(surf_workstation_resource_description, surf_workstation_resource_description_size, val); } /* callback of the cpu_model variable */ -static void _simix_cfg_cb__cpu_model(const char *name, int pos) +static void _simix_cfg_cb__cpu_model(const char *name, int pos) { char *val; - xbt_assert0(_simix_init_status<2, "Cannot change the model after the initialization"); - - val = xbt_cfg_get_string (_simix_cfg_set, name); + xbt_assert0(_simix_init_status < 2, + "Cannot change the model after the initialization"); + + val = xbt_cfg_get_string(_simix_cfg_set, name); /* New Module missing */ find_resource_description(surf_cpu_resource_description, - surf_cpu_resource_description_size, - val); + surf_cpu_resource_description_size, val); } + /* callback of the workstation_model variable */ -static void _simix_cfg_cb__network_model(const char *name, int pos) +static void _simix_cfg_cb__network_model(const char *name, int pos) { char *val; - xbt_assert0(_simix_init_status<2, "Cannot change the model after the initialization"); - - val = xbt_cfg_get_string (_simix_cfg_set, name); + xbt_assert0(_simix_init_status < 2, + "Cannot change the model after the initialization"); + + val = xbt_cfg_get_string(_simix_cfg_set, name); /* New Module missing */ find_resource_description(surf_network_resource_description, - surf_network_resource_description_size, - val); + surf_network_resource_description_size, val); } /* create the config set and register what should be */ -void simix_config_init(void) +void simix_config_init(void) { - if (_simix_init_status) - return; /* Already inited, nothing to do */ + if (_simix_init_status) + return; /* Already inited, nothing to do */ _simix_init_status = 1; _simix_cfg_set = xbt_cfg_new(); - - xbt_cfg_register (_simix_cfg_set, - "workstation_model", xbt_cfgelm_string, 1,1, - &_simix_cfg_cb__workstation_model,NULL); - - xbt_cfg_register (_simix_cfg_set, - "cpu_model", xbt_cfgelm_string, 1,1, - &_simix_cfg_cb__cpu_model,NULL); - xbt_cfg_register (_simix_cfg_set, - "network_model", xbt_cfgelm_string, 1,1, - &_simix_cfg_cb__network_model,NULL); - - xbt_cfg_set_string(_simix_cfg_set,"workstation_model", "KCCFLN05"); + + xbt_cfg_register(_simix_cfg_set, + "workstation_model", xbt_cfgelm_string, 1, 1, + &_simix_cfg_cb__workstation_model, NULL); + + xbt_cfg_register(_simix_cfg_set, + "cpu_model", xbt_cfgelm_string, 1, 1, + &_simix_cfg_cb__cpu_model, NULL); + xbt_cfg_register(_simix_cfg_set, + "network_model", xbt_cfgelm_string, 1, 1, + &_simix_cfg_cb__network_model, NULL); + + xbt_cfg_set_string(_simix_cfg_set, "workstation_model", "KCCFLN05"); } -void simix_config_finalize(void) +void simix_config_finalize(void) { - if (!_simix_init_status) - return; /* Not initialized yet. Nothing to do */ + if (!_simix_init_status) + return; /* Not initialized yet. Nothing to do */ xbt_cfg_free(&_simix_cfg_set); _simix_init_status = 0; @@ -104,10 +106,10 @@ void simix_config_finalize(void) * \param name Configuration variable name that will change. * \param pa A va_list with the others parameters */ -void SIMIX_config(const char *name, va_list pa) +void SIMIX_config(const char *name, va_list pa) { if (!_simix_init_status) { simix_config_init(); } - xbt_cfg_set_vargs(_simix_cfg_set,name,pa); + xbt_cfg_set_vargs(_simix_cfg_set, name, pa); } diff --git a/src/simix/smx_deployment.c b/src/simix/smx_deployment.c index 055172d949..4a2bb97975 100644 --- a/src/simix/smx_deployment.c +++ b/src/simix/smx_deployment.c @@ -14,26 +14,28 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_deployment, simix, "Logging specific to SIMIX (deployment)"); -static int parse_argc = -1 ; +static int parse_argc = -1; static char **parse_argv = NULL; static xbt_main_func_t parse_code = NULL; -static char * 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 = xbt_strdup(A_surfxml_process_host); - xbt_assert1(SIMIX_host_get_by_name(A_surfxml_process_host), "Unknown host %s",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 ; + xbt_assert1(parse_code, "Unknown function %s", + A_surfxml_process_function); + parse_argc = 0; parse_argv = NULL; parse_argc++; parse_argv = xbt_realloc(parse_argv, (parse_argc) * sizeof(char *)); parse_argv[(parse_argc) - 1] = xbt_strdup(A_surfxml_process_function); - surf_parse_get_double(&start_time,A_surfxml_process_start_time); - surf_parse_get_double(&kill_time,A_surfxml_process_kill_time); + surf_parse_get_double(&start_time, A_surfxml_process_start_time); + surf_parse_get_double(&kill_time, A_surfxml_process_kill_time); } static void parse_argument(void) @@ -46,9 +48,9 @@ static void parse_argument(void) static void parse_process_finalize(void) { smx_process_arg_t arg = NULL; - void * process = NULL; - if(start_time>SIMIX_get_clock()) { - arg = xbt_new0(s_smx_process_arg_t,1); + void *process = NULL; + if (start_time > SIMIX_get_clock()) { + arg = xbt_new0(s_smx_process_arg_t, 1); arg->name = parse_argv[0]; arg->code = parse_code; arg->data = NULL; @@ -57,29 +59,46 @@ static void parse_process_finalize(void) arg->argv = parse_argv; arg->kill_time = kill_time; - DEBUG3("Process %s(%s) will be started at time %f", arg->name, - 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, arg); + DEBUG3("Process %s(%s) will be started at time %f", arg->name, + 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, + arg); } - if((start_time<0) || (start_time==SIMIX_get_clock())) { + if ((start_time < 0) || (start_time == SIMIX_get_clock())) { DEBUG2("Starting Process %s(%s) right now", parse_argv[0], 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(parse_argv[0], parse_code, NULL, parse_host, parse_argc,parse_argv); - - if(kill_time > SIMIX_get_clock()) { - 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); - } - xbt_free(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(parse_argv[0], parse_code, NULL, parse_host, + parse_argc, parse_argv); + + if (kill_time > SIMIX_get_clock()) { + 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); + } + xbt_free(parse_host); } } @@ -97,14 +116,15 @@ static void parse_process_finalize(void) * \include small_deployment.xml * */ -void SIMIX_launch_application(const char *file) +void SIMIX_launch_application(const char *file) { - xbt_assert0(simix_global,"SIMIX_global_init has to be called before SIMIX_launch_application."); + xbt_assert0(simix_global, + "SIMIX_global_init has to be called before SIMIX_launch_application."); STag_surfxml_process_fun = parse_process_init; ETag_surfxml_argument_fun = parse_argument; ETag_surfxml_process_fun = parse_process_finalize; surf_parse_open(file); - xbt_assert1((!surf_parse()),"Parse error in %s",file); + xbt_assert1((!surf_parse()), "Parse error in %s", file); surf_parse_close(); } @@ -116,11 +136,12 @@ void SIMIX_launch_application(const char *file) * \param name the reference name of the function. * \param code the function */ -void SIMIX_function_register(const char *name,xbt_main_func_t code) +void SIMIX_function_register(const char *name, xbt_main_func_t code) { - xbt_assert0(simix_global,"SIMIX_global_init has to be called before SIMIX_function_register."); + xbt_assert0(simix_global, + "SIMIX_global_init has to be called before SIMIX_function_register."); - xbt_dict_set(simix_global->registered_functions,name,code,NULL); + xbt_dict_set(simix_global->registered_functions, name, code, NULL); } /** @@ -133,8 +154,8 @@ void SIMIX_function_register(const char *name,xbt_main_func_t code) */ xbt_main_func_t SIMIX_get_registered_function(const char *name) { - xbt_assert0(simix_global,"SIMIX_global_init has to be called before SIMIX_get_registered_function."); + xbt_assert0(simix_global, + "SIMIX_global_init has to be called before SIMIX_get_registered_function."); - return xbt_dict_get_or_null(simix_global->registered_functions,name); + return xbt_dict_get_or_null(simix_global->registered_functions, name); } - diff --git a/src/simix/smx_environment.c b/src/simix/smx_environment.c index db9c81b381..8ce445157c 100644 --- a/src/simix/smx_environment.c +++ b/src/simix/smx_environment.c @@ -29,7 +29,7 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_environment, simix, * \include small_platform.xml * */ -void SIMIX_create_environment(const char *file) +void SIMIX_create_environment(const char *file) { xbt_dict_cursor_t cursor = NULL; char *name = NULL; @@ -37,59 +37,68 @@ void SIMIX_create_environment(const char *file) char *workstation_model_name; int workstation_id = -1; - simix_config_init(); /* make sure that our configuration set is created */ + simix_config_init(); /* make sure that our configuration set is created */ surf_timer_resource_init(file); /* which model do you want today? */ - workstation_model_name = xbt_cfg_get_string (_simix_cfg_set, "workstation_model"); + workstation_model_name = + xbt_cfg_get_string(_simix_cfg_set, "workstation_model"); DEBUG1("Model : %s", workstation_model_name); - workstation_id = find_resource_description(surf_workstation_resource_description, - surf_workstation_resource_description_size, - workstation_model_name); - if(!strcmp(workstation_model_name,"compound")) { + workstation_id = + find_resource_description(surf_workstation_resource_description, + surf_workstation_resource_description_size, + workstation_model_name); + if (!strcmp(workstation_model_name, "compound")) { xbt_ex_t e; char *network_model_name = NULL; char *cpu_model_name = NULL; int network_id = -1; int cpu_id = -1; - TRY { - cpu_model_name = xbt_cfg_get_string (_simix_cfg_set, "cpu_model"); - } CATCH(e) { + TRY { + cpu_model_name = xbt_cfg_get_string(_simix_cfg_set, "cpu_model"); + } CATCH(e) { if (e.category == bound_error) { - xbt_assert0(0,"Set a cpu model to use with the 'compound' workstation model"); - xbt_ex_free(e); - } else { - RETHROW; + xbt_assert0(0, + "Set a cpu model to use with the 'compound' workstation model"); + xbt_ex_free(e); + } else { + RETHROW; } } - TRY { - network_model_name=xbt_cfg_get_string (_simix_cfg_set, "network_model"); - } CATCH(e) { + TRY { + network_model_name = + xbt_cfg_get_string(_simix_cfg_set, "network_model"); + } + CATCH(e) { if (e.category == bound_error) { - xbt_assert0(0,"Set a network model to use with the 'compound' workstation model"); - xbt_ex_free(e); - } else { - RETHROW; + xbt_assert0(0, + "Set a network model to use with the 'compound' workstation model"); + xbt_ex_free(e); + } else { + RETHROW; } } - network_id = find_resource_description(surf_network_resource_description, - surf_network_resource_description_size, - network_model_name); - cpu_id = find_resource_description(surf_cpu_resource_description, - surf_cpu_resource_description_size, - cpu_model_name); + network_id = + find_resource_description(surf_network_resource_description, + surf_network_resource_description_size, + network_model_name); + cpu_id = + find_resource_description(surf_cpu_resource_description, + surf_cpu_resource_description_size, + cpu_model_name); surf_cpu_resource_description[cpu_id].resource_init(file); surf_network_resource_description[network_id].resource_init(file); } - surf_workstation_resource_description[workstation_id].resource_init(file); + surf_workstation_resource_description[workstation_id]. + resource_init(file); - _simix_init_status = 2; /* inited; don't change settings now */ + _simix_init_status = 2; /* inited; don't change settings now */ xbt_dict_foreach(workstation_set, cursor, name, workstation) { __SIMIX_host_create(name, workstation, NULL); @@ -97,4 +106,3 @@ void SIMIX_create_environment(const char *file) return; } - diff --git a/src/simix/smx_global.c b/src/simix/smx_global.c index 8cf72be108..ff96a3dbb5 100644 --- a/src/simix/smx_global.c +++ b/src/simix/smx_global.c @@ -9,23 +9,25 @@ #include "private.h" #include "xbt/sysdep.h" #include "xbt/log.h" -#include "xbt/ex.h" /* ex_backtrace_display */ +#include "xbt/ex.h" /* ex_backtrace_display */ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_kernel, simix, "Logging specific to SIMIX (kernel)"); SIMIX_Global_t simix_global = NULL; /********************************* SIMIX **************************************/ -static void __simix_config_helper(const char *name, ...) { +static void __simix_config_helper(const char *name, ...) +{ va_list pa; - va_start(pa,name); - - SIMIX_config(name,pa); - + va_start(pa, name); + + SIMIX_config(name, pa); + va_end(pa); } -static void simix_cfg_control_set(const char* control_string) { +static void simix_cfg_control_set(const char *control_string) +{ /* To split the string in commands, and the cursors */ xbt_dynar_t set_strings; char *str; @@ -33,19 +35,19 @@ static void simix_cfg_control_set(const char* control_string) { if (!control_string) return; - DEBUG1("Parse log settings '%s'",control_string); + DEBUG1("Parse log settings '%s'", control_string); /* split the string, and remove empty entries */ - set_strings=xbt_str_split_quoted(control_string); + set_strings = xbt_str_split_quoted(control_string); - if (xbt_dynar_length(set_strings) == 0) { /* vicious user! */ + if (xbt_dynar_length(set_strings) == 0) { /* vicious user! */ xbt_dynar_free(&set_strings); - return; + return; } /* Parse each entry and either use it right now (if the category was already created), or store it for further use */ - xbt_dynar_foreach(set_strings,cpt,str) { - char *control_string,*control_string_sav,*name,*value; + xbt_dynar_foreach(set_strings, cpt, str) { + char *control_string, *control_string_sav, *name, *value; control_string = control_string_sav = strdup(str); @@ -53,40 +55,43 @@ static void simix_cfg_control_set(const char* control_string) { name = control_string; control_string += strcspn(str, ":="); value = control_string; - *value=0; + *value = 0; value++; - xbt_assert1(strlen(name)!=0, "Invalid name for configuration: '%s'",name); - xbt_assert1(strlen(value)!=0, "Invalid value for configuration: '%s'",value); - INFO2("setting '%s' to '%s'",name,value); + xbt_assert1(strlen(name) != 0, "Invalid name for configuration: '%s'", + name); + xbt_assert1(strlen(value) != 0, + "Invalid value for configuration: '%s'", value); + INFO2("setting '%s' to '%s'", name, value); - __simix_config_helper(name,value); + __simix_config_helper(name, value); free(control_string_sav); } xbt_dynar_free(&set_strings); } -static void simix_cfg_init(int *argc,char **argv) { - int i,j; +static void simix_cfg_init(int *argc, char **argv) +{ + int i, j; char *opt; - for (i=1; i<*argc; i++){ - if (!strncmp(argv[i],"--cfg=",strlen("--cfg="))) { - opt=strchr(argv[i],'='); + for (i = 1; i < *argc; i++) { + if (!strncmp(argv[i], "--cfg=", strlen("--cfg="))) { + opt = strchr(argv[i], '='); opt++; - + simix_cfg_control_set(opt); - DEBUG1("Did apply '%s' as config setting",opt); - /*remove this from argv*/ - - for (j=i+1; j<*argc; j++){ - argv[j-1] = argv[j]; - } - - argv[j-1] = NULL; + DEBUG1("Did apply '%s' as config setting", opt); + /*remove this from argv */ + + for (j = i + 1; j < *argc; j++) { + argv[j - 1] = argv[j]; + } + + argv[j - 1] = NULL; (*argc)--; - i--; /* compensate effect of next loop incrementation */ + i--; /* compensate effect of next loop incrementation */ } } } @@ -99,66 +104,80 @@ static void simix_cfg_init(int *argc,char **argv) { */ void SIMIX_global_init(int *argc, char **argv) { - s_smx_process_t proc; + s_smx_process_t proc; - if (!simix_global) { - surf_init(argc, argv); /* Initialize some common structures. Warning, it sets simix_global=NULL */ - simix_cfg_init(argc,argv); + if (!simix_global) { + surf_init(argc, argv); /* Initialize some common structures. Warning, it sets simix_global=NULL */ + simix_cfg_init(argc, argv); - simix_global = xbt_new0(s_SIMIX_Global_t,1); + simix_global = xbt_new0(s_SIMIX_Global_t, 1); - simix_global->host = xbt_fifo_new(); - simix_global->process_to_run = xbt_swag_new(xbt_swag_offset(proc,synchro_hookup)); - simix_global->process_list = xbt_swag_new(xbt_swag_offset(proc,process_hookup)); - simix_global->current_process = NULL; - simix_global->registered_functions = xbt_dict_new(); + simix_global->host = xbt_fifo_new(); + simix_global->process_to_run = + xbt_swag_new(xbt_swag_offset(proc, synchro_hookup)); + simix_global->process_list = + xbt_swag_new(xbt_swag_offset(proc, process_hookup)); + simix_global->current_process = NULL; + simix_global->registered_functions = xbt_dict_new(); - simix_global->create_process_function = NULL; - simix_global->kill_process_function = NULL; - simix_global->cleanup_process_function = SIMIX_process_cleanup; - } + simix_global->create_process_function = NULL; + simix_global->kill_process_function = NULL; + simix_global->cleanup_process_function = SIMIX_process_cleanup; + } } /* Debug purpose, incomplete */ void SIMIX_display_process_status(void) { - smx_process_t process = NULL; - xbt_fifo_item_t item = NULL; - smx_action_t act; - int nbprocess=xbt_swag_size(simix_global->process_list); - - INFO1("%d processes are still running, waiting for something.", - nbprocess); - /* List the process and their state */ - INFO0("Legend of the following listing: \" on : .\""); - xbt_swag_foreach(process, simix_global->process_list) { - smx_simdata_process_t p_simdata = (smx_simdata_process_t) process->simdata; - // simdata_host_t h_simdata=(simdata_host_t)p_simdata->host->simdata; - char *who, *who2; - - asprintf(&who,"%s on %s: %s", - process->name, - p_simdata->s_host->name, - (process->simdata->blocked)?"[BLOCKED] " - :((process->simdata->suspended)?"[SUSPENDED] ":"")); - - if (p_simdata->mutex) { - who2=bprintf("%s Blocked on mutex %p",who,p_simdata->mutex); - free(who); who=who2; - } else if (p_simdata->cond) { - who2=bprintf("%s Blocked on condition %p; Waiting for the following actions:",who,p_simdata->cond); - free(who); who=who2; - xbt_fifo_foreach(p_simdata->cond->actions,item, act, smx_action_t) { - who2=bprintf("%s '%s'",who,act->name); - free(who); who=who2; - } - } else { - who2=bprintf("%s Blocked in an unknown status (please report this bug)",who); - free(who); who=who2; + smx_process_t process = NULL; + xbt_fifo_item_t item = NULL; + smx_action_t act; + int nbprocess = xbt_swag_size(simix_global->process_list); + + INFO1("%d processes are still running, waiting for something.", + nbprocess); + /* List the process and their state */ + INFO0 + ("Legend of the following listing: \" on : .\""); + xbt_swag_foreach(process, simix_global->process_list) { + smx_simdata_process_t p_simdata = + (smx_simdata_process_t) process->simdata; + // simdata_host_t h_simdata=(simdata_host_t)p_simdata->host->simdata; + char *who, *who2; + + asprintf(&who, "%s on %s: %s", + process->name, + p_simdata->s_host->name, + (process->simdata->blocked) ? "[BLOCKED] " + : ((process->simdata->suspended) ? "[SUSPENDED] " : "")); + + if (p_simdata->mutex) { + who2 = bprintf("%s Blocked on mutex %p", who, p_simdata->mutex); + free(who); + who = who2; + } else if (p_simdata->cond) { + who2 = + bprintf + ("%s Blocked on condition %p; Waiting for the following actions:", + who, p_simdata->cond); + free(who); + who = who2; + xbt_fifo_foreach(p_simdata->cond->actions, item, act, smx_action_t) { + who2 = bprintf("%s '%s'", who, act->name); + free(who); + who = who2; } - INFO1("%s.",who); + } else { + who2 = + bprintf + ("%s Blocked in an unknown status (please report this bug)", + who); free(who); - } + who = who2; + } + INFO1("%s.", who); + free(who); + } } /* FIXME: Yeah, I'll do it in a portable maner one day [Mt] */ @@ -166,9 +185,9 @@ void SIMIX_display_process_status(void) static void _XBT_CALL inthandler(int ignored) { - INFO0("CTRL-C pressed. Displaying status and bailing out"); - SIMIX_display_process_status(); - exit(1); + INFO0("CTRL-C pressed. Displaying status and bailing out"); + SIMIX_display_process_status(); + exit(1); } /** @@ -176,56 +195,56 @@ static void _XBT_CALL inthandler(int ignored) */ void __SIMIX_main(void) { - smx_process_t process = NULL; - smx_cond_t cond = NULL; - smx_action_t smx_action; - xbt_fifo_t actions_done = xbt_fifo_new(); - xbt_fifo_t actions_failed = xbt_fifo_new(); - - /* Prepare to display some more info when dying on Ctrl-C pressing */ - signal(SIGINT,inthandler); - - /* Clean IO before the run */ - fflush(stdout); - fflush(stderr); - - //surf_solve(); /* Takes traces into account. Returns 0.0 */ - /* xbt_fifo_size(msg_global->process_to_run) */ - - while (SIMIX_solve(actions_done, actions_failed) != -1.0) { - - while ( (smx_action = xbt_fifo_pop(actions_failed)) ) { - - xbt_fifo_item_t _cursor; - - DEBUG1("** %s failed **",smx_action->name); - xbt_fifo_foreach(smx_action->cond_list,_cursor,cond,smx_cond_t) { - xbt_swag_foreach(process,cond->sleeping) { - DEBUG2("\t preparing to wake up %s on %s", - process->name, process->simdata->s_host->name); - } - SIMIX_cond_broadcast(cond); - /* remove conditional from action */ - xbt_fifo_remove(smx_action->cond_list,cond); - } - } - - while ( (smx_action = xbt_fifo_pop(actions_done)) ) { - xbt_fifo_item_t _cursor; - - DEBUG1("** %s done **",smx_action->name); - xbt_fifo_foreach(smx_action->cond_list,_cursor,cond,smx_cond_t) { - xbt_swag_foreach(process,cond->sleeping) { - DEBUG2("\t preparing to wake up %s on %s", - process->name, process->simdata->s_host->name); - } - SIMIX_cond_broadcast(cond); - /* remove conditional from action */ - xbt_fifo_remove(smx_action->cond_list,cond); - } - } + smx_process_t process = NULL; + smx_cond_t cond = NULL; + smx_action_t smx_action; + xbt_fifo_t actions_done = xbt_fifo_new(); + xbt_fifo_t actions_failed = xbt_fifo_new(); + + /* Prepare to display some more info when dying on Ctrl-C pressing */ + signal(SIGINT, inthandler); + + /* Clean IO before the run */ + fflush(stdout); + fflush(stderr); + + //surf_solve(); /* Takes traces into account. Returns 0.0 */ + /* xbt_fifo_size(msg_global->process_to_run) */ + + while (SIMIX_solve(actions_done, actions_failed) != -1.0) { + + while ((smx_action = xbt_fifo_pop(actions_failed))) { + + xbt_fifo_item_t _cursor; + + DEBUG1("** %s failed **", smx_action->name); + xbt_fifo_foreach(smx_action->cond_list, _cursor, cond, smx_cond_t) { + xbt_swag_foreach(process, cond->sleeping) { + DEBUG2("\t preparing to wake up %s on %s", + process->name, process->simdata->s_host->name); } - return; + SIMIX_cond_broadcast(cond); + /* remove conditional from action */ + xbt_fifo_remove(smx_action->cond_list, cond); + } + } + + while ((smx_action = xbt_fifo_pop(actions_done))) { + xbt_fifo_item_t _cursor; + + DEBUG1("** %s done **", smx_action->name); + xbt_fifo_foreach(smx_action->cond_list, _cursor, cond, smx_cond_t) { + xbt_swag_foreach(process, cond->sleeping) { + DEBUG2("\t preparing to wake up %s on %s", + process->name, process->simdata->s_host->name); + } + SIMIX_cond_broadcast(cond); + /* remove conditional from action */ + xbt_fifo_remove(smx_action->cond_list, cond); + } + } + } + return; } /** @@ -237,13 +256,14 @@ void SIMIX_process_killall() smx_process_t p = NULL; smx_process_t self = SIMIX_process_self(); - 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))) { + if (p != self) + SIMIX_process_kill(p); } xbt_context_empty_trash(); - if(self) { + if (self) { xbt_context_yield(); } @@ -261,11 +281,11 @@ void SIMIX_clean(void) smx_host_t h = NULL; smx_process_t p = NULL; - while((p=xbt_swag_extract(simix_global->process_list))) { + while ((p = xbt_swag_extract(simix_global->process_list))) { SIMIX_process_kill(p); } - xbt_fifo_foreach(simix_global->host,i,h,smx_host_t) { + xbt_fifo_foreach(simix_global->host, i, h, smx_host_t) { __SIMIX_host_destroy(h); } xbt_fifo_free(simix_global->host); @@ -276,7 +296,7 @@ void SIMIX_clean(void) free(simix_global); surf_exit(); - return ; + return; } @@ -298,110 +318,115 @@ double SIMIX_get_clock(void) * \param actions_failed List of actions failed * \return The time spent to execute the simulation or -1 if the simulation ended */ -double SIMIX_solve(xbt_fifo_t actions_done, xbt_fifo_t actions_failed) +double SIMIX_solve(xbt_fifo_t actions_done, xbt_fifo_t actions_failed) { - smx_process_t process = NULL; - int i; - double elapsed_time = 0.0; - static int state_modifications = 1; - static int first = 1; + smx_process_t process = NULL; + int i; + double elapsed_time = 0.0; + static int state_modifications = 1; + static int first = 1; - xbt_context_empty_trash(); - if(xbt_swag_size(simix_global->process_to_run) && (elapsed_time>0)) { - DEBUG0("**************************************************"); - } - if (first) { - surf_solve();/* Takes traces into account. Returns 0.0 */ - first=0; - } - while ((process = xbt_swag_extract(simix_global->process_to_run))) { - DEBUG2("Scheduling %s on %s", - process->name, - process->simdata->s_host->name); - simix_global->current_process = process; - xbt_context_schedule(process->simdata->context); - /* fflush(NULL); */ - simix_global->current_process = NULL; + xbt_context_empty_trash(); + if (xbt_swag_size(simix_global->process_to_run) && (elapsed_time > 0)) { + DEBUG0("**************************************************"); + } + if (first) { + surf_solve(); /* Takes traces into account. Returns 0.0 */ + first = 0; + } + while ((process = xbt_swag_extract(simix_global->process_to_run))) { + DEBUG2("Scheduling %s on %s", + process->name, process->simdata->s_host->name); + simix_global->current_process = process; + xbt_context_schedule(process->simdata->context); + /* fflush(NULL); */ + simix_global->current_process = NULL; + } + + { + surf_action_t action = NULL; + surf_resource_t resource = NULL; + smx_action_t smx_action = NULL; + + void *fun = NULL; + void *arg = NULL; + + xbt_dynar_foreach(resource_list, i, resource) { + if (xbt_swag_size(resource->common_public->states.failed_action_set) + || xbt_swag_size(resource->common_public->states. + done_action_set)) { + state_modifications = 1; + } + } + + if (!state_modifications) { + DEBUG1("%f : Calling surf_solve", SIMIX_get_clock()); + elapsed_time = surf_solve(); + DEBUG1("Elapsed_time %f", elapsed_time); + } + + while (surf_timer_resource->extension_public->get(&fun, (void *) &arg)) { + DEBUG2("got %p %p", fun, arg); + if (fun == SIMIX_process_create) { + smx_process_arg_t args = arg; + DEBUG2("Launching %s on %s", args->name, args->hostname); + process = SIMIX_process_create(args->name, args->code, + args->data, args->hostname, + args->argc, args->argv); + if (args->kill_time > SIMIX_get_clock()) { + surf_timer_resource->extension_public->set(args->kill_time, + (void *) + &SIMIX_process_kill, + (void *) process); } + xbt_free(args); + } + if (fun == SIMIX_process_kill) { + process = arg; + DEBUG2("Killing %s on %s", process->name, + process->simdata->s_host->name); + SIMIX_process_kill(process); + } + } - { - surf_action_t action = NULL; - surf_resource_t resource = NULL; - smx_action_t smx_action = NULL; - - void *fun = NULL; - void *arg = NULL; - - xbt_dynar_foreach(resource_list, i, resource) { - if(xbt_swag_size(resource->common_public->states.failed_action_set) || - xbt_swag_size(resource->common_public->states.done_action_set)) { - state_modifications = 1; - } - } - - if(!state_modifications) { - DEBUG1("%f : Calling surf_solve",SIMIX_get_clock()); - elapsed_time = surf_solve(); - DEBUG1("Elapsed_time %f",elapsed_time); - } - - while (surf_timer_resource->extension_public->get(&fun,(void*)&arg)) { - DEBUG2("got %p %p", fun, arg); - if(fun==SIMIX_process_create) { - smx_process_arg_t args = arg; - DEBUG2("Launching %s on %s", args->name, args->hostname); - process = SIMIX_process_create(args->name, args->code, - args->data, args->hostname, - args->argc,args->argv); - if(args->kill_time > SIMIX_get_clock()) { - surf_timer_resource->extension_public->set(args->kill_time, - (void*) &SIMIX_process_kill, - (void*) process); - } - xbt_free(args); - } - if(fun==SIMIX_process_kill) { - process = arg; - DEBUG2("Killing %s on %s", process->name, - process->simdata->s_host->name); - SIMIX_process_kill(process); - } - } - - /* Wake up all process waiting for the action finish */ - xbt_dynar_foreach(resource_list, i, resource) { - while ((action = xbt_swag_extract(resource->common_public->states.failed_action_set))) { - smx_action = action->data; - if (smx_action) { - xbt_fifo_unshift(actions_failed,smx_action); - } - } - while ((action =xbt_swag_extract(resource->common_public->states.done_action_set))) { - smx_action = action->data; - if (smx_action) { - xbt_fifo_unshift(actions_done,smx_action); - } - } - } + /* Wake up all process waiting for the action finish */ + xbt_dynar_foreach(resource_list, i, resource) { + while ((action = + xbt_swag_extract(resource->common_public->states. + failed_action_set))) { + smx_action = action->data; + if (smx_action) { + xbt_fifo_unshift(actions_failed, smx_action); + } + } + while ((action = + xbt_swag_extract(resource->common_public->states. + done_action_set))) { + smx_action = action->data; + if (smx_action) { + xbt_fifo_unshift(actions_done, smx_action); } - state_modifications = 0; + } + } + } + state_modifications = 0; - if (elapsed_time == -1) { - if (xbt_swag_size(simix_global->process_list) == 0) { + if (elapsed_time == -1) { + if (xbt_swag_size(simix_global->process_list) == 0) { /* INFO0("Congratulations ! Simulation terminated : all processes are over"); */ - } else { - INFO0("Oops ! Deadlock or code not perfectly clean."); - SIMIX_display_process_status(); - if(XBT_LOG_ISENABLED(simix, xbt_log_priority_debug) || - XBT_LOG_ISENABLED(simix_kernel, xbt_log_priority_debug)) { - DEBUG0("Aborting!"); - xbt_abort(); - } - INFO0("Return a Warning."); - } - } - return elapsed_time; + } else { + INFO0("Oops ! Deadlock or code not perfectly clean."); + SIMIX_display_process_status(); + if (XBT_LOG_ISENABLED(simix, xbt_log_priority_debug) || + XBT_LOG_ISENABLED(simix_kernel, xbt_log_priority_debug)) { + DEBUG0("Aborting!"); + xbt_abort(); + } + INFO0("Return a Warning."); + } + } + return elapsed_time; } /** @@ -413,14 +438,14 @@ double SIMIX_solve(xbt_fifo_t actions_done, xbt_fifo_t actions_failed) * \param arg Parameters of the function * */ -void SIMIX_timer_set (double date, void *function, void *arg) +void SIMIX_timer_set(double date, void *function, void *arg) { - surf_timer_resource->extension_public->set(date, function, arg); + surf_timer_resource->extension_public->set(date, function, arg); } int SIMIX_timer_get(void **function, void **arg) { - return surf_timer_resource->extension_public->get(function, arg); + return surf_timer_resource->extension_public->get(function, arg); } /** @@ -430,9 +455,10 @@ int SIMIX_timer_get(void **function, void **arg) * \param function Create process function * */ -void SIMIX_function_register_process_create(smx_creation_func_t* function) +void SIMIX_function_register_process_create(smx_creation_func_t * function) { - xbt_assert0((simix_global->create_process_function == NULL), "Data already set"); + xbt_assert0((simix_global->create_process_function == NULL), + "Data already set"); simix_global->create_process_function = function; } @@ -444,9 +470,10 @@ void SIMIX_function_register_process_create(smx_creation_func_t* function) * \param function Kill process function * */ -void SIMIX_function_register_process_kill(void_f_pvoid_t* function) +void SIMIX_function_register_process_kill(void_f_pvoid_t * function) { - xbt_assert0((simix_global->kill_process_function == NULL), "Data already set"); + xbt_assert0((simix_global->kill_process_function == NULL), + "Data already set"); simix_global->kill_process_function = function; } @@ -458,7 +485,7 @@ void SIMIX_function_register_process_kill(void_f_pvoid_t* function) * \param function cleanup process function * */ -void SIMIX_function_register_process_cleanup(void_f_pvoid_t* function) +void SIMIX_function_register_process_cleanup(void_f_pvoid_t * function) { simix_global->cleanup_process_function = function; } diff --git a/src/simix/smx_host.c b/src/simix/smx_host.c index b260c3d791..7367c49478 100644 --- a/src/simix/smx_host.c +++ b/src/simix/smx_host.c @@ -15,11 +15,10 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_host, simix, /********************************* Host **************************************/ smx_host_t __SIMIX_host_create(const char *name, - void *workstation, - void *data) + void *workstation, void *data) { - smx_simdata_host_t simdata = xbt_new0(s_smx_simdata_host_t,1); - smx_host_t host = xbt_new0(s_smx_host_t,1); + smx_simdata_host_t simdata = xbt_new0(s_smx_simdata_host_t, 1); + smx_host_t host = xbt_new0(s_smx_host_t, 1); s_smx_process_t proc; /* Host structure */ @@ -29,7 +28,8 @@ smx_host_t __SIMIX_host_create(const char *name, simdata->host = workstation; - simdata->process_list = xbt_swag_new(xbt_swag_offset(proc, host_proc_hookup)); + simdata->process_list = + xbt_swag_new(xbt_swag_offset(proc, host_proc_hookup)); /* Update global variables */ xbt_fifo_unshift(simix_global->host, host); @@ -47,13 +47,13 @@ smx_host_t __SIMIX_host_create(const char *name, */ void SIMIX_host_set_data(smx_host_t host, void *data) { - xbt_assert0((host!=NULL), "Invalid parameters"); + xbt_assert0((host != NULL), "Invalid parameters"); xbt_assert0((host->data == NULL), "Data already set"); /* Assign data */ host->data = data; - return ; + return; } /** @@ -79,7 +79,8 @@ void *SIMIX_host_get_data(smx_host_t host) const char *SIMIX_host_get_name(smx_host_t host) { - xbt_assert0((host != NULL) && (host->simdata != NULL), "Invalid parameters"); + xbt_assert0((host != NULL) + && (host->simdata != NULL), "Invalid parameters"); /* Return data */ return (host->name); @@ -107,23 +108,24 @@ void __SIMIX_host_destroy(smx_host_t host) xbt_assert0((host != NULL), "Invalid parameters"); - + /* Clean Simulator data */ simdata = host->simdata; if (xbt_swag_size(simdata->process_list) != 0) { - char *msg=bprintf("Shutting down host %s, but it's not empty:", host->name); - char *tmp; - smx_process_t process = NULL; - - xbt_swag_foreach(process, simdata->process_list) { - tmp = bprintf("%s\n\t%s",msg,process->name); - free(msg); - msg=tmp; - } - THROW1(arg_error,0,"%s",msg); + char *msg = + bprintf("Shutting down host %s, but it's not empty:", host->name); + char *tmp; + smx_process_t process = NULL; + + xbt_swag_foreach(process, simdata->process_list) { + tmp = bprintf("%s\n\t%s", msg, process->name); + free(msg); + msg = tmp; + } + THROW1(arg_error, 0, "%s", msg); } - + xbt_swag_free(simdata->process_list); free(simdata); @@ -152,7 +154,7 @@ int SIMIX_host_get_number(void) */ smx_host_t *SIMIX_host_get_table(void) { - return ((smx_host_t *)xbt_fifo_to_array(simix_global->host)); + return ((smx_host_t *) xbt_fifo_to_array(simix_global->host)); } @@ -165,10 +167,10 @@ smx_host_t *SIMIX_host_get_table(void) */ double SIMIX_host_get_speed(smx_host_t host) { - xbt_assert0((host!= NULL), "Invalid parameters"); + xbt_assert0((host != NULL), "Invalid parameters"); - return(surf_workstation_resource-> - extension_public->get_speed(host->simdata->host,1.0)); + return (surf_workstation_resource-> + extension_public->get_speed(host->simdata->host, 1.0)); } /** @@ -179,10 +181,10 @@ double SIMIX_host_get_speed(smx_host_t host) */ double SIMIX_host_get_available_speed(smx_host_t host) { - xbt_assert0((host!= NULL), "Invalid parameters"); + xbt_assert0((host != NULL), "Invalid parameters"); - return(surf_workstation_resource-> - extension_public->get_available_speed(host->simdata->host)); + return (surf_workstation_resource-> + extension_public->get_available_speed(host->simdata->host)); } /** @@ -198,10 +200,12 @@ smx_host_t SIMIX_host_get_by_name(const char *name) smx_host_t host = NULL; xbt_assert0(((simix_global != NULL) - && (simix_global->host != NULL)), "Environment not set yet"); + && (simix_global->host != NULL)), + "Environment not set yet"); - xbt_fifo_foreach(simix_global->host,i,host,smx_host_t) { - if(strcmp(host->name, name) == 0) return host; + xbt_fifo_foreach(simix_global->host, i, host, smx_host_t) { + if (strcmp(host->name, name) == 0) + return host; } return NULL; } @@ -215,11 +219,9 @@ smx_host_t SIMIX_host_get_by_name(const char *name) */ int SIMIX_host_get_state(smx_host_t host) { - xbt_assert0((host!= NULL), "Invalid parameters"); + xbt_assert0((host != NULL), "Invalid parameters"); - return(surf_workstation_resource-> - extension_public->get_state(host->simdata->host)); + return (surf_workstation_resource-> + extension_public->get_state(host->simdata->host)); } - - diff --git a/src/simix/smx_process.c b/src/simix/smx_process.c index 857761675a..652e87adaa 100644 --- a/src/simix/smx_process.c +++ b/src/simix/smx_process.c @@ -1,4 +1,4 @@ -//* $Id$ */ +//* $Id$ */ /* Copyright (c) 2002,2003,2004 Arnaud Legrand. All rights reserved. */ @@ -26,7 +26,9 @@ void SIMIX_process_cleanup(void *arg) { xbt_swag_remove(arg, simix_global->process_list); xbt_swag_remove(arg, simix_global->process_to_run); - xbt_swag_remove(arg, ((smx_process_t) arg)->simdata->s_host->simdata->process_list); + xbt_swag_remove(arg, + ((smx_process_t) arg)->simdata->s_host->simdata-> + process_list); free(((smx_process_t) arg)->name); ((smx_process_t) arg)->name = NULL; @@ -51,10 +53,11 @@ void SIMIX_process_cleanup(void *arg) */ smx_process_t SIMIX_process_create(const char *name, xbt_main_func_t code, void *data, - const char * hostname, int argc, char **argv) + const char *hostname, int argc, + char **argv) { - 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_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); @@ -62,12 +65,13 @@ smx_process_t SIMIX_process_create(const char *name, /* Simulator Data */ simdata->s_host = host; - simdata->mutex = NULL; - simdata->cond = NULL; + simdata->mutex = NULL; + simdata->cond = NULL; simdata->argc = argc; simdata->argv = argv; - simdata->context = xbt_context_new(code, NULL, NULL, - simix_global->cleanup_process_function, process, + simdata->context = xbt_context_new(code, NULL, NULL, + simix_global-> + cleanup_process_function, process, simdata->argc, simdata->argv); /* Process structure */ @@ -82,10 +86,9 @@ smx_process_t SIMIX_process_create(const char *name, xbt_context_start(process->simdata->context); simix_global->current_process = self; - xbt_swag_insert(process,simix_global->process_list); - DEBUG2("Inserting %s(%s) in the to_run list",process->name, - host->name); - xbt_swag_insert(process,simix_global->process_to_run); + xbt_swag_insert(process, simix_global->process_list); + DEBUG2("Inserting %s(%s) in the to_run list", process->name, host->name); + xbt_swag_insert(process, simix_global->process_to_run); return process; } @@ -98,11 +101,10 @@ smx_process_t SIMIX_process_create(const char *name, */ void SIMIX_jprocess_create(const char *name, smx_host_t host, void *data, - void *jprocess, void *jenv, - smx_process_t *res) + void *jprocess, void *jenv, smx_process_t * res) { - 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_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; /* HACK: We need this trick because when we xbt_context_new() do @@ -115,13 +117,13 @@ void SIMIX_jprocess_create(const char *name, smx_host_t host, All this would be much simpler if the synchronization stuff would be done in the JAVA world, I think. - */ - *res= process; + */ + *res = process; DEBUG5("jprocess_create(name=%s,host=%p,data=%p,jproc=%p,jenv=%p)", - name,host,data,jprocess,jenv); + name, host, data, jprocess, jenv); xbt_assert0(host, "Invalid parameters"); /* Simulator Data */ simdata->s_host = host; @@ -129,17 +131,18 @@ void SIMIX_jprocess_create(const char *name, smx_host_t host, simdata->cond = NULL; simdata->argc = 0; simdata->argv = NULL; - - simdata->context = xbt_context_new(NULL, NULL, NULL, - simix_global->cleanup_process_function, process, - /* argc/argv*/0,NULL); + + simdata->context = xbt_context_new(NULL, NULL, NULL, + simix_global-> + cleanup_process_function, process, + /* argc/argv */ 0, NULL); /* Process structure */ process->name = xbt_strdup(name); - process->simdata = simdata; + process->simdata = simdata; process->data = data; - SIMIX_process_set_jprocess(process,jprocess); - SIMIX_process_set_jenv(process,jenv); + SIMIX_process_set_jprocess(process, jprocess); + SIMIX_process_set_jenv(process, jenv); xbt_swag_insert(process, host->simdata->process_list); @@ -148,10 +151,9 @@ void SIMIX_jprocess_create(const char *name, smx_host_t host, xbt_context_start(process->simdata->context); simix_global->current_process = self; - xbt_swag_insert(process,simix_global->process_list); - DEBUG2("Inserting %s(%s) in the to_run list",process->name, - host->name); - xbt_swag_insert(process,simix_global->process_to_run); + xbt_swag_insert(process, simix_global->process_list); + DEBUG2("Inserting %s(%s) in the to_run list", process->name, host->name); + xbt_swag_insert(process, simix_global->process_to_run); } @@ -163,34 +165,35 @@ void SIMIX_jprocess_create(const char *name, smx_host_t host, * */ void SIMIX_process_kill(smx_process_t process) -{ - smx_simdata_process_t p_simdata = process->simdata; - - DEBUG2("Killing process %s on %s",process->name, p_simdata->s_host->name); - - /* Cleanup if we were waiting for something */ - DEBUG0("Here!"); - if (p_simdata->mutex) - xbt_swag_remove(process,p_simdata->mutex->sleeping); - - DEBUG0("Here!"); - if (p_simdata->cond) - xbt_swag_remove(process,p_simdata->cond->sleeping); - - DEBUG0("Here!"); - xbt_swag_remove(process, simix_global->process_to_run); - DEBUG0("Here!"); - xbt_swag_remove(process, simix_global->process_list); - DEBUG2("%p here! killing %p",simix_global->current_process,process); - xbt_context_kill(process->simdata->context); - - DEBUG0("Here!"); - if(process==SIMIX_process_self()) { - /* I just killed myself */ - DEBUG0("Here!"); - xbt_context_yield(); - } - DEBUG0("Here!"); +{ + smx_simdata_process_t p_simdata = process->simdata; + + DEBUG2("Killing process %s on %s", process->name, + p_simdata->s_host->name); + + /* Cleanup if we were waiting for something */ + DEBUG0("Here!"); + if (p_simdata->mutex) + xbt_swag_remove(process, p_simdata->mutex->sleeping); + + DEBUG0("Here!"); + if (p_simdata->cond) + xbt_swag_remove(process, p_simdata->cond->sleeping); + + DEBUG0("Here!"); + xbt_swag_remove(process, simix_global->process_to_run); + DEBUG0("Here!"); + xbt_swag_remove(process, simix_global->process_list); + DEBUG2("%p here! killing %p", simix_global->current_process, process); + xbt_context_kill(process->simdata->context); + + DEBUG0("Here!"); + if (process == SIMIX_process_self()) { + /* I just killed myself */ + DEBUG0("Here!"); + xbt_context_yield(); + } + DEBUG0("Here!"); } /** @@ -214,14 +217,14 @@ void *SIMIX_process_get_data(smx_process_t process) * \param process SIMIX process * \param data User data */ -void SIMIX_process_set_data(smx_process_t process,void *data) +void SIMIX_process_set_data(smx_process_t process, void *data) { xbt_assert0((process != NULL), "Invalid parameters"); //xbt_assert0((process->data == NULL), "Data already set"); - + process->data = data; - - return ; + + return; } /** @@ -233,7 +236,8 @@ void SIMIX_process_set_data(smx_process_t process,void *data) */ smx_host_t SIMIX_process_get_host(smx_process_t process) { - xbt_assert0(((process != NULL) && (process->simdata)), "Invalid parameters"); + xbt_assert0(((process != NULL) + && (process->simdata)), "Invalid parameters"); return (process->simdata->s_host); } @@ -247,7 +251,8 @@ smx_host_t SIMIX_process_get_host(smx_process_t process) */ const char *SIMIX_process_get_name(smx_process_t process) { - xbt_assert0(((process != NULL) && (process->simdata)), "Invalid parameters"); + xbt_assert0(((process != NULL) + && (process->simdata)), "Invalid parameters"); return (process->name); } @@ -272,51 +277,51 @@ smx_process_t SIMIX_process_self(void) void SIMIX_process_suspend(smx_process_t process) { smx_simdata_process_t simdata = NULL; - + xbt_assert0(((process) && (process->simdata)), "Invalid parameters"); - if(process!=SIMIX_process_self()) { + if (process != SIMIX_process_self()) { simdata = process->simdata; - - if (simdata->mutex) { - /* process blocked on a mutex, only set suspend=1 */ - simdata->suspended = 1; - } - else if (simdata->cond){ - /* process blocked cond, suspend all actions */ - - /* temporaries variables */ - smx_cond_t c; - xbt_fifo_item_t i; - smx_action_t act; - - simdata->suspended = 1; - c = simdata->cond; - xbt_fifo_foreach(c->actions,i,act, smx_action_t) { - surf_workstation_resource->common_public->suspend(act->simdata->surf_action); - } - } - else { - simdata->suspended = 1; - } + + if (simdata->mutex) { + /* process blocked on a mutex, only set suspend=1 */ + simdata->suspended = 1; + } else if (simdata->cond) { + /* process blocked cond, suspend all actions */ + + /* temporaries variables */ + smx_cond_t c; + xbt_fifo_item_t i; + smx_action_t act; + + simdata->suspended = 1; + c = simdata->cond; + xbt_fifo_foreach(c->actions, i, act, smx_action_t) { + surf_workstation_resource->common_public->suspend(act->simdata-> + surf_action); + } + } else { + simdata->suspended = 1; + } + } else { + /* process executing, I can create an action and suspend it */ + process->simdata->suspended = 1; + smx_action_t dummy; + smx_cond_t cond; + char name[] = "dummy"; + + cond = SIMIX_cond_init(); + dummy = SIMIX_action_execute(SIMIX_process_get_host(process), name, 0); + surf_workstation_resource->common_public->set_priority(dummy->simdata-> + surf_action, + 0.0); + SIMIX_register_condition_to_action(dummy, cond); + SIMIX_register_action_to_condition(dummy, cond); + __SIMIX_cond_wait(cond); + //SIMIX_action_destroy(dummy); + //SIMIX_cond_destroy(cond); } - else { - /* process executing, I can create an action and suspend it */ - process->simdata->suspended = 1; - smx_action_t dummy; - smx_cond_t cond; - char name[] = "dummy"; - - cond = SIMIX_cond_init(); - dummy = SIMIX_action_execute(SIMIX_process_get_host(process), name, 0); - surf_workstation_resource->common_public->set_priority(dummy->simdata->surf_action,0.0); - SIMIX_register_condition_to_action(dummy,cond); - SIMIX_register_action_to_condition(dummy,cond); - __SIMIX_cond_wait(cond); - //SIMIX_action_destroy(dummy); - //SIMIX_cond_destroy(cond); - } - return ; + return; } /** @@ -329,36 +334,36 @@ void SIMIX_process_resume(smx_process_t process) { smx_simdata_process_t simdata = NULL; - xbt_assert0(((process != NULL) && (process->simdata)), "Invalid parameters"); + xbt_assert0(((process != NULL) + && (process->simdata)), "Invalid parameters"); SIMIX_CHECK_HOST(); - if(process == SIMIX_process_self()) { - return; + if (process == SIMIX_process_self()) { + return; } simdata = process->simdata; - if(simdata->mutex) { - DEBUG0("Resume process blocked on a mutex"); - simdata->suspended = 0; /* He'll wake up by itself */ - return; + if (simdata->mutex) { + DEBUG0("Resume process blocked on a mutex"); + simdata->suspended = 0; /* He'll wake up by itself */ + return; + } else if (simdata->cond) { + DEBUG0("Resume process blocked on a conditional"); + /* temporaries variables */ + smx_cond_t c; + xbt_fifo_item_t i; + smx_action_t act; + simdata->suspended = 0; + c = simdata->cond; + xbt_fifo_foreach(c->actions, i, act, smx_action_t) { + surf_workstation_resource->common_public->resume(act->simdata-> + surf_action); + } + return; + } else { + simdata->suspended = 0; + xbt_swag_insert(process, simix_global->process_to_run); } - else if (simdata->cond) { - DEBUG0("Resume process blocked on a conditional"); - /* temporaries variables */ - smx_cond_t c; - xbt_fifo_item_t i; - smx_action_t act; - simdata->suspended = 0; - c = simdata->cond; - xbt_fifo_foreach(c->actions,i,act, smx_action_t) { - surf_workstation_resource->common_public->resume(act->simdata->surf_action); - } - return; - } - else { - simdata->suspended = 0; - xbt_swag_insert(process,simix_global->process_to_run); - } } @@ -371,40 +376,52 @@ void SIMIX_process_resume(smx_process_t process) */ int SIMIX_process_is_suspended(smx_process_t process) { - xbt_assert0(((process != NULL) && (process->simdata)), "Invalid parameters"); + xbt_assert0(((process != NULL) + && (process->simdata)), "Invalid parameters"); return (process->simdata->suspended); } /* Helper functions for jMSG: manipulate the context data without breaking the module separation */ -#include "xbt/context.h" /* to pass java objects from MSG to the context */ +#include "xbt/context.h" /* to pass java objects from MSG to the context */ -void SIMIX_process_set_jprocess(smx_process_t process, void *jp) { - xbt_context_set_jprocess(process->simdata->context,jp); -} -void* SIMIX_process_get_jprocess(smx_process_t process) { - return xbt_context_get_jprocess(process->simdata->context); +void SIMIX_process_set_jprocess(smx_process_t process, void *jp) +{ + xbt_context_set_jprocess(process->simdata->context, jp); } -void SIMIX_process_set_jmutex(smx_process_t process, void *jm) { - xbt_context_set_jmutex(process->simdata->context,jm); +void *SIMIX_process_get_jprocess(smx_process_t process) +{ + return xbt_context_get_jprocess(process->simdata->context); } -void* SIMIX_process_get_jmutex(smx_process_t process) { - return xbt_context_get_jmutex(process->simdata->context); + +void SIMIX_process_set_jmutex(smx_process_t process, void *jm) +{ + xbt_context_set_jmutex(process->simdata->context, jm); } -void SIMIX_process_set_jcond(smx_process_t process, void *jc) { - xbt_context_set_jcond(process->simdata->context,jc); +void *SIMIX_process_get_jmutex(smx_process_t process) +{ + return xbt_context_get_jmutex(process->simdata->context); } -void* SIMIX_process_get_jcond(smx_process_t process) { - return xbt_context_get_jcond(process->simdata->context); + +void SIMIX_process_set_jcond(smx_process_t process, void *jc) +{ + xbt_context_set_jcond(process->simdata->context, jc); } -void SIMIX_process_set_jenv(smx_process_t process, void *je) { - xbt_context_set_jenv(process->simdata->context,je); +void *SIMIX_process_get_jcond(smx_process_t process) +{ + return xbt_context_get_jcond(process->simdata->context); } -void* SIMIX_process_get_jenv(smx_process_t process) { - return xbt_context_get_jenv(process->simdata->context); + +void SIMIX_process_set_jenv(smx_process_t process, void *je) +{ + xbt_context_set_jenv(process->simdata->context, je); } +void *SIMIX_process_get_jenv(smx_process_t process) +{ + return xbt_context_get_jenv(process->simdata->context); +} diff --git a/src/simix/smx_synchro.c b/src/simix/smx_synchro.c index 08d0827374..0139dee630 100644 --- a/src/simix/smx_synchro.c +++ b/src/simix/smx_synchro.c @@ -26,12 +26,12 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_synchro, simix, */ smx_mutex_t SIMIX_mutex_init() { - smx_mutex_t m = xbt_new0(s_smx_mutex_t,1); - s_smx_process_t p; /* useful to initialize sleeping swag */ - /* structures initialization */ - m->using = 0; - m->sleeping = xbt_swag_new(xbt_swag_offset(p, synchro_hookup)); - return m; + smx_mutex_t m = xbt_new0(s_smx_mutex_t, 1); + s_smx_process_t p; /* useful to initialize sleeping swag */ + /* structures initialization */ + m->using = 0; + m->sleeping = xbt_swag_new(xbt_swag_offset(p, synchro_hookup)); + return m; } /** @@ -42,30 +42,29 @@ smx_mutex_t SIMIX_mutex_init() */ void SIMIX_mutex_lock(smx_mutex_t mutex) { - smx_process_t self = SIMIX_process_self(); - xbt_assert0((mutex != NULL), "Invalid parameters"); - - - if (mutex->using) { - /* somebody using the mutex, block */ - xbt_swag_insert(self, mutex->sleeping); - self->simdata->mutex = mutex; - /* wait for some process make the unlock and wake up me from mutex->sleeping */ - xbt_context_yield(); - self->simdata->mutex = NULL; - - /* verify if the process was suspended */ - while (self->simdata->suspended) { - xbt_context_yield(); - } - - mutex->using = 1; - } - else { - /* mutex free */ - mutex->using = 1; - } - return; + smx_process_t self = SIMIX_process_self(); + xbt_assert0((mutex != NULL), "Invalid parameters"); + + + if (mutex->using) { + /* somebody using the mutex, block */ + xbt_swag_insert(self, mutex->sleeping); + self->simdata->mutex = mutex; + /* wait for some process make the unlock and wake up me from mutex->sleeping */ + xbt_context_yield(); + self->simdata->mutex = NULL; + + /* verify if the process was suspended */ + while (self->simdata->suspended) { + xbt_context_yield(); + } + + mutex->using = 1; + } else { + /* mutex free */ + mutex->using = 1; + } + return; } /** @@ -77,14 +76,14 @@ void SIMIX_mutex_lock(smx_mutex_t mutex) */ int SIMIX_mutex_trylock(smx_mutex_t mutex) { - xbt_assert0((mutex != NULL), "Invalid parameters"); - - if (mutex->using) - return 0; - else { - mutex->using = 1; - return 1; - } + xbt_assert0((mutex != NULL), "Invalid parameters"); + + if (mutex->using) + return 0; + else { + mutex->using = 1; + return 1; + } } /** @@ -95,20 +94,19 @@ int SIMIX_mutex_trylock(smx_mutex_t mutex) */ void SIMIX_mutex_unlock(smx_mutex_t mutex) { - smx_process_t p; /*process to wake up */ - - xbt_assert0((mutex != NULL), "Invalid parameters"); - - if (xbt_swag_size(mutex->sleeping) > 0) { - p = xbt_swag_extract(mutex->sleeping); - mutex->using = 0; - xbt_swag_insert(p, simix_global->process_to_run); - } - else { - /* nobody to wake up */ - mutex->using = 0; - } - return; + smx_process_t p; /*process to wake up */ + + xbt_assert0((mutex != NULL), "Invalid parameters"); + + if (xbt_swag_size(mutex->sleeping) > 0) { + p = xbt_swag_extract(mutex->sleeping); + mutex->using = 0; + xbt_swag_insert(p, simix_global->process_to_run); + } else { + /* nobody to wake up */ + mutex->using = 0; + } + return; } /** @@ -119,13 +117,13 @@ void SIMIX_mutex_unlock(smx_mutex_t mutex) */ void SIMIX_mutex_destroy(smx_mutex_t mutex) { - if ( mutex == NULL ) - return ; - else { - xbt_swag_free(mutex->sleeping); - xbt_free(mutex); - return ; - } + if (mutex == NULL) + return; + else { + xbt_swag_free(mutex->sleeping); + xbt_free(mutex); + return; + } } /******************************** Conditional *********************************/ @@ -138,13 +136,13 @@ void SIMIX_mutex_destroy(smx_mutex_t mutex) */ smx_cond_t SIMIX_cond_init() { - smx_cond_t cond = xbt_new0(s_smx_cond_t,1); - s_smx_process_t p; - - cond->sleeping = xbt_swag_new(xbt_swag_offset(p,synchro_hookup)); - cond->actions = xbt_fifo_new(); - cond->mutex = NULL; - return cond; + smx_cond_t cond = xbt_new0(s_smx_cond_t, 1); + s_smx_process_t p; + + cond->sleeping = xbt_swag_new(xbt_swag_offset(p, synchro_hookup)); + cond->actions = xbt_fifo_new(); + cond->mutex = NULL; + return cond; } /** @@ -155,16 +153,16 @@ smx_cond_t SIMIX_cond_init() */ void SIMIX_cond_signal(smx_cond_t cond) { - DEBUG1("Signal condition %p",cond); - xbt_assert0((cond != NULL), "Invalid parameters"); - smx_process_t proc = NULL; + DEBUG1("Signal condition %p", cond); + xbt_assert0((cond != NULL), "Invalid parameters"); + smx_process_t proc = NULL; - if (xbt_swag_size(cond->sleeping) >= 1) { - proc = xbt_swag_extract(cond->sleeping); - xbt_swag_insert(proc, simix_global->process_to_run); - } + if (xbt_swag_size(cond->sleeping) >= 1) { + proc = xbt_swag_extract(cond->sleeping); + xbt_swag_insert(proc, simix_global->process_to_run); + } - return; + return; } /** @@ -174,54 +172,53 @@ void SIMIX_cond_signal(smx_cond_t cond) * \param cond A condition * \param mutex A mutex */ -void SIMIX_cond_wait(smx_cond_t cond,smx_mutex_t mutex) +void SIMIX_cond_wait(smx_cond_t cond, smx_mutex_t mutex) { - smx_action_t act_sleep; - xbt_assert0((mutex != NULL), "Invalid parameters"); - - DEBUG1("Wait condition %p",cond); - cond->mutex = mutex; - - SIMIX_mutex_unlock(mutex); - /* create an action null only if there are no actions already on the condition, usefull if the host crashs */ - if (xbt_fifo_size(cond->actions) ==0 ) { - act_sleep = SIMIX_action_sleep(SIMIX_host_self(), -1); - SIMIX_register_action_to_condition(act_sleep,cond); - SIMIX_register_condition_to_action(act_sleep,cond); - __SIMIX_cond_wait(cond); - xbt_fifo_pop(act_sleep->cond_list); - SIMIX_action_destroy(act_sleep); - } - else { - __SIMIX_cond_wait(cond); - } - /* get the mutex again */ - SIMIX_mutex_lock(cond->mutex); - - return; + smx_action_t act_sleep; + xbt_assert0((mutex != NULL), "Invalid parameters"); + + DEBUG1("Wait condition %p", cond); + cond->mutex = mutex; + + SIMIX_mutex_unlock(mutex); + /* create an action null only if there are no actions already on the condition, usefull if the host crashs */ + if (xbt_fifo_size(cond->actions) == 0) { + act_sleep = SIMIX_action_sleep(SIMIX_host_self(), -1); + SIMIX_register_action_to_condition(act_sleep, cond); + SIMIX_register_condition_to_action(act_sleep, cond); + __SIMIX_cond_wait(cond); + xbt_fifo_pop(act_sleep->cond_list); + SIMIX_action_destroy(act_sleep); + } else { + __SIMIX_cond_wait(cond); + } + /* get the mutex again */ + SIMIX_mutex_lock(cond->mutex); + + return; } xbt_fifo_t SIMIX_cond_get_actions(smx_cond_t cond) { - xbt_assert0((cond != NULL), "Invalid parameters"); - return cond->actions; + xbt_assert0((cond != NULL), "Invalid parameters"); + return cond->actions; } void __SIMIX_cond_wait(smx_cond_t cond) { - smx_process_t self = SIMIX_process_self(); - xbt_assert0((cond != NULL), "Invalid parameters"); - - /* process status */ - - self->simdata->cond = cond; - xbt_swag_insert(self, cond->sleeping); - xbt_context_yield(); - self->simdata->cond = NULL; - while (self->simdata->suspended) { - xbt_context_yield(); - } - return; + smx_process_t self = SIMIX_process_self(); + xbt_assert0((cond != NULL), "Invalid parameters"); + + /* process status */ + + self->simdata->cond = cond; + xbt_swag_insert(self, cond->sleeping); + xbt_context_yield(); + self->simdata->cond = NULL; + while (self->simdata->suspended) { + xbt_context_yield(); + } + return; } @@ -233,37 +230,36 @@ void __SIMIX_cond_wait(smx_cond_t cond) * \param mutex A mutex * \param max_duration Timeout time */ -void SIMIX_cond_wait_timeout(smx_cond_t cond,smx_mutex_t mutex, double max_duration) +void SIMIX_cond_wait_timeout(smx_cond_t cond, smx_mutex_t mutex, + double max_duration) { - xbt_assert0((mutex != NULL), "Invalid parameters"); - smx_action_t act_sleep; - - DEBUG1("Timed wait condition %p",cond); - cond->mutex = mutex; - - SIMIX_mutex_unlock(mutex); - if (max_duration >=0) { - act_sleep = SIMIX_action_sleep(SIMIX_host_self(), max_duration); - SIMIX_register_action_to_condition(act_sleep,cond); - SIMIX_register_condition_to_action(act_sleep,cond); - __SIMIX_cond_wait(cond); - xbt_fifo_remove(act_sleep->cond_list,cond); - if ( SIMIX_action_get_state(act_sleep) == SURF_ACTION_DONE) { - SIMIX_action_destroy(act_sleep); - THROW0(timeout_error,0,"Condition timeout"); - } - else { - SIMIX_action_destroy(act_sleep); - } - - } - else - __SIMIX_cond_wait(cond); - - /* get the mutex again */ - SIMIX_mutex_lock(cond->mutex); - - return; + xbt_assert0((mutex != NULL), "Invalid parameters"); + smx_action_t act_sleep; + + DEBUG1("Timed wait condition %p", cond); + cond->mutex = mutex; + + SIMIX_mutex_unlock(mutex); + if (max_duration >= 0) { + act_sleep = SIMIX_action_sleep(SIMIX_host_self(), max_duration); + SIMIX_register_action_to_condition(act_sleep, cond); + SIMIX_register_condition_to_action(act_sleep, cond); + __SIMIX_cond_wait(cond); + xbt_fifo_remove(act_sleep->cond_list, cond); + if (SIMIX_action_get_state(act_sleep) == SURF_ACTION_DONE) { + SIMIX_action_destroy(act_sleep); + THROW0(timeout_error, 0, "Condition timeout"); + } else { + SIMIX_action_destroy(act_sleep); + } + + } else + __SIMIX_cond_wait(cond); + + /* get the mutex again */ + SIMIX_mutex_lock(cond->mutex); + + return; } /** @@ -274,17 +270,17 @@ void SIMIX_cond_wait_timeout(smx_cond_t cond,smx_mutex_t mutex, double max_durat */ void SIMIX_cond_broadcast(smx_cond_t cond) { - xbt_assert0((cond != NULL), "Invalid parameters"); - smx_process_t proc = NULL; - smx_process_t proc_next = NULL; + xbt_assert0((cond != NULL), "Invalid parameters"); + smx_process_t proc = NULL; + smx_process_t proc_next = NULL; - DEBUG1("Broadcast condition %p",cond); - xbt_swag_foreach_safe(proc,proc_next,cond->sleeping) { - xbt_swag_remove(proc,cond->sleeping); - xbt_swag_insert(proc, simix_global->process_to_run); - } + DEBUG1("Broadcast condition %p", cond); + xbt_swag_foreach_safe(proc, proc_next, cond->sleeping) { + xbt_swag_remove(proc, cond->sleeping); + xbt_swag_insert(proc, simix_global->process_to_run); + } - return; + return; } /** @@ -295,23 +291,24 @@ void SIMIX_cond_broadcast(smx_cond_t cond) */ void SIMIX_cond_destroy(smx_cond_t cond) { - DEBUG1("Destroy condition %p",cond); - if ( cond == NULL ) - return ; - else { - xbt_fifo_item_t item = NULL; - smx_action_t action = NULL; - - xbt_assert0( xbt_swag_size(cond->sleeping) == 0 , "Cannot destroy conditional since someone is still using it"); - xbt_swag_free(cond->sleeping); - - xbt_fifo_foreach(cond->actions,item,action,smx_action_t) { - SIMIX_unregister_condition_to_action(action, cond); - } - xbt_fifo_free(cond->actions); - xbt_free(cond); - return; - } + DEBUG1("Destroy condition %p", cond); + if (cond == NULL) + return; + else { + xbt_fifo_item_t item = NULL; + smx_action_t action = NULL; + + xbt_assert0(xbt_swag_size(cond->sleeping) == 0, + "Cannot destroy conditional since someone is still using it"); + xbt_swag_free(cond->sleeping); + + xbt_fifo_foreach(cond->actions, item, action, smx_action_t) { + SIMIX_unregister_condition_to_action(action, cond); + } + xbt_fifo_free(cond->actions); + xbt_free(cond); + return; + } } /** @@ -321,12 +318,13 @@ void SIMIX_cond_destroy(smx_cond_t cond) * \param action SIMIX action * \param cond SIMIX cond */ -void SIMIX_register_condition_to_action(smx_action_t action, smx_cond_t cond) +void SIMIX_register_condition_to_action(smx_action_t action, + smx_cond_t cond) { - xbt_assert0( (action != NULL) && (cond != NULL), "Invalid parameters"); + xbt_assert0((action != NULL) && (cond != NULL), "Invalid parameters"); - DEBUG2("Register condition %p to action %p",cond,action); - xbt_fifo_push(action->cond_list,cond); + DEBUG2("Register condition %p to action %p", cond, action); + xbt_fifo_push(action->cond_list, cond); } /** @@ -336,12 +334,11 @@ void SIMIX_register_condition_to_action(smx_action_t action, smx_cond_t cond) * \param action SIMIX action * \param cond SIMIX cond */ -void SIMIX_unregister_condition_to_action(smx_action_t action, smx_cond_t cond) +void SIMIX_unregister_condition_to_action(smx_action_t action, + smx_cond_t cond) { - xbt_assert0( (action != NULL) && (cond != NULL), "Invalid parameters"); + xbt_assert0((action != NULL) && (cond != NULL), "Invalid parameters"); - while(xbt_fifo_remove(action->cond_list,cond)) {} + while (xbt_fifo_remove(action->cond_list, cond)) { + } } - - -