X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/2a6374b4690c4acd146423676b19c66d26f45c28..32df02dabc4562d5bb8dbd0e54fb026cd6534376:/src/mc/mc_state.c diff --git a/src/mc/mc_state.c b/src/mc/mc_state.c index f6ccb79637..4137ad30f4 100644 --- a/src/mc/mc_state.c +++ b/src/mc/mc_state.c @@ -12,8 +12,8 @@ mc_state_t MC_state_new(void) mc_state_t state = NULL; state = xbt_new0(s_mc_state_t, 1); - state->interleave = xbt_setset_new_set(mc_setset); - state->done = xbt_setset_new_set(mc_setset); + state->max_pid = simix_process_maxpid; + state->interleave = xbt_new0(char, state->max_pid); mc_stats->expanded_states++; return state; @@ -25,11 +25,31 @@ mc_state_t MC_state_new(void) */ void MC_state_delete(mc_state_t state) { - xbt_setset_destroy_set(state->interleave); - xbt_setset_destroy_set(state->done); + xbt_free(state->interleave); xbt_free(state); } +void MC_state_add_to_interleave(mc_state_t state, smx_process_t process) +{ + state->interleave[process->pid] = 1; +} + +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) + size++; + } + + return size; +} + +int MC_state_process_is_done(mc_state_t state, smx_process_t process){ + return state->interleave[process->pid] == -1 ? TRUE : FALSE; +} + void MC_state_set_executed_request(mc_state_t state, smx_req_t req) { state->executed = *req; @@ -40,16 +60,31 @@ smx_req_t MC_state_get_executed_request(mc_state_t state) return &state->executed; } -smx_req_t MC_state_get_request(mc_state_t state) +smx_req_t MC_state_get_request(mc_state_t state, char *value) { - smx_process_t process = NULL; - while((process = xbt_setset_set_extract(state->interleave))){ - if(SIMIX_process_is_enabled(process) - && !xbt_setset_set_belongs(state->done, process)){ - xbt_setset_set_insert(state->done, process); - return &process->request; + unsigned int i; + smx_process_t process = NULL; + + for(i=0; i < state->max_pid; i++){ + if(state->interleave[i] > 0){ + *value = state->interleave[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]--; + + /* FIXME: SIMIX should implement a process table indexed by pid */ + /* So we should use that instead of traversing the swag */ + xbt_swag_foreach(process, simix_global->process_list){ + if(process->pid == i) + break; + } + + if(SIMIX_process_is_enabled(process)) + return &process->request; } } - + return NULL; }