From 1558b85acf6704049c50c44b9f9f92966294b171 Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Sat, 28 Nov 2009 15:35:15 -0700 Subject: [PATCH] second attempt to fix "idle to active" fast path If another thread succeeds in entering the "exclusive" state while we use the fast path to transition the current thread to "active", we must switch back to "idle" temporarily to allow the exclusive thread a chance to continue, and then retry the transition to "active" via the slow path. --- src/machine.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/machine.cpp b/src/machine.cpp index cdb12a5219..62c4649659 100644 --- a/src/machine.cpp +++ b/src/machine.cpp @@ -2422,12 +2422,13 @@ enter(Thread* t, Thread::State s) // fast path INCREMENT(&(t->m->activeCount), 1); + t->state = s; + if (t->m->exclusive) { - // a thread has entered exclusive mode - switch to slow path - assert(t, t->m->activeCount > 0); - INCREMENT(&(t->m->activeCount), -1); + // another thread has entered the exclusive state, so we + // return to idle and use the slow path to become active + enter(t, Thread::IdleState); } else { - t->state = s; break; } }