model: set thread state during 'swap' calls
authorBrian Norris <banorris@uci.edu>
Tue, 12 Feb 2013 20:53:20 +0000 (12:53 -0800)
committerBrian Norris <banorris@uci.edu>
Tue, 12 Feb 2013 20:57:33 +0000 (12:57 -0800)
Rather than setting thread-state from subtle places within ModelChecker,
it makes more logical sense to set it from withing the Thread::swap
functions.

model.cc
threads.cc

index cbf1f3313ac3d2e89e7053e43c96bcf32a096ed6..08096528bddc326b04dbe31b0772b1fcfb6458f6 100644 (file)
--- a/model.cc
+++ b/model.cc
@@ -296,7 +296,6 @@ void ModelChecker::execute_sleep_set()
                thread_id_t tid = int_to_id(i);
                Thread *thr = get_thread(tid);
                if (scheduler->is_sleep_set(thr) && thr->get_pending() == NULL) {
-                       thr->set_state(THREAD_RUNNING);
                        scheduler->next_thread(thr);
                        Thread::swap(&system_context, thr);
                        priv->current_action->set_sleep_flag();
@@ -2677,7 +2676,6 @@ uint64_t ModelChecker::switch_to_master(ModelAction *act)
        DBG();
        Thread *old = thread_current();
        set_current_action(act);
-       old->set_state(THREAD_READY);
        if (Thread::swap(old, &system_context) < 0) {
                perror("swap threads");
                exit(EXIT_FAILURE);
@@ -2745,13 +2743,10 @@ bool ModelChecker::take_step(ModelAction *curr)
        if (!next_thrd)
                return false;
 
-       next_thrd->set_state(THREAD_RUNNING);
-
        if (next_thrd->get_pending() != NULL) {
                /* restart a pending action */
                set_current_action(next_thrd->get_pending());
                next_thrd->set_pending(NULL);
-               next_thrd->set_state(THREAD_READY);
                return true;
        }
 
index 6adc053ae2dbfc58a00bbbb2f0e6a7c2e79a7b4c..9de580297871687e4529f2a67512aa6087a9cc1b 100644 (file)
@@ -84,6 +84,7 @@ int Thread::create_context()
  */
 int Thread::swap(Thread *t, ucontext_t *ctxt)
 {
+       t->set_state(THREAD_READY);
        return swapcontext(&t->context, ctxt);
 }
 
@@ -97,6 +98,7 @@ int Thread::swap(Thread *t, ucontext_t *ctxt)
  */
 int Thread::swap(ucontext_t *ctxt, Thread *t)
 {
+       t->set_state(THREAD_RUNNING);
        return swapcontext(ctxt, &t->context);
 }