From: cristianrosa Date: Wed, 5 Jan 2011 09:02:34 +0000 (+0000) Subject: Rework state's implementation to better support waitany and testany type of transitions X-Git-Tag: v3.6_beta2~572 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/4eef970157b378912a244042261347add9d3df6a Rework state's implementation to better support waitany and testany type of transitions git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@9356 48e7efb5-ca39-0410-a469-dd3cf9ba447f --- diff --git a/src/mc/mc_state.c b/src/mc/mc_state.c index 4137ad30f4..74f5a54b7d 100644 --- a/src/mc/mc_state.c +++ b/src/mc/mc_state.c @@ -13,7 +13,7 @@ mc_state_t MC_state_new(void) state = xbt_new0(s_mc_state_t, 1); state->max_pid = simix_process_maxpid; - state->interleave = xbt_new0(char, state->max_pid); + state->proc_status = xbt_new0(s_mc_procstate_t, state->max_pid); mc_stats->expanded_states++; return state; @@ -25,13 +25,14 @@ mc_state_t MC_state_new(void) */ void MC_state_delete(mc_state_t state) { - xbt_free(state->interleave); + xbt_free(state->proc_status); xbt_free(state); } void MC_state_add_to_interleave(mc_state_t state, smx_process_t process) { - state->interleave[process->pid] = 1; + state->proc_status[process->pid].state = MC_INTERLEAVE; + state->proc_status[process->pid].num_to_interleave = 1; } unsigned int MC_state_interleave_size(mc_state_t state) @@ -39,7 +40,7 @@ unsigned int MC_state_interleave_size(mc_state_t state) unsigned int i, size=0; for(i=0; i < state->max_pid; i++){ - if(state->interleave[i] != 0 && state->interleave[i] != -1) + if(state->proc_status[i].state == MC_INTERLEAVE) size++; } @@ -47,7 +48,7 @@ unsigned int MC_state_interleave_size(mc_state_t state) } int MC_state_process_is_done(mc_state_t state, smx_process_t process){ - return state->interleave[process->pid] == -1 ? TRUE : FALSE; + return state->proc_status[process->pid].state == MC_DONE ? TRUE : FALSE; } void MC_state_set_executed_request(mc_state_t state, smx_req_t req) @@ -64,15 +65,19 @@ smx_req_t MC_state_get_request(mc_state_t state, char *value) { unsigned int i; smx_process_t process = NULL; + mc_procstate_t procstate = NULL; for(i=0; i < state->max_pid; i++){ - if(state->interleave[i] > 0){ - *value = state->interleave[i]--; + procstate = &state->proc_status[i]; - /* If 0 was reached means that the process is done, so we - * set it's value to -1 (the "done" value) */ - if(state->interleave[i] == 0) - state->interleave[i]--; + if(procstate->state == MC_INTERLEAVE){ + + if(procstate->num_to_interleave-- > 1) + *value = procstate->requests_indexes[procstate->num_to_interleave]; + + /* If the are no more requests to interleave for process i then it is done */ + if(procstate->num_to_interleave == 0) + procstate->state = MC_DONE; /* FIXME: SIMIX should implement a process table indexed by pid */ /* So we should use that instead of traversing the swag */ diff --git a/src/mc/private.h b/src/mc/private.h index b5d91ac09d..a1720fdef2 100644 --- a/src/mc/private.h +++ b/src/mc/private.h @@ -59,10 +59,28 @@ void MC_dpor(void); void MC_dpor_exit(void); /******************************** States **************************************/ +/* Possible exploration status of a process in a state */ +typedef enum { + MC_NOT_INTERLEAVE = 0, /* Do not interleave (do not execute) */ + MC_INTERLEAVE, /* Interleave the process (one or more request) */ + MC_DONE /* Already interleaved */ +} e_mc_process_state_t; + +/* On every state, each process has an entry of the following type */ +typedef struct mc_procstate{ + e_mc_process_state_t state; /* Exploration control information */ + unsigned int num_to_interleave; /* Number of request to interleave */ + /* If a process has a request with multiple possible responses like a */ + /* "WaitAny", then the following vector with the indexes to interleave */ + /* is additionally used. */ + unsigned int *requests_indexes; /* Indexes of the requests to interleave */ +} s_mc_procstate_t, *mc_procstate_t; + +/* An exploration state is composed of: */ typedef struct mc_state { - char *interleave; /* processes to interleave by the mc */ - unsigned long max_pid; - s_smx_req_t executed; + unsigned long max_pid; /* Maximum pid at state's creation time */ + mc_procstate_t proc_status; /* State's exploration status by process */ + s_smx_req_t executed; /* The executed request of the state */ } s_mc_state_t, *mc_state_t; extern xbt_fifo_t mc_stack;