model(m),
params(params),
scheduler(scheduler),
- action_trace(new action_list_t()),
- thread_map(),
+ action_trace(),
+ thread_map(2), /* We'll always need at least 2 threads */
obj_map(new HashTable<const void *, action_list_t *, uintptr_t, 4>()),
condvar_waiters_map(),
obj_thrd_map(),
{
/* Initialize a model-checker thread, for special ModelActions */
model_thread = new Thread(get_next_id());
- thread_map.put(id_to_int(model_thread->get_id()), model_thread);
+ add_thread(model_thread);
scheduler->register_engine(this);
}
ModelExecution::~ModelExecution()
{
for (unsigned int i = 0; i < get_num_threads(); i++)
- delete thread_map.get(i);
+ delete get_thread(int_to_id(i));
delete obj_map;
- delete action_trace;
for (unsigned int i = 0; i < promises.size(); i++)
delete promises[i];
return NULL;
/* Skip past the release */
- action_list_t *list = action_trace;
- action_list_t::reverse_iterator rit;
+ const action_list_t *list = &action_trace;
+ action_list_t::const_reverse_iterator rit;
for (rit = list->rbegin(); rit != list->rend(); rit++)
if (*rit == last_release)
break;
*/
bool updated = false;
if (curr->is_acquire()) {
- action_list_t *list = action_trace;
+ action_list_t *list = &action_trace;
action_list_t::reverse_iterator rit;
/* Find X : is_read(X) && X --sb-> curr */
for (rit = list->rbegin(); rit != list->rend(); rit++) {
work_queue->push_back(MOEdgeWorkEntry(acquire));
/* propagate synchronization to later actions */
- action_list_t::reverse_iterator rit = action_trace->rbegin();
+ action_list_t::reverse_iterator rit = action_trace.rbegin();
for (; (*rit) != acquire; rit++) {
ModelAction *propagate = *rit;
if (acquire->happens_before(propagate)) {
work_queue->push_back(MOEdgeWorkEntry(acquire));
/* propagate synchronization to later actions */
- action_list_t::reverse_iterator rit = action_trace->rbegin();
+ action_list_t::reverse_iterator rit = action_trace.rbegin();
for (; (*rit) != acquire; rit++) {
ModelAction *propagate = *rit;
if (acquire->happens_before(propagate)) {
}
list->push_back(act);
- action_trace->push_back(act);
+ action_trace.push_back(act);
if (uninit)
- action_trace->push_front(uninit);
+ action_trace.push_front(uninit);
SnapVector<action_list_t> *vec = get_safe_ptr_vect_action(&obj_thrd_map, act->get_location());
if (tid >= (int)vec->size())
*/
ModelAction * ModelExecution::get_last_seq_cst_fence(thread_id_t tid, const ModelAction *before_fence) const
{
- /* All fences should have NULL location */
- action_list_t *list = get_safe_ptr_action(obj_map, NULL);
+ /* All fences should have location FENCE_LOCATION */
+ action_list_t *list = get_safe_ptr_action(obj_map, FENCE_LOCATION);
action_list_t::reverse_iterator rit = list->rbegin();
if (before_fence) {
return act;
}
-static void print_list(action_list_t *list)
+static void print_list(const action_list_t *list)
{
- action_list_t::iterator it;
+ action_list_t::const_iterator it;
model_print("---------------------------------------------------------------------\n");
mo_graph->dumpNodes(file);
ModelAction **thread_array = (ModelAction **)model_calloc(1, sizeof(ModelAction *) * get_num_threads());
- for (action_list_t::iterator it = action_trace->begin(); it != action_trace->end(); it++) {
+ for (action_list_t::iterator it = action_trace.begin(); it != action_trace.end(); it++) {
ModelAction *act = *it;
if (act->is_read()) {
mo_graph->dot_print_node(file, act);
model_print("\n");
} else
print_infeasibility(" INFEASIBLE");
- print_list(action_trace);
+ print_list(&action_trace);
model_print("\n");
if (!promises.empty()) {
model_print("Pending promises:\n");
*/
void ModelExecution::add_thread(Thread *t)
{
- thread_map.put(id_to_int(t->get_id()), t);
+ unsigned int i = id_to_int(t->get_id());
+ if (i >= thread_map.size())
+ thread_map.resize(i + 1);
+ thread_map[i] = t;
if (!t->is_model_thread())
scheduler->add_thread(t);
}
*/
Thread * ModelExecution::get_thread(thread_id_t tid) const
{
- return thread_map.get(id_to_int(tid));
+ unsigned int i = id_to_int(tid);
+ if (i < thread_map.size())
+ return thread_map[i];
+ return NULL;
}
/**