Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5611bdab authored by Hans Boehm's avatar Hans Boehm Committed by Android Git Automerger
Browse files

am dc1fb908: am a0187a9c: Merge "Revert "Revert "Revert "Revert "Remove...

am dc1fb908: am a0187a9c: Merge "Revert "Revert "Revert "Revert "Remove incorrect android_atomic_...64 use."""""

* commit 'dc1fb908':
  Revert "Revert "Revert "Revert "Remove incorrect android_atomic_...64 use.""""
parents 9671799c dc1fb908
Loading
Loading
Loading
Loading
+3 −1
Original line number Original line Diff line number Diff line
@@ -17,6 +17,8 @@
#ifndef ANDROID_BINDER_H
#ifndef ANDROID_BINDER_H
#define ANDROID_BINDER_H
#define ANDROID_BINDER_H


#include <stdatomic.h>
#include <stdint.h>
#include <binder/IBinder.h>
#include <binder/IBinder.h>


// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
@@ -69,7 +71,7 @@ private:


    class Extras;
    class Extras;


            Extras*     mExtras;
    atomic_uintptr_t    mExtras;  // should be atomic<Extras *>
            void*       mReserved0;
            void*       mReserved0;
};
};


+18 −14
Original line number Original line Diff line number Diff line
@@ -16,7 +16,7 @@


#include <binder/Binder.h>
#include <binder/Binder.h>


#include <utils/Atomic.h>
#include <stdatomic.h>
#include <utils/misc.h>
#include <utils/misc.h>
#include <binder/BpBinder.h>
#include <binder/BpBinder.h>
#include <binder/IInterface.h>
#include <binder/IInterface.h>
@@ -71,8 +71,8 @@ public:
// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------


BBinder::BBinder()
BBinder::BBinder()
    : mExtras(NULL)
{
{
    atomic_init(&mExtras, 0);
}
}


bool BBinder::isBinderAlive() const
bool BBinder::isBinderAlive() const
@@ -139,19 +139,19 @@ void BBinder::attachObject(
    const void* objectID, void* object, void* cleanupCookie,
    const void* objectID, void* object, void* cleanupCookie,
    object_cleanup_func func)
    object_cleanup_func func)
{
{
    Extras* e = mExtras;
    Extras* e = reinterpret_cast<Extras*>(
                    atomic_load_explicit(&mExtras, memory_order_acquire));


    if (!e) {
    if (!e) {
        e = new Extras;
        e = new Extras;
#ifdef __LP64__
        uintptr_t* expected = 0;
        if (android_atomic_release_cas64(0, reinterpret_cast<int64_t>(e),
        if (!atomic_compare_exchange_strong_explicit(
                reinterpret_cast<volatile int64_t*>(&mExtras)) != 0) {
                                        &mExtras, &expected,
#else
                                        reinterpret_cast<uintptr_t>(e),
        if (android_atomic_cmpxchg(0, reinterpret_cast<int32_t>(e),
                                        memory_order_release,
                reinterpret_cast<volatile int32_t*>(&mExtras)) != 0) {
                                        memory_order_acquire)) {
#endif
            delete e;
            delete e;
            e = mExtras;
            e = reinterpret_cast<Extras*>(expected);  // Filled in by CAS
        }
        }
        if (e == 0) return; // out of memory
        if (e == 0) return; // out of memory
    }
    }
@@ -162,7 +162,8 @@ void BBinder::attachObject(


void* BBinder::findObject(const void* objectID) const
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;
    if (!e) return NULL;


    AutoMutex _l(e->mLock);
    AutoMutex _l(e->mLock);
@@ -171,7 +172,8 @@ void* BBinder::findObject(const void* objectID) const


void BBinder::detachObject(const void* objectID)
void BBinder::detachObject(const void* objectID)
{
{
    Extras* e = mExtras;
    Extras* e = reinterpret_cast<Extras*>(
                    atomic_load_explicit(&mExtras, memory_order_acquire));
    if (!e) return;
    if (!e) return;


    AutoMutex _l(e->mLock);
    AutoMutex _l(e->mLock);
@@ -185,7 +187,9 @@ BBinder* BBinder::localBinder()


BBinder::~BBinder()
BBinder::~BBinder()
{
{
    if (mExtras) delete mExtras;
    Extras* e = reinterpret_cast<Extras*>(
                    atomic_load_explicit(&mExtras, memory_order_relaxed));
    if (e) delete e;
}
}