Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Rework state's implementation to better support waitany and testany type of transitions
[simgrid.git] / src / mc / mc_state.c
1 #include "../simix/private.h"
2 #include "xbt/fifo.h"
3 #include "private.h"
4
5 static void MC_state_add_transition(mc_state_t state, mc_transition_t trans);
6
7 /**
8  * \brief Creates a state data structure used by the exploration algorithm
9  */
10 mc_state_t MC_state_new(void)
11 {
12   mc_state_t state = NULL;
13   
14   state = xbt_new0(s_mc_state_t, 1);
15   state->max_pid = simix_process_maxpid;
16   state->proc_status = xbt_new0(s_mc_procstate_t, state->max_pid);
17   
18   mc_stats->expanded_states++;
19   return state;
20 }
21
22 /**
23  * \brief Deletes a state data structure
24  * \param trans The state to be deleted
25  */
26 void MC_state_delete(mc_state_t state)
27 {
28   xbt_free(state->proc_status);
29   xbt_free(state);
30 }
31
32 void MC_state_add_to_interleave(mc_state_t state, smx_process_t process)
33 {
34   state->proc_status[process->pid].state = MC_INTERLEAVE;
35   state->proc_status[process->pid].num_to_interleave = 1;
36 }
37
38 unsigned int MC_state_interleave_size(mc_state_t state)
39 {
40   unsigned int i, size=0;
41
42   for(i=0; i < state->max_pid; i++){
43     if(state->proc_status[i].state == MC_INTERLEAVE)
44       size++;
45   }
46
47   return size;
48 }
49
50 int MC_state_process_is_done(mc_state_t state, smx_process_t process){
51   return state->proc_status[process->pid].state == MC_DONE ? TRUE : FALSE;
52 }
53
54 void MC_state_set_executed_request(mc_state_t state, smx_req_t req)
55 {
56   state->executed = *req;
57 }
58
59 smx_req_t MC_state_get_executed_request(mc_state_t state)
60 {
61   return &state->executed;
62 }
63
64 smx_req_t MC_state_get_request(mc_state_t state, char *value)
65 {
66   unsigned int i;
67   smx_process_t process = NULL;
68   mc_procstate_t procstate = NULL;
69
70   for(i=0; i < state->max_pid; i++){
71     procstate = &state->proc_status[i];
72
73     if(procstate->state == MC_INTERLEAVE){
74
75       if(procstate->num_to_interleave-- > 1)
76         *value = procstate->requests_indexes[procstate->num_to_interleave];
77
78       /* If the are no more requests to interleave for process i then it is done */
79       if(procstate->num_to_interleave == 0)
80         procstate->state = MC_DONE;
81
82       /* FIXME: SIMIX should implement a process table indexed by pid */
83       /* So we should use that instead of traversing the swag */
84       xbt_swag_foreach(process, simix_global->process_list){
85         if(process->pid == i)
86           break;
87       }
88
89       if(SIMIX_process_is_enabled(process))
90         return &process->request;
91     }
92   }
93
94   return NULL;
95 }