Some edits
authorweiyu <weiyuluo1232@gmail.com>
Wed, 9 Oct 2019 22:09:42 +0000 (15:09 -0700)
committerweiyu <weiyuluo1232@gmail.com>
Wed, 9 Oct 2019 22:09:42 +0000 (15:09 -0700)
hashtable.h
history.cc
waitobj.cc
waitobj.h

index c9da5aad4341883bba7225f3bc97f1f2bd04fc9f..4758999a6a4f23148446a5f0cf6376480fa4910c 100644 (file)
@@ -284,6 +284,9 @@ public:
                return size;
        }
 
+       bool isEmpty() {
+               return size == 0;
+       }
 
        /**
         * @brief Check whether the table contains a value for the given key
index 9969c016a35927531ea03647fffa885ca659fc0d..2ad4c1a90c53b33f959d8830213b81019b5e685e 100644 (file)
@@ -153,8 +153,6 @@ void ModelHistory::process_action(ModelAction *act, thread_id_t tid)
                thrd_func_act_lists = execution->get_thrd_func_act_lists();
 
        uint32_t thread_id = id_to_int(tid);
-       uint32_t func_id = (*thrd_func_list)[thread_id].back();
-
        /* Return if thread tid has not entered any function that contains atomics */
        if ( thrd_func_list->size() <= thread_id )
                return;
@@ -179,23 +177,25 @@ void ModelHistory::process_action(ModelAction *act, thread_id_t tid)
                check_waiting_write(act);
        }
 
+       uint32_t func_id = (*thrd_func_list)[thread_id].back();
+
        /* The following does not care about actions that are not inside
         * any function that contains atomics or actions without a position */
        if (func_id == 0 || act->get_position() == NULL)
                return;
 
        SnapList<action_list_t *> * func_act_lists = (*thrd_func_act_lists)[thread_id];
+
        /* The list of actions that thread tid has taken in its current function */
        action_list_t * curr_act_list = func_act_lists->back();
-       ASSERT(curr_act_list != NULL);
 
        if (skip_action(act, curr_act_list))
                return;
 
-       FuncNode * func_node = func_nodes[func_id];
-
        /* Add to curr_inst_list */
        curr_act_list->push_back(act);
+
+       FuncNode * func_node = func_nodes[func_id];
        func_node->add_inst(act);
 
        if (act->is_read()) {
@@ -460,6 +460,8 @@ SnapVector<inst_act_map_t *> * ModelHistory::getThrdInstActMap(uint32_t func_id)
 
 bool ModelHistory::skip_action(ModelAction * act, SnapList<ModelAction *> * curr_act_list)
 {
+       ASSERT(curr_act_list != NULL);
+
        bool second_part_of_rmw = act->is_rmwc() || act->is_rmw();
        modelclock_t curr_seq_number = act->get_seq_number();
 
@@ -514,7 +516,7 @@ void ModelHistory::monitor_waiting_thread(uint32_t func_id, thread_id_t tid)
        }
 }
 
-void monitor_waiting_thread_counter(thread_id_t tid)
+void ModelHistory::monitor_waiting_thread_counter(thread_id_t tid)
 {
        WaitObj * wait_obj = getWaitObj(tid);
        thrd_id_set_t * waited_by = wait_obj->getWaitedBy();
@@ -528,8 +530,16 @@ void monitor_waiting_thread_counter(thread_id_t tid)
 
                bool expire = other_wait_obj->incr_counter(tid);
                if (expire) {
-                       // TODO: complete
-                       expire_threads.push_back(tid);
+                       wait_obj->remove_waited_by(waited_by_id);
+                       other_wait_obj->remove_waiting_for(tid);
+
+                       thrd_id_set_t * other_waiting_for = other_wait_obj->getWaitingFor();
+                       if ( other_waiting_for->isEmpty() ) {
+                               // 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);
+                       }
                }
        }
 }
index 5a1bc12f1f3c68f0bda956fd2557c85a69e47fe9..692f0203fb2e1577c4b49efeefc78a64b4aefabc 100644 (file)
@@ -54,7 +54,10 @@ bool WaitObj::remove_waiting_for_node(thread_id_t other, FuncNode * node)
 
        /* The thread has no nodes to reach */
        if (target_nodes->isEmpty()) {
+               int index = id_to_int(other);
+               thrd_action_counters[index] = 0;
                waiting_for.remove(other);
+
                return true;
        }
 
@@ -64,11 +67,17 @@ bool WaitObj::remove_waiting_for_node(thread_id_t other, FuncNode * node)
 /* Stop waiting for the thread */
 void WaitObj::remove_waiting_for(thread_id_t other)
 {
-       // TODO: clear dist_map or not?
        waiting_for.remove(other);
 
+       // TODO: clear dist_map or not?
+       /* dist_map_t * dist_map = getDistMap(other);
+          dist_map->reset(); */
+
        node_set_t * target_nodes = getTargetNodes(other);
        target_nodes->reset();
+
+       int index = id_to_int(other);
+       thrd_action_counters[index] = 0;
 }
 
 void WaitObj::remove_waited_by(thread_id_t other)
@@ -119,24 +128,6 @@ node_set_t * WaitObj::getTargetNodes(thread_id_t tid)
        return thrd_target_nodes[thread_id];
 }
 
-/*
-SnapVector<thread_id_t> WaitObj::incr_waiting_for_counter()
-{
-       SnapVector<thread_id_t> expire_thrds;
-
-       thrd_id_set_iter * iter = waiting_for.iterator();
-       while (iter->hasNext()) {
-               thread_id_t waiting_for_id = iter->next();
-               bool expire = incr_counter(waiting_for_id);
-
-               if (expire) {
-                       expire_thrds.push_back(waiting_for_id);
-               }
-       }
-
-       return expire_thrds;
-}*/
-
 /**
  * Increment action counter for thread tid
  * @return true if the counter for tid expires
@@ -151,7 +142,6 @@ bool WaitObj::incr_counter(thread_id_t tid)
        }
 
        thrd_action_counters[thread_id]++;
-
        if (thrd_action_counters[thread_id] > 1000)
                return true;
 
@@ -164,9 +154,14 @@ void WaitObj::clear_waiting_for()
        while (iter->hasNext()) {
                thread_id_t tid = iter->next();
                int index = id_to_int(tid);
-               thrd_target_nodes[index]->reset();
+               thrd_action_counters[index] = 0;
+
                /* thrd_dist_maps are not reset because distances
-                * will be overwritten when node targets are added */
+                * will be overwritten when node targets are added
+                * thrd_dist_maps[index]->reset(); */
+
+               node_set_t * target_nodes = getTargetNodes(tid);
+               target_nodes->reset();
        }
 
        waiting_for.reset();
index c15fb21f4ad0f17cb968d35a682f57f0e66c1b4e..36d95796461fa8e73718d9de125762cb5d2c353e 100644 (file)
--- a/waitobj.h
+++ b/waitobj.h
@@ -18,6 +18,7 @@ public:
        void add_waiting_for(thread_id_t other, FuncNode * node, int dist);
        void add_waited_by(thread_id_t other);
        bool remove_waiting_for_node(thread_id_t other, FuncNode * node);
+       void remove_waiting_for(thread_id_t other);
        void remove_waited_by(thread_id_t other);
 
        thrd_id_set_t * getWaitingFor() { return &waiting_for; }
@@ -27,7 +28,6 @@ public:
        int lookup_dist(thread_id_t tid, FuncNode * target);
 
        bool incr_counter(thread_id_t tid);
-       // SnapVector<thread_id_t> incr_waiting_for_counter();
 
        void clear_waiting_for();