From: weiyu Date: Wed, 8 Apr 2020 22:41:58 +0000 (-0700) Subject: Use simple_action_list for conditionvariable waiters X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=f269c2a1c390e82ae189bc690a750601f874283f;p=c11tester.git Use simple_action_list for conditionvariable waiters --- f269c2a1c390e82ae189bc690a750601f874283f diff --cc classlist.h index ccbbbb14,71f54512..e74ebcf6 --- a/classlist.h +++ b/classlist.h @@@ -26,7 -29,7 +29,8 @@@ class actionlist struct model_snapshot_members; struct bug_message; - typedef SnapList action_list_t; ++typedef SnapList simple_action_list_t; + typedef actionlist action_list_t; typedef SnapList func_id_list_t; typedef SnapList func_inst_list_t; diff --cc execution.cc index 48c73cfb,c37de41a..9c3b4afa --- a/execution.cc +++ b/execution.cc @@@ -118,6 -118,6 +118,16 @@@ static SnapVector * get_ return tmp; } ++static simple_action_list_t * get_safe_ptr_action(HashTable * 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 * 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)); } @@@ -442,7 -434,7 +456,7 @@@ 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 * rit = waiters->begin();rit != NULL;rit=rit->getNext()) { scheduler->wake(get_thread(rit->getVal())); @@@ -451,7 -443,7 +465,7 @@@ 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 722b8647,7ca610ca..0c401b19 --- a/execution.h +++ b/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 condvar_waiters_map; ++ HashTable condvar_waiters_map; /** Per-object list of actions that each thread performed. */ HashTable *, uintptr_t, 2> obj_thrd_map; diff --cc fuzzer.cc index 371838dc,c41af4a0..e102d9c3 --- a/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 * 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 14dff6e0,14dff6e0..0fcfb51f --- a/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 index 45a7e8bb,45a7e8bb..26fab3f6 --- a/newfuzzer.h +++ b/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);