Add some methods for WaitObj
authorweiyu <weiyuluo1232@gmail.com>
Sat, 5 Oct 2019 02:02:10 +0000 (19:02 -0700)
committerweiyu <weiyuluo1232@gmail.com>
Sat, 5 Oct 2019 02:02:10 +0000 (19:02 -0700)
history.cc
history.h
newfuzzer.cc
waitobj.cc
waitobj.h

index 8682da3..93abfbc 100644 (file)
@@ -378,6 +378,28 @@ WaitObj * ModelHistory::getWaitObj(thread_id_t tid)
        return (*thrd_wait_obj)[thread_id];
 }
 
+void ModelHistory::add_waiting_thread(thread_id_t self_id,
+               thread_id_t waiting_for_id, int dist)
+{
+       WaitObj * self_wait_obj = getWaitObj(self_id);
+       self_wait_obj->add_waiting_for(waiting_for_id, dist);
+
+       /* Update waited-by relation */
+       WaitObj * other_wait_obj = getWaitObj(waiting_for_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)
+{
+       WaitObj * self_wait_obj = getWaitObj(self_id);
+       self_wait_obj->remove_waiting_for(waiting_for_id);
+
+       /* Update waited-by relation */
+       WaitObj * other_wait_obj = getWaitObj(waiting_for_id);
+       other_wait_obj->remove_waited_by(self_id);
+}
+
+
 SnapVector<inst_act_map_t *> * ModelHistory::getThrdInstActMap(uint32_t func_id)
 {
        ASSERT(func_id != 0);
@@ -464,6 +486,11 @@ void ModelHistory::print_waiting_threads()
                thread_id_t tid = int_to_id(i);
                WaitObj * wait_obj = getWaitObj(tid);
                wait_obj->print_waiting_for();
+       }
+
+       for (unsigned int i = 0; i < execution->get_num_threads();i++) {
+               thread_id_t tid = int_to_id(i);
+               WaitObj * wait_obj = getWaitObj(tid);
                wait_obj->print_waited_by();
        }
 }
index 2cf93f8..8030776 100644 (file)
--- a/history.h
+++ b/history.h
@@ -38,8 +38,10 @@ public:
        void remove_waiting_write(thread_id_t tid);
        void check_waiting_write(ModelAction * write_act);
        SnapVector<ConcretePredicate *> * getThrdWaitingWrite() { return thrd_waiting_write; }
-       thrd_id_set_t * getWaitingFor(thread_id_t tid);
+
        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);
 
        SnapVector<inst_act_map_t *> * getThrdInstActMap(uint32_t func_id);
 
index 490ce04..69f1ce1 100644 (file)
@@ -295,7 +295,6 @@ void NewFuzzer::find_threads(ModelAction * pending_read)
 {
        void * location = pending_read->get_location();
        thread_id_t self_id = pending_read->get_tid();
-       HashSet<thread_id_t, int, 0> waiting_for_threads(64);
 
        SnapVector<FuncNode *> * func_node_list = history->getWrFuncNodes(location);
        for (uint i = 0; i < func_node_list->size(); i++) {
@@ -312,24 +311,13 @@ void NewFuzzer::find_threads(ModelAction * pending_read)
 
                        int distance = node->compute_distance(target_node);
                        if (distance != -1) {
-                               waiting_for_threads.add(tid);
+                               history->add_waiting_thread(self_id, tid, distance);
                                model_print("thread: %d; distance from node %d to node %d: %d\n", tid, node->get_func_id(), target_node->get_func_id(), distance);
 
                        }
 
                }
        }
-
-       /* Clear list first */
-       WaitObj * wait_obj = history->getWaitObj(self_id);
-       thrd_id_set_t * waiting_threads = wait_obj->getWaitingFor();
-       waiting_threads->reset();
-
-       HSIterator<thread_id_t, int, 0> * it = waiting_for_threads.iterator();
-       while (it->hasNext()) {
-               thread_id_t tid = it->next();
-               waiting_threads->add(tid);
-       }
 }
 
 bool NewFuzzer::shouldWait(const ModelAction * act)
index e9299f5..3aaa632 100644 (file)
@@ -7,6 +7,28 @@ WaitObj::WaitObj(thread_id_t tid) :
        dist_table(32)
 {}
 
+void WaitObj::add_waiting_for(thread_id_t other, int dist)
+{
+       waiting_for.add(other);
+       dist_table.put(other, dist);
+}
+
+void WaitObj::add_waited_by(thread_id_t other)
+{
+       waited_by.add(other);
+}
+
+void WaitObj::remove_waiting_for(thread_id_t other)
+{
+       waiting_for.remove(other);
+       dist_table.remove(other);
+}
+
+void WaitObj::remove_waited_by(thread_id_t other)
+{
+       waited_by.remove(other);
+}
+
 int WaitObj::lookup_dist(thread_id_t other_id)
 {
        if (dist_table.contains(other_id))
@@ -15,6 +37,13 @@ int WaitObj::lookup_dist(thread_id_t other_id)
        return -1;
 }
 
+void WaitObj::reset()
+{
+       waiting_for.reset();
+       waited_by.reset();
+       dist_table.reset();
+}
+
 void WaitObj::print_waiting_for()
 {
        if (waiting_for.getSize() == 0)
index 26f7f1c..ae7a5fe 100644 (file)
--- a/waitobj.h
+++ b/waitobj.h
@@ -11,10 +11,17 @@ public:
 
        thread_id_t get_tid() { return tid; }
 
+       void add_waiting_for(thread_id_t other, int dist);
+       void add_waited_by(thread_id_t other);
+       void remove_waiting_for(thread_id_t other);
+       void remove_waited_by(thread_id_t other);
+
        thrd_id_set_t * getWaitingFor() { return &waiting_for; }
        thrd_id_set_t * getWaitingBy() { return &waited_by; }
        int lookup_dist(thread_id_t other_tid);
 
+       void reset();
+
        void print_waiting_for();
        void print_waited_by();