diff options
author | Ian Rogers <irogers@google.com> | 2014-07-09 21:12:06 -0700 |
---|---|---|
committer | Ian Rogers <irogers@google.com> | 2014-07-09 21:24:04 -0700 |
commit | b8e087e0dfd619df90cbb56534478a60bc859ebf (patch) | |
tree | f6f4e896935b02c68a40ae1410edb08f7296cad9 /runtime/thread-inl.h | |
parent | 43b6fe0270477cd47f8dd8b064d006961a44be54 (diff) | |
download | art-b8e087e0dfd619df90cbb56534478a60bc859ebf.zip art-b8e087e0dfd619df90cbb56534478a60bc859ebf.tar.gz art-b8e087e0dfd619df90cbb56534478a60bc859ebf.tar.bz2 |
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
Diffstat (limited to 'runtime/thread-inl.h')
-rw-r--r-- | runtime/thread-inl.h | 18 |
1 files changed, 10 insertions, 8 deletions
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 <pthread.h> -#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. |