2 * @brief Core model checker.
15 #include "libthreads.h"
18 #include "clockvector.h"
19 #include "hashtable.h"
21 /* Forward declaration */
27 * Model checker parameter structure. Holds run-time configuration options for
33 /** @brief The central structure for model-checking */
36 ModelChecker(struct model_params params);
39 /** The scheduler to use: tracks the running/ready Threads */
42 /** Stores the context for the main model-checking system thread (call
44 * @param ctxt The system context structure
46 void set_system_context(ucontext_t *ctxt) { system_context = ctxt; }
48 /** @returns the context for the main model-checking system thread */
49 ucontext_t * get_system_context(void) { return system_context; }
51 void check_current_action(void);
53 /** Prints an execution summary with trace information. */
56 Thread * schedule_next_thread();
58 int add_thread(Thread *t);
59 void remove_thread(Thread *t);
60 Thread * get_thread(thread_id_t tid) { return thread_map->get(id_to_int(tid)); }
62 thread_id_t get_next_id();
63 int get_num_threads();
64 modelclock_t get_next_seq_num();
66 int switch_to_master(ModelAction *act);
67 ClockVector * get_cv(thread_id_t tid);
68 bool next_execution();
70 bool isfinalfeasible();
71 void check_promises(ClockVector *old_cv, ClockVector * merge_cv);
76 modelclock_t used_sequence_numbers;
79 const model_params params;
82 * Stores the ModelAction for the current thread action. Call this
83 * immediately before switching from user- to system-context to pass
85 * @param act The ModelAction created by the user-thread action
87 void set_current_action(ModelAction *act) { current_action = act; }
89 ModelAction * get_last_conflict(ModelAction *act);
90 void set_backtracking(ModelAction *act);
91 thread_id_t get_next_replay_thread();
92 ModelAction * get_next_backtrack();
93 void reset_to_initial_state();
94 void resolve_promises(ModelAction *curr);
95 void compute_promises(ModelAction *curr);
97 void add_action_to_lists(ModelAction *act);
98 ModelAction * get_last_action(thread_id_t tid);
99 ModelAction * get_parent_action(thread_id_t tid);
100 ModelAction * get_last_seq_cst(const void *location);
101 void build_reads_from_past(ModelAction *curr);
102 ModelAction * process_rmw(ModelAction * curr);
103 void post_r_modification_order(ModelAction * curr, const ModelAction *rf);
104 void r_modification_order(ModelAction * curr, const ModelAction *rf);
105 void w_modification_order(ModelAction * curr);
107 ModelAction *current_action;
108 ModelAction *diverge;
109 thread_id_t nextThread;
111 ucontext_t *system_context;
112 action_list_t *action_trace;
113 HashTable<int, Thread *, int> *thread_map;
115 /** Per-object list of actions. Maps an object (i.e., memory location)
116 * to a trace of all actions performed on the object. */
117 HashTable<const void *, action_list_t, uintptr_t, 4> *obj_map;
119 HashTable<void *, std::vector<action_list_t>, uintptr_t, 4 > *obj_thrd_map;
120 std::vector<Promise *> * promises;
121 std::vector<ModelAction *> *thrd_last_action;
122 NodeStack *node_stack;
123 ModelAction *next_backtrack;
124 CycleGraph * cyclegraph;
128 extern ModelChecker *model;
130 #endif /* __MODEL_H__ */