Separate the marking algorithm and action removal algorithm
[c11tester.git] / history.cc
index f1060ca996e7949214d200e59aa0aa2c1b5a5dd0..d5179332a36e8e489a73b5248921d8535cd74a01 100644 (file)
@@ -79,7 +79,7 @@ void ModelHistory::enter_function(const uint32_t func_id, thread_id_t tid)
        }
 
        /* Monitor the statuses of threads waiting for tid */
-       monitor_waiting_thread(func_id, tid);
+       // monitor_waiting_thread(func_id, tid);
 }
 
 /* @param func_id a non-zero value */
@@ -146,7 +146,7 @@ void ModelHistory::process_action(ModelAction *act, thread_id_t tid)
                return;
 
        /* Monitor the statuses of threads waiting for tid */
-       monitor_waiting_thread_counter(tid);
+       // monitor_waiting_thread_counter(tid);
 
        /* Every write action should be processed, including
         * nonatomic writes (which have no position) */
@@ -181,7 +181,16 @@ void ModelHistory::process_action(ModelAction *act, thread_id_t tid)
                return;
 
        /* Add to curr_inst_list */
-       curr_act_list->push_back(act);
+       act->setFuncActRef(curr_act_list->add_back(act));
+       if (act->is_read()) {
+               ModelAction * rf = act->get_reads_from();
+               void * func_act_ref = rf->getFuncActRef();
+               if (func_act_ref == WRITE_REFERENCED) {
+                       // do nothing
+               } else if (func_act_ref == NULL) {
+                       rf->setFuncActRef(WRITE_REFERENCED);
+               }
+       }
 
        FuncNode * func_node = func_nodes[func_id];
        func_node->add_inst(act);
@@ -190,7 +199,7 @@ void ModelHistory::process_action(ModelAction *act, thread_id_t tid)
                func_node->update_inst_act_map(tid, act);
 
                Fuzzer * fuzzer = model->get_execution()->getFuzzer();
-               Predicate * selected_branch = fuzzer->get_selected_child_branch(tid);
+               Predicate * selected_branch = ((NewFuzzer *)fuzzer)->get_selected_child_branch(tid);
                func_node->set_predicate_tree_position(tid, selected_branch);
        }
 
@@ -200,7 +209,7 @@ void ModelHistory::process_action(ModelAction *act, thread_id_t tid)
 
                if (curr_pred) {
                        // Follow child
-                       curr_pred = curr_pred->get_single_child(curr_inst);
+                       curr_pred = curr_pred->follow_write_child(curr_inst);
                }
                func_node->set_predicate_tree_position(tid, curr_pred);
        }
@@ -363,7 +372,7 @@ void ModelHistory::check_waiting_write(ModelAction * write_act)
                        Thread * thread = model->get_thread(tid);
 
                        //model_print("** thread %d is woken up\n", thread->get_id());
-                       model->get_execution()->getFuzzer()->notify_paused_thread(thread);
+                       ((NewFuzzer *)model->get_execution()->getFuzzer())->notify_paused_thread(thread);
                }
 
                index++;
@@ -385,7 +394,7 @@ WaitObj * ModelHistory::getWaitObj(thread_id_t tid)
 }
 
 void ModelHistory::add_waiting_thread(thread_id_t self_id,
-thread_id_t waiting_for_id, FuncNode * target_node, int dist)
+                                                                                                                                                       thread_id_t waiting_for_id, FuncNode * target_node, int dist)
 {
        WaitObj * self_wait_obj = getWaitObj(self_id);
        self_wait_obj->add_waiting_for(waiting_for_id, target_node, dist);
@@ -410,10 +419,11 @@ void ModelHistory::remove_waiting_thread(thread_id_t tid)
        }
 
        self_wait_obj->clear_waiting_for();
+       delete iter;
 }
 
 void ModelHistory::stop_waiting_for_node(thread_id_t self_id,
-thread_id_t waiting_for_id, FuncNode * target_node)
+                                                                                                                                                                thread_id_t waiting_for_id, FuncNode * target_node)
 {
        WaitObj * self_wait_obj = getWaitObj(self_id);
        bool thread_removed = self_wait_obj->remove_waiting_for_node(waiting_for_id, target_node);
@@ -430,7 +440,7 @@ thread_id_t waiting_for_id, FuncNode * target_node)
                        // model_print("\tthread %d waits for nobody, wake up\n", self_id);
                        ModelExecution * execution = model->get_execution();
                        Thread * thread = execution->get_thread(self_id);
-                       execution->getFuzzer()->notify_paused_thread(thread);
+                       ((NewFuzzer *)execution->getFuzzer())->notify_paused_thread(thread);
                }
        }
 }
@@ -503,7 +513,11 @@ void ModelHistory::monitor_waiting_thread(uint32_t func_id, thread_id_t tid)
                                stop_waiting_for_node(waited_by_id, tid, target);
                        }
                }
+
+               delete node_iter;
        }
+
+       delete tid_iter;
 }
 
 void ModelHistory::monitor_waiting_thread_counter(thread_id_t tid)
@@ -528,10 +542,12 @@ void ModelHistory::monitor_waiting_thread_counter(thread_id_t tid)
                                // model_print("\tthread %d waits for nobody, wake up\n", self_id);
                                ModelExecution * execution = model->get_execution();
                                Thread * thread = execution->get_thread(waited_by_id);
-                               execution->getFuzzer()->notify_paused_thread(thread);
+                               ((NewFuzzer *)execution->getFuzzer())->notify_paused_thread(thread);
                        }
                }
        }
+
+       delete tid_iter;
 }
 
 /* Reallocate some snapshotted memories when new executions start */
@@ -565,8 +581,6 @@ void ModelHistory::print_func_node()
        /* function id starts with 1 */
        for (uint32_t i = 1;i < func_nodes.size();i++) {
                FuncNode * func_node = func_nodes[i];
-
-               func_node->assign_base_score();
                func_node->print_predicate_tree();
 
 /*