Fix methods
authorweiyu <weiyuluo1232@gmail.com>
Mon, 7 Oct 2019 18:55:22 +0000 (11:55 -0700)
committerweiyu <weiyuluo1232@gmail.com>
Mon, 7 Oct 2019 18:55:22 +0000 (11:55 -0700)
history.cc
history.h
newfuzzer.cc

index 93abfbc0091806410df585607958c954c68ab069..3f098a604625bbb737fd1cd1d446579b16c5919f 100644 (file)
@@ -389,17 +389,21 @@ void ModelHistory::add_waiting_thread(thread_id_t self_id,
        other_wait_obj->add_waited_by(self_id);
 }
 
-void ModelHistory::remove_waiting_thread(thread_id_t self_id, thread_id_t waiting_for_id)
+void ModelHistory::remove_waiting_thread(thread_id_t tid)
 {
-       WaitObj * self_wait_obj = getWaitObj(self_id);
-       self_wait_obj->remove_waiting_for(waiting_for_id);
+       WaitObj * self_wait_obj = getWaitObj(tid);
+       thrd_id_set_t * waiting_for = self_wait_obj->getWaitingFor();
+
+       thrd_id_set_iter * iter = waiting_for->iterator();
+       while (iter->hasNext()) {
+               thread_id_t other_id = iter->next();
+               WaitObj * other_wait_obj = getWaitObj(other_id);
+               other_wait_obj->remove_waited_by(tid);
+       }
 
-       /* Update waited-by relation */
-       WaitObj * other_wait_obj = getWaitObj(waiting_for_id);
-       other_wait_obj->remove_waited_by(self_id);
+       waiting_for->reset();
 }
 
-
 SnapVector<inst_act_map_t *> * ModelHistory::getThrdInstActMap(uint32_t func_id)
 {
        ASSERT(func_id != 0);
index 803077693e6ef8edab7ddd0f2552a1e341502708..a718510629bb96b69abb9963da3414f906d49c72 100644 (file)
--- a/history.h
+++ b/history.h
@@ -41,7 +41,7 @@ public:
 
        WaitObj * getWaitObj(thread_id_t tid);
        void add_waiting_thread(thread_id_t self_id, thread_id_t waiting_for_id, int dist);
-       void remove_waiting_thread(thread_id_t self_id, thread_id_t waiting_for_id);
+       void remove_waiting_thread(thread_id_t tid);
 
        SnapVector<inst_act_map_t *> * getThrdInstActMap(uint32_t func_id);
 
index 69f1ce148bb3c2eb70f2252c1f8cba07b7722888..b5f1cd8ec41dd9c1ce668274060a5bb89c6c2890 100644 (file)
@@ -65,8 +65,6 @@ int NewFuzzer::selectWrite(ModelAction *read, SnapVector<ModelAction *> * rf_set
 
                conditional_sleep(read_thread);
 
-               find_threads(read);
-
                return -1;
 /*
                SnapVector<ModelAction *> * pruned_writes = thrd_pruned_writes[thread_id];
@@ -229,6 +227,9 @@ void NewFuzzer::conditional_sleep(Thread * thread)
        concrete->set_location(read->get_location());
 
        history->add_waiting_write(concrete);
+
+       /* history->add_waiting_thread is called in find_threads */
+       find_threads(read);
 }
 
 bool NewFuzzer::has_paused_threads()
@@ -240,7 +241,7 @@ Thread * NewFuzzer::selectThread(int * threadlist, int numthreads)
 {
        if (numthreads == 0 && has_paused_threads()) {
                wake_up_paused_threads(threadlist, &numthreads);
-               model_print("list size: %d, active t id: %d\n", numthreads, threadlist[0]);
+               //model_print("list size: %d, active t id: %d\n", numthreads, threadlist[0]);
        }
 
        int random_index = random() % numthreads;
@@ -266,6 +267,7 @@ void NewFuzzer::wake_up_paused_threads(int * threadlist, int * numthreads)
 
        thread_id_t tid = thread->get_id();
        history->remove_waiting_write(tid);
+       history->remove_waiting_thread(tid);
 
        model_print("thread %d is woken up\n", tid);
        threadlist[*numthreads] = tid;
@@ -288,11 +290,14 @@ void NewFuzzer::notify_paused_thread(Thread * thread)
 
        thread_id_t tid = thread->get_id();
        history->remove_waiting_write(tid);
+       history->remove_waiting_thread(tid);
 }
 
 /* Find threads that may write values that the pending read action is waiting for */
 void NewFuzzer::find_threads(ModelAction * pending_read)
 {
+       ASSERT(pending_read->is_read());
+
        void * location = pending_read->get_location();
        thread_id_t self_id = pending_read->get_tid();