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
index ccbbbb1418a9ca785394e41df2480f24f22a923d,71f545128b9257156940fe4427380c78f84ea764..e74ebcf64bdbb5aace60103095d47dcf09bfd395
@@@ -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
index 48c73cfbeca2db10dd19148062bded4bfd9858e7,c37de41a1f14fb032c0ab85fe28064426cb943a1..9c3b4afa2986fac9ecce604e9de9394ebca6f3eb
@@@ -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
index 722b864723a40f8d902c5ed2920575d43b837b01,7ca610cad3fa7d488f29d682795f7886ff0f5943..0c401b19b59084609a2fe12b1cbb565a736cfbac
@@@ -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
index 371838dcb1977c912a346a7a995e4e9cc3083425,c41af4a0466b173615a7cd2d9bb48a45c569424c..e102d9c34431a13dea089d9437857640e2691cfd
+++ 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
index 14dff6e023ddbbf174f1a129378bee7a55b72f55,14dff6e023ddbbf174f1a129378bee7a55b72f55..0fcfb51f67e66ff9ee439f9b48c1bd860838cbfa
+++ 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
index 45a7e8bbe91f44f867e22958502491ffb64b4fa6,45a7e8bbe91f44f867e22958502491ffb64b4fa6..26fab3f6c2fff4e0ed995e4d68a8dd7733ecb5f5
@@@ -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