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 /** @returns the context for the main model-checking system thread */
40 ucontext_t * get_system_context() { return &system_context; }
42 void check_current_action(void);
44 /** Prints an execution summary with trace information. */
47 Thread * schedule_next_thread();
49 void add_thread(Thread *t);
50 void remove_thread(Thread *t);
51 Thread * get_thread(thread_id_t tid) { return thread_map->get(id_to_int(tid)); }
53 thread_id_t get_next_id();
54 int get_num_threads();
55 modelclock_t get_next_seq_num();
57 /** @return The currently executing Thread. */
58 Thread * get_current_thread() { return scheduler->get_current_thread(); }
60 int switch_to_master(ModelAction *act);
61 ClockVector * get_cv(thread_id_t tid);
62 bool next_execution();
64 bool isfinalfeasible();
65 void check_promises(ClockVector *old_cv, ClockVector * merge_cv);
67 void finish_execution();
71 /** The scheduler to use: tracks the running/ready Threads */
75 modelclock_t used_sequence_numbers;
78 const model_params params;
81 * Stores the ModelAction for the current thread action. Call this
82 * immediately before switching from user- to system-context to pass
84 * @param act The ModelAction created by the user-thread action
86 void set_current_action(ModelAction *act) { current_action = act; }
90 ModelAction * get_last_conflict(ModelAction *act);
91 void set_backtracking(ModelAction *act);
92 thread_id_t get_next_replay_thread();
93 ModelAction * get_next_backtrack();
94 void reset_to_initial_state();
95 void resolve_promises(ModelAction *curr);
96 void compute_promises(ModelAction *curr);
98 void add_action_to_lists(ModelAction *act);
99 ModelAction * get_last_action(thread_id_t tid);
100 ModelAction * get_parent_action(thread_id_t tid);
101 ModelAction * get_last_seq_cst(const void *location);
102 void build_reads_from_past(ModelAction *curr);
103 ModelAction * process_rmw(ModelAction * curr);
104 void post_r_modification_order(ModelAction * curr, const ModelAction *rf);
105 void r_modification_order(ModelAction * curr, const ModelAction *rf);
106 void w_modification_order(ModelAction * curr);
108 ModelAction *current_action;
109 ModelAction *diverge;
110 thread_id_t nextThread;
112 ucontext_t system_context;
113 action_list_t *action_trace;
114 HashTable<int, Thread *, int> *thread_map;
116 /** Per-object list of actions. Maps an object (i.e., memory location)
117 * to a trace of all actions performed on the object. */
118 HashTable<const void *, action_list_t, uintptr_t, 4> *obj_map;
120 HashTable<void *, std::vector<action_list_t>, uintptr_t, 4 > *obj_thrd_map;
121 std::vector<Promise *> * promises;
122 std::vector<ModelAction *> *thrd_last_action;
123 NodeStack *node_stack;
124 ModelAction *next_backtrack;
125 CycleGraph * cyclegraph;
129 extern ModelChecker *model;
131 #endif /* __MODEL_H__ */