fix bug
[c11tester.git] / history.cc
index 7b6e3c87fe6adfca4e5bbcd54e99203b8ec35234..60bda965dc1d40852ade46dbe538c54d4141e463 100644 (file)
@@ -14,7 +14,8 @@ ModelHistory::ModelHistory() :
        func_map(),
        func_map_rev(),
        func_nodes(),
-       write_history()
+       write_history(),
+       write_locations()
 {}
 
 void ModelHistory::enter_function(const uint32_t func_id, thread_id_t tid)
@@ -26,7 +27,11 @@ void ModelHistory::enter_function(const uint32_t func_id, thread_id_t tid)
                thrd_func_inst_lists = model->get_execution()->get_thrd_func_inst_lists();
 
        if ( thrd_func_list->size() <= id ) {
+               uint oldsize = thrd_func_list->size();
                thrd_func_list->resize( id + 1 );
+               for(uint i = oldsize; i < id + 1; i++) {
+                       new(&(*thrd_func_list)[i]) func_id_list_t();
+               }
                thrd_func_inst_lists->resize( id + 1 );
        }
 
@@ -56,7 +61,6 @@ void ModelHistory::exit_function(const uint32_t func_id, thread_id_t tid)
        uint32_t last_func_id = (*thrd_func_list)[id].back();
 
        if (last_func_id == func_id) {
-               /* clear read map upon exiting functions */
                FuncNode * func_node = func_nodes[func_id];
                func_node->clear_read_map(tid);
 
@@ -79,7 +83,7 @@ void ModelHistory::resize_func_nodes(uint32_t new_size)
        if ( old_size < new_size )
                func_nodes.resize(new_size);
 
-       for (uint32_t id = old_size; id < new_size; id++) {
+       for (uint32_t id = old_size;id < new_size;id++) {
                const char * func_name = func_map_rev[id];
                FuncNode * func_node = new FuncNode();
                func_node->set_func_id(id);
@@ -90,6 +94,11 @@ void ModelHistory::resize_func_nodes(uint32_t new_size)
 
 void ModelHistory::process_action(ModelAction *act, thread_id_t tid)
 {
+       action_type act_type = act->get_type();
+       if (act_type == THREAD_FINISH || act_type == THREAD_JOIN ||
+               act_type == PTHREAD_JOIN || act_type == THREADONLY_FINISH)
+               return;
+
        /* return if thread i has not entered any function or has exited
           from all functions */
        SnapVector<func_id_list_t> * thrd_func_list = model->get_execution()->get_thrd_func_list();
@@ -116,8 +125,8 @@ void ModelHistory::process_action(ModelAction *act, thread_id_t tid)
        if (inst == NULL)
                return;
 
-       if (inst->is_read())
-               func_node->store_read(act, tid);
+       //      if (inst->is_read())
+       //      func_node->store_read(act, tid);
 
        if (inst->is_write())
                add_to_write_history(act->get_location(), act->get_write_value());
@@ -156,28 +165,35 @@ uint64_t ModelHistory::query_last_read(void * location, thread_id_t tid)
 
 void ModelHistory::add_to_write_history(void * location, uint64_t write_val)
 {
-       if ( !write_history.contains(location) )
-               write_history.put(location, new write_set_t() );
-
        write_set_t * write_set = write_history.get(location);
+
+       if (write_set == NULL) {
+               write_set = new write_set_t();
+               write_history.put(location, write_set);
+       }
+
        write_set->add(write_val);
+       write_locations.add(location);
 }
 
-void ModelHistory::print()
+void ModelHistory::print_write()
+{
+}
+
+void ModelHistory::print_func_node()
 {
        /* function id starts with 1 */
-       for (uint32_t i = 1;i < func_nodes.size();i++) {
+       for (uint32_t i = 1; i < func_nodes.size(); i++) {
                FuncNode * func_node = func_nodes[i];
 
                func_inst_list_mt * entry_insts = func_node->get_entry_insts();
                model_print("function %s has entry actions\n", func_node->get_func_name());
 
-               func_inst_list_mt::iterator it;
-               for (it = entry_insts->begin();it != entry_insts->end();it++) {
-                       FuncInst *inst = *it;
+               mllnode<FuncInst*>* it;
+               for (it = entry_insts->begin();it != NULL;it=it->getNext()) {
+                       FuncInst *inst = it->getVal();
                        model_print("type: %d, at: %s\n", inst->get_type(), inst->get_position());
                }
-
 /*
                 func_inst_list_mt * inst_list = funcNode->get_inst_list();
 
@@ -187,6 +203,6 @@ void ModelHistory::print()
                         FuncInst *inst = *it;
                         model_print("type: %d, at: %s\n", inst->get_type(), inst->get_position());
                 }
- */
+*/
        }
 }