From e1430f3d41e01fca5b878fc5909cf1c871c12f0e Mon Sep 17 00:00:00 2001 From: Brian Norris Date: Tue, 17 Apr 2012 15:46:11 -0700 Subject: [PATCH] threads/model: move switch_to_master from class Thread to class ModelChecker --- libatomic.cc | 5 ++--- libthreads.cc | 4 ++-- model.cc | 12 ++++++++++++ model.h | 2 ++ threads.cc | 11 ----------- threads_internal.h | 1 - 6 files changed, 18 insertions(+), 17 deletions(-) diff --git a/libatomic.cc b/libatomic.cc index 059d2ae..e224a8a 100644 --- a/libatomic.cc +++ b/libatomic.cc @@ -1,14 +1,13 @@ #include "libatomic.h" #include "model.h" -#include "threads_internal.h" void atomic_store_explicit(struct atomic_object *obj, int value, memory_order order) { - thread_current()->switch_to_master(new ModelAction(ATOMIC_WRITE, order, obj, value)); + model->switch_to_master(new ModelAction(ATOMIC_WRITE, order, obj, value)); } int atomic_load_explicit(struct atomic_object *obj, memory_order order) { - thread_current()->switch_to_master(new ModelAction(ATOMIC_READ, order, obj, VALUE_NONE)); + model->switch_to_master(new ModelAction(ATOMIC_READ, order, obj, VALUE_NONE)); return 0; } diff --git a/libthreads.cc b/libthreads.cc index fd6259a..7ed5491 100644 --- a/libthreads.cc +++ b/libthreads.cc @@ -23,14 +23,14 @@ int thrd_join(thrd_t t) Thread *th = model->get_thread(thrd_to_id(t)); while (th->get_state() != THREAD_COMPLETED && !ret) /* seq_cst is just a 'don't care' parameter */ - ret = thread_current()->switch_to_master(new ModelAction(THREAD_JOIN, memory_order_seq_cst, NULL, VALUE_NONE)); + ret = model->switch_to_master(new ModelAction(THREAD_JOIN, memory_order_seq_cst, NULL, VALUE_NONE)); return ret; } int thrd_yield(void) { /* seq_cst is just a 'don't care' parameter */ - return thread_current()->switch_to_master(new ModelAction(THREAD_YIELD, memory_order_seq_cst, NULL, VALUE_NONE)); + return model->switch_to_master(new ModelAction(THREAD_YIELD, memory_order_seq_cst, NULL, VALUE_NONE)); } thrd_t thrd_current(void) diff --git a/model.cc b/model.cc index 42d31b3..1015701 100644 --- a/model.cc +++ b/model.cc @@ -55,6 +55,18 @@ int ModelChecker::add_thread(Thread *t) return 0; } +int ModelChecker::switch_to_master(ModelAction *act) +{ + Thread *old, *next; + + DBG(); + old = thread_current(); + set_current_action(act); + old->set_state(THREAD_READY); + next = system_thread; + return old->swap(next); +} + ModelAction::ModelAction(action_type_t type, memory_order order, void *loc, int value) { Thread *t = thread_current(); diff --git a/model.h b/model.h index f26ab55..05cdf5c 100644 --- a/model.h +++ b/model.h @@ -48,6 +48,8 @@ public: Thread *get_thread(thread_id_t tid) { return thread_map[tid]; } void assign_id(Thread *t); + + int switch_to_master(ModelAction *act); private: int used_thread_id; class ModelAction *current_action; diff --git a/threads.cc b/threads.cc index 38a0dce..397c789 100644 --- a/threads.cc +++ b/threads.cc @@ -60,17 +60,6 @@ void Thread::dispose() stack_free(stack); } -int Thread::switch_to_master(ModelAction *act) -{ - Thread *next; - - DBG(); - model->set_current_action(act); - state = THREAD_READY; - next = model->system_thread; - return swap(next); -} - Thread::Thread(thrd_t *t, void (*func)(), void *a) { int ret; diff --git a/threads_internal.h b/threads_internal.h index bdef9a5..4c1e36a 100644 --- a/threads_internal.h +++ b/threads_internal.h @@ -20,7 +20,6 @@ public: Thread(thrd_t *t); int swap(Thread *t); void dispose(); - int switch_to_master(ModelAction *act); thread_state get_state() { return state; } void set_state(thread_state s) { state = s; } -- 2.34.1