summaryrefslogtreecommitdiff
path: root/Binder.cpp
diff options
context:
space:
mode:
authorBailey Forrest <bcf@google.com>2015-08-18 17:15:10 -0700
committerBailey Forrest <bcf@google.com>2015-08-19 14:56:16 -0700
commite20d6f4a895e4493df51134985766c958027c34c (patch)
tree6f639dcd12369534af03772946a84e43dd5d665b /Binder.cpp
parentc2cdb78518eb2916757ea3f70feced3daec51d63 (diff)
downloadlibhwbinder-e20d6f4a895e4493df51134985766c958027c34c.tar.gz
binder: Change from C11 <stdatomic.h> to C++11 <atomic>.
Change-Id: Ib831a9ccfcc7089940d37883d860574359c270e2
Diffstat (limited to 'Binder.cpp')
-rw-r--r--Binder.cpp41
1 files changed, 13 insertions, 28 deletions
diff --git a/Binder.cpp b/Binder.cpp
index 9d200fb..e39093d 100644
--- a/Binder.cpp
+++ b/Binder.cpp
@@ -16,7 +16,7 @@
#include <binder/Binder.h>
-#include <stdatomic.h>
+#include <atomic>
#include <utils/misc.h>
#include <binder/BpBinder.h>
#include <binder/IInterface.h>
@@ -70,9 +70,8 @@ public:
// ---------------------------------------------------------------------------
-BBinder::BBinder()
+BBinder::BBinder() : mExtras(nullptr)
{
- atomic_init(&mExtras, static_cast<uintptr_t>(0));
}
bool BBinder::isBinderAlive() const
@@ -139,19 +138,16 @@ void BBinder::attachObject(
const void* objectID, void* object, void* cleanupCookie,
object_cleanup_func func)
{
- Extras* e = reinterpret_cast<Extras*>(
- atomic_load_explicit(&mExtras, memory_order_acquire));
+ Extras* e = mExtras.load(std::memory_order_acquire);
if (!e) {
e = new Extras;
- uintptr_t expected = 0;
- if (!atomic_compare_exchange_strong_explicit(
- &mExtras, &expected,
- reinterpret_cast<uintptr_t>(e),
- memory_order_release,
- memory_order_acquire)) {
+ Extras* expected = nullptr;
+ if (!mExtras.compare_exchange_strong(expected, e,
+ std::memory_order_release,
+ std::memory_order_acquire)) {
delete e;
- e = reinterpret_cast<Extras*>(expected); // Filled in by CAS
+ e = expected; // Filled in by CAS
}
if (e == 0) return; // out of memory
}
@@ -160,18 +156,9 @@ void BBinder::attachObject(
e->mObjects.attach(objectID, object, cleanupCookie, func);
}
-// The C11 standard doesn't allow atomic loads from const fields,
-// though C++11 does. Fudge it until standards get straightened out.
-static inline uintptr_t load_const_atomic(const atomic_uintptr_t* p,
- memory_order mo) {
- atomic_uintptr_t* non_const_p = const_cast<atomic_uintptr_t*>(p);
- return atomic_load_explicit(non_const_p, mo);
-}
-
void* BBinder::findObject(const void* objectID) const
{
- Extras* e = reinterpret_cast<Extras*>(
- load_const_atomic(&mExtras, memory_order_acquire));
+ Extras* e = mExtras.load(std::memory_order_acquire);
if (!e) return NULL;
AutoMutex _l(e->mLock);
@@ -180,8 +167,7 @@ void* BBinder::findObject(const void* objectID) const
void BBinder::detachObject(const void* objectID)
{
- Extras* e = reinterpret_cast<Extras*>(
- atomic_load_explicit(&mExtras, memory_order_acquire));
+ Extras* e = mExtras.load(std::memory_order_acquire);
if (!e) return;
AutoMutex _l(e->mLock);
@@ -195,8 +181,7 @@ BBinder* BBinder::localBinder()
BBinder::~BBinder()
{
- Extras* e = reinterpret_cast<Extras*>(
- atomic_load_explicit(&mExtras, memory_order_relaxed));
+ Extras* e = mExtras.load(std::memory_order_relaxed);
if (e) delete e;
}
@@ -252,7 +237,7 @@ BpRefBase::BpRefBase(const sp<IBinder>& o)
BpRefBase::~BpRefBase()
{
if (mRemote) {
- if (!(mState&kRemoteAcquired)) {
+ if (!(mState.load(std::memory_order_relaxed)&kRemoteAcquired)) {
mRemote->decStrong(this);
}
mRefs->decWeak(this);
@@ -261,7 +246,7 @@ BpRefBase::~BpRefBase()
void BpRefBase::onFirstRef()
{
- android_atomic_or(kRemoteAcquired, &mState);
+ mState.fetch_or(kRemoteAcquired, std::memory_order_relaxed);
}
void BpRefBase::onLastStrongRef(const void* /*id*/)