From: Brian Norris <banorris@uci.edu>
Date: Tue, 12 Feb 2013 20:53:20 +0000 (-0800)
Subject: model: set thread state during 'swap' calls
X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=1cdcdc24156572a63fd8261a7a3dd2f04ca6648c;p=cdsspec-compiler.git

model: set thread state during 'swap' calls

Rather than setting thread-state from subtle places within ModelChecker,
it makes more logical sense to set it from withing the Thread::swap
functions.
---

diff --git a/model.cc b/model.cc
index cbf1f33..0809652 100644
--- 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;
 	}
 
diff --git a/threads.cc b/threads.cc
index 6adc053..9de5802 100644
--- a/threads.cc
+++ b/threads.cc
@@ -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);
 }