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

Commit 696d3d46 authored by Steven Moreland's avatar Steven Moreland Committed by android-build-merger
Browse files

Merge "libbinder_ndk: assert for known bad refcounting" am: 72c8a93b am: f163cf2c

am: dc72b537

Change-Id: I558148f61f2adbe8eb58e42ac22c83c8c3721dfe
parents bc99b990 dc72b537
Loading
Loading
Loading
Loading
+7 −1
Original line number Diff line number Diff line
@@ -30,6 +30,8 @@
#include <android/binder_parcel.h>
#include <android/binder_status.h>

#include <assert.h>

#ifdef __cplusplus

#include <cstddef>
@@ -76,7 +78,11 @@ public:
     * Takes ownership of one strong refcount of binder
     */
    void set(AIBinder* binder) {
        if (mBinder != nullptr) AIBinder_decStrong(mBinder);
        AIBinder* old = *const_cast<AIBinder* volatile*>(&mBinder);
        if (old != nullptr) AIBinder_decStrong(old);
        if (old != *const_cast<AIBinder* volatile*>(&mBinder)) {
            __assert(__FILE__, __LINE__, "Race detected.");
        }
        mBinder = binder;
    }

+10 −1
Original line number Diff line number Diff line
@@ -30,6 +30,8 @@
#include <android/binder_auto_utils.h>
#include <android/binder_ibinder.h>

#include <assert.h>

#ifdef __cplusplus

#include <memory>
@@ -39,11 +41,18 @@ namespace ndk {

/**
 * analog using std::shared_ptr for internally held refcount
 *
 * ref must be called at least one time during the lifetime of this object. The recommended way to construct
 * this object is with SharedRefBase::make.
 */
class SharedRefBase {
public:
    SharedRefBase() {}
    virtual ~SharedRefBase() {}
    virtual ~SharedRefBase() {
        std::call_once(mFlagThis, [&]() {
            __assert(__FILE__, __LINE__, "SharedRefBase: no ref created during lifetime");
        });
    }

    /**
     * A shared_ptr must be held to this object when this is called. This must be called once during