diff options
author | Hans Boehm <hboehm@google.com> | 2014-08-08 14:19:14 -0700 |
---|---|---|
committer | Hans Boehm <hboehm@google.com> | 2014-08-08 17:14:30 -0700 |
commit | 52be6ceb70c5d207ebbb4f66bd86a1cf3e97dff6 (patch) | |
tree | 37b834db2966b74d3d1bb104e278a0f2e20d1a3d /Binder.cpp | |
parent | 7aadd8d5d50efb4626e4627ad5de019c3a192a8e (diff) | |
download | libhwbinder-52be6ceb70c5d207ebbb4f66bd86a1cf3e97dff6.tar.gz |
Revert "Revert "Remove incorrect android_atomic_...64 use.""
This reverts commit 9dc5c269f74ac76f62515e3d9558e67c6e63067d.
Adds a stdint.h include in case stdatomic.h stops including that.
Change-Id: If3dd1db1f1132c0f2dc1efb0a44617d3f36d7cfb
Diffstat (limited to 'Binder.cpp')
-rw-r--r-- | Binder.cpp | 32 |
1 files changed, 18 insertions, 14 deletions
@@ -16,7 +16,7 @@ #include <binder/Binder.h> -#include <utils/Atomic.h> +#include <stdatomic.h> #include <utils/misc.h> #include <binder/BpBinder.h> #include <binder/IInterface.h> @@ -71,8 +71,8 @@ public: // --------------------------------------------------------------------------- BBinder::BBinder() - : mExtras(NULL) { + atomic_init(&mExtras, 0); } bool BBinder::isBinderAlive() const @@ -139,19 +139,19 @@ void BBinder::attachObject( const void* objectID, void* object, void* cleanupCookie, object_cleanup_func func) { - Extras* e = mExtras; + Extras* e = reinterpret_cast<Extras*>( + atomic_load_explicit(&mExtras, memory_order_acquire)); if (!e) { e = new Extras; -#ifdef __LP64__ - if (android_atomic_release_cas64(0, reinterpret_cast<int64_t>(e), - reinterpret_cast<volatile int64_t*>(&mExtras)) != 0) { -#else - if (android_atomic_cmpxchg(0, reinterpret_cast<int32_t>(e), - reinterpret_cast<volatile int32_t*>(&mExtras)) != 0) { -#endif + uintptr_t* expected = 0; + if (!atomic_compare_exchange_strong_explicit( + &mExtras, &expected, + reinterpret_cast<uintptr_t>(e), + memory_order_release, + memory_order_acquire)) { delete e; - e = mExtras; + e = reinterpret_cast<Extras*>(expected); // Filled in by CAS } if (e == 0) return; // out of memory } @@ -162,7 +162,8 @@ void BBinder::attachObject( void* BBinder::findObject(const void* objectID) const { - Extras* e = mExtras; + Extras* e = reinterpret_cast<Extras*>( + atomic_load_explicit(&mExtras, memory_order_acquire)); if (!e) return NULL; AutoMutex _l(e->mLock); @@ -171,7 +172,8 @@ void* BBinder::findObject(const void* objectID) const void BBinder::detachObject(const void* objectID) { - Extras* e = mExtras; + Extras* e = reinterpret_cast<Extras*>( + atomic_load_explicit(&mExtras, memory_order_acquire)); if (!e) return; AutoMutex _l(e->mLock); @@ -185,7 +187,9 @@ BBinder* BBinder::localBinder() BBinder::~BBinder() { - if (mExtras) delete mExtras; + Extras* e = reinterpret_cast<Extras*>( + atomic_load_explicit(&mExtras, memory_order_relaxed)); + if (e) delete e; } |