From b8e087e0dfd619df90cbb56534478a60bc859ebf Mon Sep 17 00:00:00 2001 From: Ian Rogers Date: Wed, 9 Jul 2014 21:12:06 -0700 Subject: Move thread state to art::Atomic. Leaves the CAS operations as relaxed although art::Atomic treats relaxed CAS as a strong CAS when not compiling with clang. Change-Id: I6d37c22173540d166b624385e52e4ad05e592adc --- runtime/thread-inl.h | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'runtime/thread-inl.h') diff --git a/runtime/thread-inl.h b/runtime/thread-inl.h index b1180bd..38f1307 100644 --- a/runtime/thread-inl.h +++ b/runtime/thread-inl.h @@ -21,8 +21,6 @@ #include -#include "cutils/atomic-inline.h" - #include "base/casts.h" #include "base/mutex-inl.h" #include "gc/heap.h" @@ -99,9 +97,12 @@ inline void Thread::TransitionFromRunnableToSuspended(ThreadState new_state) { DCHECK_EQ((old_state_and_flags.as_struct.flags & kCheckpointRequest), 0); new_state_and_flags.as_struct.flags = old_state_and_flags.as_struct.flags; new_state_and_flags.as_struct.state = new_state; - int status = android_atomic_cas(old_state_and_flags.as_int, new_state_and_flags.as_int, - &tls32_.state_and_flags.as_int); - if (LIKELY(status == 0)) { + + // CAS the value without a memory ordering as that is given by the lock release below. + bool done = + tls32_.state_and_flags.as_atomic_int.CompareExchangeWeakRelaxed(old_state_and_flags.as_int, + new_state_and_flags.as_int); + if (LIKELY(done)) { break; } } @@ -141,9 +142,10 @@ inline ThreadState Thread::TransitionFromSuspendedToRunnable() { union StateAndFlags new_state_and_flags; new_state_and_flags.as_int = old_state_and_flags.as_int; new_state_and_flags.as_struct.state = kRunnable; - // CAS the value without a memory barrier, that occurred in the lock above. - done = android_atomic_cas(old_state_and_flags.as_int, new_state_and_flags.as_int, - &tls32_.state_and_flags.as_int) == 0; + // CAS the value without a memory ordering as that is given by the lock acquisition above. + done = + tls32_.state_and_flags.as_atomic_int.CompareExchangeWeakRelaxed(old_state_and_flags.as_int, + new_state_and_flags.as_int); } if (UNLIKELY(!done)) { // Failed to transition to Runnable. Release shared mutator_lock_ access and try again. -- cgit v1.1