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 /** Stores the context for the main model-checking system thread (call
41 * @param ctxt The system context structure
43 void set_system_context(ucontext_t *ctxt) { system_context = ctxt; }
45 /** @returns the context for the main model-checking system thread */
46 ucontext_t * get_system_context(void) { return system_context; }
48 void check_current_action(void);
50 /** Prints an execution summary with trace information. */
53 Thread * schedule_next_thread();
55 void add_thread(Thread *t);
56 void remove_thread(Thread *t);
57 Thread * get_thread(thread_id_t tid) { return thread_map->get(id_to_int(tid)); }
59 thread_id_t get_next_id();
60 int get_num_threads();
61 modelclock_t get_next_seq_num();
63 /** @return The currently executing Thread. */
64 Thread * get_current_thread() { return scheduler->get_current_thread(); }
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);
73 void finish_execution();
77 /** The scheduler to use: tracks the running/ready Threads */
81 modelclock_t used_sequence_numbers;
84 const model_params params;
87 * Stores the ModelAction for the current thread action. Call this
88 * immediately before switching from user- to system-context to pass
90 * @param act The ModelAction created by the user-thread action
92 void set_current_action(ModelAction *act) { current_action = act; }
96 ModelAction * get_last_conflict(ModelAction *act);
97 void set_backtracking(ModelAction *act);
98 thread_id_t get_next_replay_thread();
99 ModelAction * get_next_backtrack();
100 void reset_to_initial_state();
101 void resolve_promises(ModelAction *curr);
102 void compute_promises(ModelAction *curr);
104 void add_action_to_lists(ModelAction *act);
105 ModelAction * get_last_action(thread_id_t tid);
106 ModelAction * get_parent_action(thread_id_t tid);
107 ModelAction * get_last_seq_cst(const void *location);
108 void build_reads_from_past(ModelAction *curr);
109 ModelAction * process_rmw(ModelAction * curr);
110 void post_r_modification_order(ModelAction * curr, const ModelAction *rf);
111 void r_modification_order(ModelAction * curr, const ModelAction *rf);
112 void w_modification_order(ModelAction * curr);
114 ModelAction *current_action;
115 ModelAction *diverge;
116 thread_id_t nextThread;
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;
128 std::vector<ModelAction *> *thrd_last_action;
129 NodeStack *node_stack;
130 ModelAction *next_backtrack;
131 CycleGraph * cyclegraph;
135 extern ModelChecker *model;
137 #endif /* __MODEL_H__ */