From: donassbr Date: Wed, 7 Mar 2007 13:38:57 +0000 (+0000) Subject: Some tests done and bugs corrected. X-Git-Tag: v3.3~2156 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/c2bf63103e5914cb2245c77d45adc47e9a302889 Some tests done and bugs corrected. Removed SIMIX_error_t. Added new privates variables in the header ( action and process ). git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@3203 48e7efb5-ca39-0410-a469-dd3cf9ba447f --- diff --git a/src/include/simix/datatypes.h b/src/include/simix/datatypes.h index 4557bfdfce..abaaf31dd6 100644 --- a/src/include/simix/datatypes.h +++ b/src/include/simix/datatypes.h @@ -92,27 +92,5 @@ typedef struct s_smx_process *smx_process_t; typedef int(*smx_process_code_t)(int argc,char *argv[]) ; /** @} */ - -/* ***************************** Error handling ***************************** */ -/** @brief Error handling - @ingroup m_datatypes_management - @{ -*/ -typedef enum { - SIMIX_OK = 0, /**< @brief Everything is right. Keep on going this way ! */ - SIMIX_WARNING, /**< @brief Mmmh! Something must be not perfectly clean. But I - may be a paranoid freak... ! */ - SIMIX_TRANSFER_FAILURE, /**< @brief There has been a problem during you action - transfer. Either the network is down or the remote host has been - shutdown. */ - SIMIX_HOST_FAILURE, /**< @brief System shutdown. The host on which you are - running has just been rebooted. Free your datastructures and - return now !*/ - SIMIX_ACTION_CANCELLED, /**< @brief Cancelled action. This action has been cancelled - by somebody!*/ - SIMIX_FATAL /**< @brief You've done something wrong. You'd better look at it... */ -} SIMIX_error_t; -/** @} */ - SG_END_DECL() #endif diff --git a/src/include/simix/simix.h b/src/include/simix/simix.h index 20a656d893..ccafb75060 100644 --- a/src/include/simix/simix.h +++ b/src/include/simix/simix.h @@ -19,8 +19,8 @@ SG_BEGIN_DECL() XBT_PUBLIC(void) SIMIX_config(const char *name, ...); XBT_PUBLIC(void) SIMIX_global_init(int *argc, char **argv); XBT_PUBLIC(void) SIMIX_global_init_args(int *argc, char **argv); -XBT_PUBLIC(SIMIX_error_t) SIMIX_main(void); -XBT_PUBLIC(SIMIX_error_t) SIMIX_clean(void); +XBT_PUBLIC(void) SIMIX_main(void); +XBT_PUBLIC(void) SIMIX_clean(void); XBT_PUBLIC(void) SIMIX_function_register(const char *name, smx_process_code_t code); XBT_PUBLIC(smx_process_code_t) SIMIX_get_registered_function(const char *name); // SIMIX_deploy_application??? @@ -30,7 +30,7 @@ XBT_PUBLIC(double) SIMIX_get_clock(void); /************************** Host handling ***********************************/ //pointer to above layer -XBT_PUBLIC(SIMIX_error_t) SIMIX_host_set_data(smx_host_t host, void *data); +XBT_PUBLIC(void) SIMIX_host_set_data(smx_host_t host, void *data); XBT_PUBLIC(void*) SIMIX_host_get_data(smx_host_t host); XBT_PUBLIC(const char *) SIMIX_host_get_name(smx_host_t host); @@ -55,21 +55,22 @@ XBT_PUBLIC(smx_process_t) SIMIX_process_create_with_arguments(const char *name, XBT_PUBLIC(void) SIMIX_process_kill(smx_process_t process); XBT_PUBLIC(void) SIMIX_process_killall(void); -XBT_PUBLIC(SIMIX_error_t) SIMIX_process_change_host(smx_process_t process, smx_host_t host); +XBT_PUBLIC(void) SIMIX_process_change_host(smx_process_t process, smx_host_t host); //above layer XBT_PUBLIC(void*) SIMIX_process_get_data(smx_process_t process); -XBT_PUBLIC(SIMIX_error_t) SIMIX_process_set_data(smx_process_t process, void *data); +XBT_PUBLIC(void) SIMIX_process_set_data(smx_process_t process, void *data); XBT_PUBLIC(smx_host_t) SIMIX_process_get_host(smx_process_t process); XBT_PUBLIC(const char *)SIMIX_process_get_name(smx_process_t process); XBT_PUBLIC(smx_process_t) SIMIX_process_self(void); -XBT_PUBLIC(SIMIX_error_t) SIMIX_process_suspend(smx_process_t process); -XBT_PUBLIC(SIMIX_error_t) SIMIX_process_resume(smx_process_t process); +XBT_PUBLIC(void) SIMIX_process_suspend(smx_process_t process); +XBT_PUBLIC(void) SIMIX_process_resume(smx_process_t process); XBT_PUBLIC(int) SIMIX_process_is_suspended(smx_process_t process); -XBT_PUBLIC(SIMIX_error_t) SIMIX_process_sleep(double nb_sec); -XBT_PUBLIC(SIMIX_error_t) SIMIX_get_errno(void); +XBT_PUBLIC(void) SIMIX_process_sleep(double nb_sec); +//XBT_PUBLIC(void) SIMIX_get_errno(void); + /************************** Synchro handling **********************************/ @@ -78,7 +79,7 @@ XBT_PUBLIC(smx_mutex_t) SIMIX_mutex_init(void); XBT_PUBLIC(void) SIMIX_mutex_lock(smx_mutex_t mutex); XBT_PUBLIC(int) SIMIX_mutex_trylock(smx_mutex_t mutex); XBT_PUBLIC(void) SIMIX_mutex_unlock(smx_mutex_t mutex); -XBT_PUBLIC(SIMIX_error_t) SIMIX_mutex_destroy(smx_mutex_t mutex); +XBT_PUBLIC(void) SIMIX_mutex_destroy(smx_mutex_t mutex); /*****Conditional*****/ XBT_PUBLIC(smx_cond_t) SIMIX_cond_init(void); @@ -86,15 +87,15 @@ XBT_PUBLIC(void) SIMIX_cond_signal(smx_cond_t cond); XBT_PUBLIC(void) SIMIX_cond_wait(smx_cond_t cond,smx_mutex_t mutex); XBT_PUBLIC(void) SIMIX_cond_wait_timeout(smx_cond_t cond,smx_mutex_t mutex, double max_duration); XBT_PUBLIC(void) SIMIX_cond_broadcast(smx_cond_t cond); -XBT_PUBLIC(SIMIX_error_t) SIMIX_cond_destroy(smx_cond_t cond); +XBT_PUBLIC(void) SIMIX_cond_destroy(smx_cond_t cond); /************************** Action handling ************************************/ XBT_PUBLIC(smx_action_t) SIMIX_communicate(smx_host_t sender,smx_host_t receiver, char *name, double size, double rate); XBT_PUBLIC(smx_action_t) SIMIX_execute(smx_host_t host,char *name, double amount); -XBT_PUBLIC(SIMIX_error_t) SIMIX_action_cancel(smx_action_t action); +XBT_PUBLIC(void) SIMIX_action_cancel(smx_action_t action); XBT_PUBLIC(void) SIMIX_action_set_priority(smx_action_t action, double priority); -XBT_PUBLIC(SIMIX_error_t) SIMIX_action_destroy(smx_action_t action); +XBT_PUBLIC(void) SIMIX_action_destroy(smx_action_t action); XBT_PUBLIC(void) SIMIX_register_action_to_condition(smx_action_t action, smx_cond_t cond); XBT_PUBLIC(void) SIMIX_register_condition_to_action(smx_action_t action, smx_cond_t cond); diff --git a/src/simix/private.h b/src/simix/private.h index 6ee5adbb0b..293b0a0700 100644 --- a/src/simix/private.h +++ b/src/simix/private.h @@ -12,7 +12,6 @@ #include "simix/simix.h" #include "surf/surf.h" #include "xbt/fifo.h" -#include "xbt/dynar.h" #include "xbt/swag.h" #include "xbt/dict.h" #include "xbt/context.h" @@ -57,7 +56,7 @@ typedef struct s_simdata_process { smx_action_t block_action; /* action that block the process when it does a mutex_lock or cond_wait */ int argc; /* arguments number if any */ char **argv; /* arguments table if any */ - SIMIX_error_t last_errno; /* the last value returned by a MSG_function */ +// SIMIX_error_t last_errno; /* the last value returned by a MSG_function */ // int paje_state; /* the number of states stacked with Paje */ } s_simdata_process_t; @@ -92,21 +91,13 @@ typedef struct s_simdata_action { surf_action_t surf_action; /* SURF modeling of computation */ xbt_fifo_t cond_list; /* conditional variables that must be signaled when the action finish. */ - smx_host_t source; -/* - double priority; - double rate; -*/ - /*int using;*/ - - /******* Parallel Tasks Only !!!! *******/ - /* - int host_nb; - void * *host_list; *//* SURF modeling */ - /* - double *comp_amount; - double *comm_amount; - */ + smx_host_t source; + +/* control needed when the action blocks a process(__SIMIX_process_block). For each process that is blocked a new action is created, the process is stocked in cond_process variable and the "boolean" action_block is marked to 1 */ + int action_block; /* simix control variable, system action or not */ + smx_process_t cond_process; /* system process will wake up */ + smx_cond_t timeout_cond; /* useful to remove the process from the sleeping list when a timeout occurs */ + } s_simdata_action_t; @@ -125,9 +116,9 @@ extern xbt_cfg_t _simix_cfg_set; -#define PROCESS_SET_ERRNO(val) (SIMIX_process_self()->simdata->last_errno=val) -#define PROCESS_GET_ERRNO() (SIMIX_process_self()->simdata->last_errno) -#define SIMIX_RETURN(val) do {PROCESS_SET_ERRNO(val);return(val);} while(0) +//#define PROCESS_SET_ERRNO(val) (SIMIX_process_self()->simdata->last_errno=val) +//#define PROCESS_GET_ERRNO() (SIMIX_process_self()->simdata->last_errno) +//#define SIMIX_RETURN(val) do {PROCESS_SET_ERRNO(val);return(val);} while(0) /* #define CHECK_ERRNO() ASSERT((PROCESS_GET_ERRNO()!=MSG_HOST_FAILURE),"Host failed, you cannot call this function.") */ #define CHECK_HOST() xbt_assert0(surf_workstation_resource->extension_public-> \ @@ -138,12 +129,12 @@ smx_host_t __SIMIX_host_create(const char *name, void *workstation, void *data); void __SIMIX_host_destroy(smx_host_t host); int __SIMIX_process_block(double max_duration); -SIMIX_error_t __SIMIX_process_unblock(smx_process_t process); +void __SIMIX_process_unblock(smx_process_t process); int __SIMIX_process_isBlocked(smx_process_t process); void __SIMIX_display_process_status(void); -SIMIX_error_t __SIMIX_wait_for_action(smx_process_t process, smx_action_t action); +void __SIMIX_wait_for_action(smx_process_t process, smx_action_t action); /* diff --git a/src/simix/smx_action.c b/src/simix/smx_action.c index dc09c63f2d..dbde45337c 100644 --- a/src/simix/smx_action.c +++ b/src/simix/smx_action.c @@ -24,8 +24,10 @@ smx_action_t SIMIX_communicate(smx_host_t sender,smx_host_t receiver,char * name simdata->cond_list = xbt_fifo_new(); /* initialize them */ - act-> name = xbt_strdup(name); - + act->name = xbt_strdup(name); + simdata->action_block=0; + simdata->cond_process=NULL; + simdata->timeout_cond = NULL; simdata->surf_action = surf_workstation_resource->extension_public-> @@ -48,6 +50,9 @@ smx_action_t SIMIX_execute(smx_host_t host, char * name, double amount) /* initialize them */ simdata->source = host; act-> name = xbt_strdup(name); + simdata->action_block=0; + simdata->cond_process=NULL; + simdata->timeout_cond = NULL; /* set communication */ simdata->surf_action = surf_workstation_resource->extension_public-> @@ -58,15 +63,14 @@ smx_action_t SIMIX_execute(smx_host_t host, char * name, double amount) return act; } -SIMIX_error_t SIMIX_action_cancel(smx_action_t action) +void SIMIX_action_cancel(smx_action_t action) { xbt_assert0((action != NULL), "Invalid parameter"); if(action->simdata->surf_action) { surf_workstation_resource->common_public->action_cancel(action->simdata->surf_action); - return SIMIX_OK; } - return SIMIX_FATAL; + return; } void SIMIX_action_set_priority(smx_action_t action, double priority) @@ -78,13 +82,13 @@ void SIMIX_action_set_priority(smx_action_t action, double priority) return; } -SIMIX_error_t SIMIX_action_destroy(smx_action_t action) +void SIMIX_action_destroy(smx_action_t action) { xbt_assert0((action != NULL), "Invalid parameter"); - xbt_assert0((xbt_fifo_size(action->simdata->cond_list)==0), - "Conditional list not empty. There is a problem. Cannot destroy it now!"); + xbt_assert1((xbt_fifo_size(action->simdata->cond_list)==0), + "Conditional list not empty %d. There is a problem. Cannot destroy it now!", xbt_fifo_size(action->simdata->cond_list)); if(action->name) free(action->name); @@ -93,7 +97,7 @@ SIMIX_error_t SIMIX_action_destroy(smx_action_t action) if(action->simdata->surf_action) action->simdata->surf_action->resource_type->common_public->action_free(action->simdata->surf_action); - return SIMIX_OK; + return; } void SIMIX_register_action_to_condition(smx_action_t action, smx_cond_t cond) @@ -103,7 +107,7 @@ void SIMIX_register_action_to_condition(smx_action_t action, smx_cond_t cond) xbt_fifo_push(cond->actions,action); } -SIMIX_error_t __SIMIX_wait_for_action(smx_process_t process, smx_action_t action) +void __SIMIX_wait_for_action(smx_process_t process, smx_action_t action) { e_surf_action_state_t state = SURF_ACTION_NOT_IN_THE_SYSTEM; simdata_action_t simdata = action->simdata; @@ -121,17 +125,15 @@ SIMIX_error_t __SIMIX_wait_for_action(smx_process_t process, smx_action_t action if(state == SURF_ACTION_DONE) { if(surf_workstation_resource->common_public->action_free(simdata->surf_action)) simdata->surf_action = NULL; - SIMIX_RETURN(SIMIX_OK); } else if(surf_workstation_resource->extension_public-> get_state(SIMIX_process_get_host(process)->simdata->host) == SURF_CPU_OFF) { if(surf_workstation_resource->common_public->action_free(simdata->surf_action)) simdata->surf_action = NULL; - SIMIX_RETURN(SIMIX_HOST_FAILURE); } else { if(surf_workstation_resource->common_public->action_free(simdata->surf_action)) simdata->surf_action = NULL; - SIMIX_RETURN(SIMIX_ACTION_CANCELLED); } + return; } diff --git a/src/simix/smx_global.c b/src/simix/smx_global.c index e8c5beecd6..c35edaf7c3 100644 --- a/src/simix/smx_global.c +++ b/src/simix/smx_global.c @@ -49,7 +49,7 @@ void SIMIX_global_init(int *argc, char **argv) xbt_context_init(); simix_global->host = xbt_fifo_new(); - simix_global->process_to_run = xbt_swag_new(xbt_swag_offset(proc,process_hookup)); + 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(); @@ -96,7 +96,7 @@ static void _XBT_CALL inthandler(int ignored) /** \ingroup msg_simulation * \brief Launch the SIMIX simulation */ -SIMIX_error_t SIMIX_main(void) +void SIMIX_main(void) { smx_process_t process = NULL; smx_cond_t cond = NULL; @@ -191,11 +191,20 @@ SIMIX_error_t SIMIX_main(void) xbt_fifo_item_t _cursor; DEBUG1("** %s failed **",smx_action->name); - xbt_fifo_foreach(smx_action->simdata->cond_list,_cursor,cond,smx_cond_t) { - SIMIX_cond_broadcast(cond); - xbt_swag_foreach(process,cond->sleeping) { - DEBUG2("\t preparing to wake up %s on %s", - process->name, process->simdata->host->name); + /* put all the process that are waiting in a conditional (dummy action) on the process_to_run list */ + if ( smx_action->simdata->action_block) { + xbt_swag_insert(smx_action->simdata->cond_process,simix_global->process_to_run); + } + /* else, do the dummy action finish, call the signal broadcast */ + else { + xbt_fifo_foreach(smx_action->simdata->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->host->name); + } + SIMIX_cond_broadcast(cond); + /* remove conditional from action */ + xbt_fifo_remove(smx_action->simdata->cond_list,cond); } } process=NULL; @@ -205,6 +214,35 @@ SIMIX_error_t SIMIX_main(void) xbt_swag_extract(resource->common_public->states. done_action_set))) { smx_action = action->data; + if (smx_action) { + xbt_fifo_item_t _cursor; + + DEBUG1("** %s done **",smx_action->name); + /* put all the process that are waiting in a conditional (dummy action) on the process_to_run list */ + if ( smx_action->simdata->action_block) { + if (smx_action->simdata->timeout_cond) { + xbt_swag_remove(smx_action->simdata->cond_process,smx_action->simdata->timeout_cond->sleeping); + } + process = smx_action->simdata->cond_process; + xbt_swag_insert(smx_action->simdata->cond_process,simix_global->process_to_run); + DEBUG2("\t preparing to wake up %s on %s", + process->name, process->simdata->host->name); + } + /* else, do the dummy action finish, call the signal broadcast */ + else { + xbt_fifo_foreach(smx_action->simdata->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->host->name); + } + SIMIX_cond_broadcast(cond); + /* remove conditional from action */ + xbt_fifo_remove(smx_action->simdata->cond_list,cond); + } + } + process=NULL; + } +/* if (smx_action) { xbt_fifo_item_t _cursor; @@ -217,7 +255,7 @@ SIMIX_error_t SIMIX_main(void) } } process=NULL; - } + }*/ } } @@ -227,7 +265,7 @@ SIMIX_error_t SIMIX_main(void) if (xbt_swag_size(simix_global->process_list) == 0) { INFO0("Congratulations ! Simulation terminated : all processes are over"); - return SIMIX_OK; + return; } else { INFO0("Oops ! Deadlock or code not perfectly clean."); __SIMIX_display_process_status(); @@ -238,7 +276,7 @@ SIMIX_error_t SIMIX_main(void) } INFO0("Return a Warning."); - return SIMIX_WARNING; + return; } } @@ -270,7 +308,7 @@ void SIMIX_process_killall() /** \ingroup msg_simulation * \brief Clean the SIMIX simulation */ -SIMIX_error_t SIMIX_clean(void) +void SIMIX_clean(void) { xbt_fifo_item_t i = NULL; smx_host_t h = NULL; @@ -293,7 +331,7 @@ SIMIX_error_t SIMIX_clean(void) free(simix_global); surf_exit(); - return SIMIX_OK; + return ; } diff --git a/src/simix/smx_host.c b/src/simix/smx_host.c index b1f1b7912f..d700fef4b2 100644 --- a/src/simix/smx_host.c +++ b/src/simix/smx_host.c @@ -56,7 +56,7 @@ smx_host_t __SIMIX_host_create(const char *name, * This functions checks whether some data has already been associated to \a host or not and attach \a data to \a host if it is possible. */ -SIMIX_error_t SIMIX_host_set_data(smx_host_t host, void *data) +void SIMIX_host_set_data(smx_host_t host, void *data) { xbt_assert0((host!=NULL), "Invalid parameters"); xbt_assert0((host->data == NULL), "Data already set"); @@ -64,7 +64,7 @@ SIMIX_error_t SIMIX_host_set_data(smx_host_t host, void *data) /* Assign data */ host->data = data; - return SIMIX_OK; + return ; } /** \ingroup m_host_management diff --git a/src/simix/smx_process.c b/src/simix/smx_process.c index 25c580125b..08f6c8ce22 100644 --- a/src/simix/smx_process.c +++ b/src/simix/smx_process.c @@ -91,7 +91,7 @@ smx_process_t SIMIX_process_create_with_arguments(const char *name, SIMIX_process_cleanup, process, simdata->argc, simdata->argv); - simdata->last_errno=SIMIX_OK; + //simdata->last_errno=SIMIX_OK; /* Process structure */ @@ -106,7 +106,7 @@ smx_process_t SIMIX_process_create_with_arguments(const char *name, xbt_context_start(process->simdata->context); simix_global->current_process = self; - // xbt_swag_insert(process,simix_global->process_list); + 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); @@ -170,7 +170,7 @@ void SIMIX_process_kill(smx_process_t process) * This functions checks whether \a process and \a host are valid pointers and change the value of the #m_host_t on which \a process is running. */ -SIMIX_error_t SIMIX_process_change_host(smx_process_t process, smx_host_t host) +void SIMIX_process_change_host(smx_process_t process, smx_host_t host) { simdata_process_t simdata = NULL; @@ -184,7 +184,7 @@ SIMIX_error_t SIMIX_process_change_host(smx_process_t process, smx_host_t host) simdata->host = host; xbt_swag_insert(process,host->simdata->process_list); - return SIMIX_OK; + return ; } /** \ingroup m_process_management @@ -206,14 +206,14 @@ void *SIMIX_process_get_data(smx_process_t process) * This functions checks whether \a process is a valid pointer or not and set the user data associated to \a process if it is possible. */ -SIMIX_error_t 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 SIMIX_OK; + return ; } /** \ingroup m_process_management @@ -227,7 +227,7 @@ smx_host_t SIMIX_process_get_host(smx_process_t process) { xbt_assert0(((process != NULL) && (process->simdata)), "Invalid parameters"); - return (((simdata_process_t) process->simdata)->host); + return (process->simdata->host); } /** \ingroup m_process_management @@ -259,28 +259,22 @@ smx_process_t SIMIX_process_self(void) * This functions suspend the process by suspending the task on which * it was waiting for the completion. */ -SIMIX_error_t SIMIX_process_suspend(smx_process_t process) +void SIMIX_process_suspend(smx_process_t process) { simdata_process_t simdata = NULL; - smx_action_t dummy; - char name[] = "dummy"; xbt_assert0(((process) && (process->simdata)), "Invalid parameters"); if(process!=SIMIX_process_self()) { simdata = process->simdata; - if ( (simdata->mutex == NULL) && (simdata->cond == NULL) ) { - /* Ops, I don't know what to do yet. */ - - } - else if (simdata->mutex) { + 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; @@ -289,25 +283,23 @@ SIMIX_error_t SIMIX_process_suspend(smx_process_t process) 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); + surf_workstation_resource->common_public->suspend(act->simdata->surf_action); } } + else if (simdata->block_action) { + simdata->suspended = 1; + } else xbt_assert0(0, "Unknown process status"); } else { /* process executing, I can create an action and suspend it */ - dummy = SIMIX_execute(SIMIX_process_get_host(process)->simdata->host, name, 0); - process->simdata->block_action = dummy; - process->simdata->suspended = 1; - surf_workstation_resource->common_public->suspend(dummy->simdata->surf_action); - __SIMIX_wait_for_action(process,dummy); - SIMIX_action_destroy(dummy); + __SIMIX_process_block(-1); process->simdata->suspended = 0; } - return SIMIX_OK; + return ; } /** \ingroup m_process_management @@ -316,7 +308,7 @@ SIMIX_error_t SIMIX_process_suspend(smx_process_t process) * This functions resume a suspended process by resuming the task on * which it was waiting for the completion. */ -SIMIX_error_t SIMIX_process_resume(smx_process_t process) +void SIMIX_process_resume(smx_process_t process) { simdata_process_t simdata = NULL; @@ -324,34 +316,34 @@ SIMIX_error_t SIMIX_process_resume(smx_process_t process) CHECK_HOST(); if(process == SIMIX_process_self()) { - SIMIX_RETURN(SIMIX_OK); + return; } simdata = process->simdata; - if(simdata->mutex) { + DEBUG0("Resume process blocked on a mutex"); simdata->suspended = 0; /* He'll wake up by itself */ - SIMIX_RETURN(SIMIX_OK); + 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); } - SIMIX_RETURN(SIMIX_OK); + return; } else if (simdata->block_action){ simdata->suspended = 0; surf_workstation_resource->common_public->resume(simdata->block_action->simdata->surf_action); - SIMIX_RETURN(SIMIX_OK); + return; } - else xbt_assert0(0, "Unknown process status"); + else xbt_assert0(0, "Unknown status"); } @@ -375,15 +367,23 @@ int __SIMIX_process_block(double max_duration) smx_action_t dummy = NULL; char name[] = "dummy"; - dummy = SIMIX_execute(SIMIX_process_get_host(process)->simdata->host, name, 0); - process->simdata->block_action = dummy; + dummy = SIMIX_execute(SIMIX_process_get_host(process), name, 0); + dummy->simdata->action_block=1; + + /* process which will wake up when this system action finish */ + dummy->simdata->cond_process = process; + + process->simdata->block_action = dummy; process->simdata->blocked=1; surf_workstation_resource->common_public->suspend(dummy->simdata->surf_action); - if(max_duration>=0) + + if(max_duration>=0) { surf_workstation_resource->common_public->set_max_duration(dummy->simdata->surf_action, max_duration); + dummy->simdata->timeout_cond = process->simdata->cond; + } __SIMIX_wait_for_action(process,dummy); SIMIX_action_destroy(dummy); process->simdata->blocked=0; @@ -394,58 +394,27 @@ int __SIMIX_process_block(double max_duration) DEBUG0("I've been resumed, let's keep going"); } -/* - m_task_t dummy = SIMIX_TASK_UNINITIALIZED; - char blocked_name[512]; - snprintf(blocked_name,512,"blocked [%s] (%s:%s)", - info, process->name, process->simdata->host->name); - - XBT_IN1(": max_duration=%g",max_duration); - - dummy = MSG_task_create(blocked_name, 0.0, 0, NULL); - - PAJE_PROCESS_PUSH_STATE(process,"B",NULL); - - process->simdata->blocked=1; - __MSG_task_execute(process,dummy); - surf_workstation_resource->common_public->suspend(dummy->simdata->compute); - if(max_duration>=0) - surf_workstation_resource->common_public->set_max_duration(dummy->simdata->compute, - max_duration); - __MSG_wait_for_computation(process,dummy); - MSG_task_destroy(dummy); - process->simdata->blocked=0; - - if(process->simdata->suspended) { - DEBUG0("I've been suspended in the meantime"); - SIMIX_process_suspend(process); - DEBUG0("I've been resumed, let's keep going"); - } - - PAJE_PROCESS_POP_STATE(process); - - XBT_OUT; - */ return 1; } -SIMIX_error_t __SIMIX_process_unblock(smx_process_t process) +void __SIMIX_process_unblock(smx_process_t process) { simdata_process_t simdata = NULL; simdata_action_t simdata_action = NULL; xbt_assert0(((process != NULL) && (process->simdata)), "Invalid parameters"); - CHECK_HOST(); - simdata = process->simdata; + simdata = process->simdata; + if(!(simdata->block_action)) { xbt_assert0(0,"Process is not blocked !"); - return SIMIX_WARNING; + return; } - simdata_action = simdata->block_action->simdata; + + simdata_action = simdata->block_action->simdata; xbt_assert0(simdata->blocked,"Process not blocked"); surf_workstation_resource->common_public->resume(simdata_action->surf_action); - SIMIX_RETURN(SIMIX_OK); + return ; /* simdata_process_t simdata = NULL; diff --git a/src/simix/smx_synchro.c b/src/simix/smx_synchro.c index fa4d4d9cda..9e067c7a71 100644 --- a/src/simix/smx_synchro.c +++ b/src/simix/smx_synchro.c @@ -78,14 +78,14 @@ void SIMIX_mutex_unlock(smx_mutex_t mutex) return; } -SIMIX_error_t SIMIX_mutex_destroy(smx_mutex_t mutex) +void SIMIX_mutex_destroy(smx_mutex_t mutex) { if ( mutex == NULL ) - return SIMIX_WARNING; + return ; else { xbt_swag_free(mutex->sleeping); xbt_free(mutex); - return SIMIX_OK; + return ; } } @@ -131,11 +131,11 @@ void SIMIX_cond_wait_timeout(smx_cond_t cond,smx_mutex_t mutex, double max_durat /* process status */ self->simdata->cond = cond; - xbt_swag_insert(self, cond->sleeping); cond->mutex = mutex; SIMIX_mutex_unlock(mutex); - /* if the max_duration < 0, blocks forever */ + xbt_swag_insert(self, cond->sleeping); + /* creates a new action to be the timeout */ if (max_duration >=0) { __SIMIX_process_block(max_duration); self->simdata->cond = NULL; @@ -146,6 +146,7 @@ void SIMIX_cond_wait_timeout(smx_cond_t cond,smx_mutex_t mutex, double max_durat } /* get the mutex again */ SIMIX_mutex_lock(cond->mutex); + return; } @@ -164,19 +165,18 @@ void SIMIX_cond_broadcast(smx_cond_t cond) return; } -SIMIX_error_t SIMIX_cond_destroy(smx_cond_t cond) +void SIMIX_cond_destroy(smx_cond_t cond) { if ( cond == NULL ) - return SIMIX_WARNING; + return ; else { - xbt_assert0( (xbt_swag_size(cond->sleeping) > 0) && - (xbt_fifo_size(cond->actions) > 0), "Cannot destroy conditional"); + xbt_assert0( xbt_swag_size(cond->sleeping) == 0 , "Cannot destroy conditional"); xbt_swag_free(cond->sleeping); xbt_fifo_free(cond->actions); xbt_free(cond); - return SIMIX_OK; + return; } }