Use simple_action_list for conditionvariable waiters
authorweiyu <weiyuluo1232@gmail.com>
Wed, 8 Apr 2020 22:41:58 +0000 (15:41 -0700)
committerweiyu <weiyuluo1232@gmail.com>
Wed, 8 Apr 2020 22:41:58 +0000 (15:41 -0700)
1  2 
classlist.h
execution.cc
execution.h
fuzzer.cc
fuzzer.h
newfuzzer.h
threads.cc

diff --cc classlist.h
@@@ -26,7 -29,7 +29,8 @@@ class actionlist
  struct model_snapshot_members;
  struct bug_message;
  
- typedef SnapList<ModelAction *> action_list_t;
++typedef SnapList<ModelAction *> simple_action_list_t;
+ typedef actionlist action_list_t;
  typedef SnapList<uint32_t> func_id_list_t;
  typedef SnapList<FuncInst *> func_inst_list_t;
  
diff --cc execution.cc
@@@ -118,6 -118,6 +118,16 @@@ static SnapVector<action_list_t> * get_
        return tmp;
  }
  
++static simple_action_list_t * get_safe_ptr_action(HashTable<const void *, simple_action_list_t *, uintptr_t, 2> * hash, void * ptr)
++{
++      simple_action_list_t *tmp = hash->get(ptr);
++      if (tmp == NULL) {
++              tmp = new simple_action_list_t();
++              hash->put(ptr, tmp);
++      }
++      return tmp;
++}
++
  /** @return a thread ID for a new Thread */
  thread_id_t ModelExecution::get_next_id()
  {
@@@ -401,17 -403,8 +415,17 @@@ bool ModelExecution::process_mutex(Mode
                        /* unlock the lock - after checking who was waiting on it */
                        state->locked = NULL;
  
 -                      /* disable this thread */
 -                      get_safe_ptr_action(&condvar_waiters_map, curr->get_location())->addAction(curr);
 +                      /* remove old wait action and disable this thread */
-                       action_list_t * waiters = get_safe_ptr_action(&condvar_waiters_map, curr->get_location());
++                      simple_action_list_t * waiters = get_safe_ptr_action(&condvar_waiters_map, curr->get_location());
 +                      for (sllnode<ModelAction *> * it = waiters->begin(); it != NULL; it = it->getNext()) {
 +                              ModelAction * wait = it->getVal();
 +                              if (wait->get_tid() == curr->get_tid()) {
 +                                      waiters->erase(it);
 +                                      break;
 +                              }
 +                      }
 +
 +                      waiters->push_back(curr);
                        scheduler->sleep(get_thread(curr));
                }
  
                break;
        }
        case ATOMIC_NOTIFY_ALL: {
--              action_list_t *waiters = get_safe_ptr_action(&condvar_waiters_map, curr->get_location());
++              simple_action_list_t *waiters = get_safe_ptr_action(&condvar_waiters_map, curr->get_location());
                //activate all the waiting threads
                for (sllnode<ModelAction *> * rit = waiters->begin();rit != NULL;rit=rit->getNext()) {
                        scheduler->wake(get_thread(rit->getVal()));
                break;
        }
        case ATOMIC_NOTIFY_ONE: {
--              action_list_t *waiters = get_safe_ptr_action(&condvar_waiters_map, curr->get_location());
++              simple_action_list_t *waiters = get_safe_ptr_action(&condvar_waiters_map, curr->get_location());
                if (waiters->size() != 0) {
                        Thread * thread = fuzzer->selectNotify(waiters);
                        scheduler->wake(thread);
diff --cc execution.h
@@@ -152,7 -150,7 +150,7 @@@ private
  
        /** Per-object list of actions. Maps an object (i.e., memory location)
         * to a trace of all actions performed on the object. */
--      HashTable<const void *, action_list_t *, uintptr_t, 2> condvar_waiters_map;
++      HashTable<const void *, simple_action_list_t *, uintptr_t, 2> condvar_waiters_map;
  
        /** Per-object list of actions that each thread performed. */
        HashTable<const void *, SnapVector<action_list_t> *, uintptr_t, 2> obj_thrd_map;
diff --cc fuzzer.cc
+++ b/fuzzer.cc
@@@ -16,7 -16,7 +16,7 @@@ Thread * Fuzzer::selectThread(int * thr
        return model->get_thread(curr_tid);
  }
  
--Thread * Fuzzer::selectNotify(action_list_t * waiters) {
++Thread * Fuzzer::selectNotify(simple_action_list_t * waiters) {
        int numwaiters = waiters->size();
        int random_index = random() % numwaiters;
        sllnode<ModelAction*> * it = waiters->begin();
@@@ -41,5 -41,5 +41,5 @@@ bool Fuzzer::shouldWake(const ModelActi
  
  bool Fuzzer::shouldWait(const ModelAction * act)
  {
--      return random() & 1;
++      return true;
  }
diff --cc fuzzer.h
+++ b/fuzzer.h
@@@ -12,7 -12,7 +12,7 @@@ public
        virtual bool has_paused_threads() { return false; }
        virtual Thread * selectThread(int * threadlist, int numthreads);
  
--      Thread * selectNotify(action_list_t * waiters);
++      Thread * selectNotify(simple_action_list_t * waiters);
        bool shouldSleep(const ModelAction *sleep);
        bool shouldWake(const ModelAction *sleep);
        virtual bool shouldWait(const ModelAction *wait);
diff --cc newfuzzer.h
@@@ -29,7 -29,7 +29,7 @@@ public
        void notify_paused_thread(Thread * thread);
  
        Thread * selectThread(int * threadlist, int numthreads);
--      Thread * selectNotify(action_list_t * waiters);
++      Thread * selectNotify(simple_action_list_t * waiters);
        bool shouldSleep(const ModelAction * sleep);
        bool shouldWake(const ModelAction * sleep);
        bool shouldWait(const ModelAction * wait);
diff --cc threads.cc
Simple merge