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 /** Prints an execution summary with trace information. */
45 void add_thread(Thread *t);
46 void remove_thread(Thread *t);
47 Thread * get_thread(thread_id_t tid) { return thread_map->get(id_to_int(tid)); }
49 thread_id_t get_next_id();
50 int get_num_threads();
51 modelclock_t get_next_seq_num();
53 /** @return The currently executing Thread. */
54 Thread * get_current_thread() { return scheduler->get_current_thread(); }
56 int switch_to_master(ModelAction *act);
57 ClockVector * get_cv(thread_id_t tid);
58 ModelAction * get_parent_action(thread_id_t tid);
59 bool next_execution();
61 bool isfinalfeasible();
62 void check_promises(ClockVector *old_cv, ClockVector * merge_cv);
63 void get_release_seq_heads(ModelAction *act,
64 std::vector<const ModelAction *> *release_heads);
66 void finish_execution();
67 bool isfeasibleprefix();
68 void set_assert() {asserted=true;}
72 /** The scheduler to use: tracks the running/ready Threads */
75 bool has_asserted() {return asserted;}
76 void reset_asserted() {asserted=false;}
78 modelclock_t used_sequence_numbers;
81 const model_params params;
84 * Stores the ModelAction for the current thread action. Call this
85 * immediately before switching from user- to system-context to pass
87 * @param act The ModelAction created by the user-thread action
89 void set_current_action(ModelAction *act) { current_action = act; }
90 Thread * check_current_action(ModelAction *curr);
94 ModelAction * get_last_conflict(ModelAction *act);
95 void set_backtracking(ModelAction *act);
96 Thread * get_next_replay_thread();
97 ModelAction * get_next_backtrack();
98 void reset_to_initial_state();
99 bool resolve_promises(ModelAction *curr);
100 void compute_promises(ModelAction *curr);
102 void add_action_to_lists(ModelAction *act);
103 ModelAction * get_last_action(thread_id_t tid);
104 ModelAction * get_last_seq_cst(const void *location);
105 void build_reads_from_past(ModelAction *curr);
106 ModelAction * process_rmw(ModelAction *curr);
107 void post_r_modification_order(ModelAction *curr, const ModelAction *rf);
108 bool r_modification_order(ModelAction *curr, const ModelAction *rf);
109 bool w_modification_order(ModelAction *curr);
110 bool release_seq_head(const ModelAction *rf,
111 std::vector<const ModelAction *> *release_heads) const;
112 bool resolve_release_sequences(void *location);
114 ModelAction *current_action;
115 ModelAction *diverge;
118 ucontext_t system_context;
119 action_list_t *action_trace;
120 HashTable<int, Thread *, int> *thread_map;
122 /** Per-object list of actions. Maps an object (i.e., memory location)
123 * to a trace of all actions performed on the object. */
124 HashTable<const void *, action_list_t, uintptr_t, 4> *obj_map;
126 HashTable<void *, std::vector<action_list_t>, uintptr_t, 4 > *obj_thrd_map;
127 std::vector<Promise *> *promises;
130 * Collection of lists of objects that might synchronize with one or
131 * more release sequence. Release sequences might be determined lazily
132 * as promises are fulfilled and modification orders are established.
133 * This structure maps its lists by object location. Each ModelAction
134 * in the lists should be an acquire operation.
136 HashTable<void *, std::list<ModelAction *>, uintptr_t, 4> *lazy_sync_with_release;
138 std::vector<ModelAction *> *thrd_last_action;
139 NodeStack *node_stack;
140 ModelAction *next_backtrack;
143 * @brief The modification order graph
145 * A directed acyclic graph recording observations of the modification
146 * order on all the atomic objects in the system. This graph should
147 * never contain any cycles, as that represents a violation of the
148 * memory model (total ordering). This graph really consists of many
149 * disjoint (unconnected) subgraphs, each graph corresponding to a
150 * separate ordering on a distinct object.
152 * The edges in this graph represent the "ordered before" relation,
153 * such that <tt>a --> b</tt> means <tt>a</tt> was ordered before
156 CycleGraph *mo_graph;
161 extern ModelChecker *model;
163 #endif /* __MODEL_H__ */