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

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

am 4a7001ca: Merge "Work around C11 const atomic restrictions."

* commit '4a7001ca':
  Work around C11 const atomic restrictions.
parents 6f3e466b 4a7001ca
Loading
Loading
Loading
Loading
+9 −1
Original line number Diff line number Diff line
@@ -160,10 +160,18 @@ 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*>(
                    atomic_load_explicit(&mExtras, memory_order_acquire));
                    load_const_atomic(&mExtras, memory_order_acquire));
    if (!e) return NULL;

    AutoMutex _l(e->mLock);