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

Commit 7794b305 authored by Mathias Agopian's avatar Mathias Agopian Committed by Android Git Automerger
Browse files

am 77079399: am a9c9a4ba: fix RefBase so it retains binary-compatibility with...

am 77079399: am a9c9a4ba: fix RefBase so it retains binary-compatibility with gingerbread (DO NOT MERGE)

* commit '77079399fca3e9c71e2ac06f3da26934e1c278b9':
  fix RefBase so it retains binary-compatibility with gingerbread (DO NOT MERGE)
parents 574462f9 4c83aefe
Loading
Loading
Loading
Loading
+13 −7
Original line number Original line Diff line number Diff line
@@ -117,16 +117,22 @@ public:


    typedef RefBase basetype;
    typedef RefBase basetype;


protected:
    // used to override the RefBase destruction.
                            RefBase();
    class Destroyer {
    virtual                 ~RefBase();
        friend class RefBase;
    public:
        virtual ~Destroyer();
    private:
        virtual void destroy(RefBase const* base) = 0;
    };


    // called when the last reference goes away. this is responsible for
    // calling the destructor. The default implementation just does
    // "delete this;".
    // Make sure to never acquire a strong reference from this function. The
    // Make sure to never acquire a strong reference from this function. The
    // same restrictions than for destructors apply.
    // same restrictions than for destructors apply.
    virtual void            destroy() const;
    void setDestroyer(Destroyer* destroyer);

protected:
                            RefBase();
    virtual                 ~RefBase();


    //! Flags for extendObjectLifetime()
    //! Flags for extendObjectLifetime()
    enum {
    enum {
+25 −9
Original line number Original line Diff line number Diff line
@@ -49,6 +49,11 @@ namespace android {


// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------


RefBase::Destroyer::~Destroyer() {
}

// ---------------------------------------------------------------------------

class RefBase::weakref_impl : public RefBase::weakref_type
class RefBase::weakref_impl : public RefBase::weakref_type
{
{
public:
public:
@@ -56,7 +61,7 @@ public:
    volatile int32_t    mWeak;
    volatile int32_t    mWeak;
    RefBase* const      mBase;
    RefBase* const      mBase;
    volatile int32_t    mFlags;
    volatile int32_t    mFlags;

    Destroyer*          mDestroyer;


#if !DEBUG_REFS
#if !DEBUG_REFS


@@ -65,6 +70,7 @@ public:
        , mWeak(0)
        , mWeak(0)
        , mBase(base)
        , mBase(base)
        , mFlags(0)
        , mFlags(0)
        , mDestroyer(0)
    {
    {
    }
    }


@@ -345,10 +351,6 @@ void RefBase::incStrong(const void* id) const
    const_cast<RefBase*>(this)->onFirstRef();
    const_cast<RefBase*>(this)->onFirstRef();
}
}


void RefBase::destroy() const {
    delete this;
}

void RefBase::decStrong(const void* id) const
void RefBase::decStrong(const void* id) const
{
{
    weakref_impl* const refs = mRefs;
    weakref_impl* const refs = mRefs;
@@ -361,7 +363,11 @@ void RefBase::decStrong(const void* id) const
    if (c == 1) {
    if (c == 1) {
        const_cast<RefBase*>(this)->onLastStrongRef(id);
        const_cast<RefBase*>(this)->onLastStrongRef(id);
        if ((refs->mFlags&OBJECT_LIFETIME_WEAK) != OBJECT_LIFETIME_WEAK) {
        if ((refs->mFlags&OBJECT_LIFETIME_WEAK) != OBJECT_LIFETIME_WEAK) {
            destroy();
            if (refs->mDestroyer) {
                refs->mDestroyer->destroy(this);
            } else {
                delete this;
            }
        }
        }
    }
    }
    refs->decWeak(id);
    refs->decWeak(id);
@@ -394,7 +400,9 @@ int32_t RefBase::getStrongCount() const
    return mRefs->mStrong;
    return mRefs->mStrong;
}
}



void RefBase::setDestroyer(RefBase::Destroyer* destroyer) {
    mRefs->mDestroyer = destroyer;
}


RefBase* RefBase::weakref_type::refBase() const
RefBase* RefBase::weakref_type::refBase() const
{
{
@@ -420,7 +428,11 @@ void RefBase::weakref_type::decWeak(const void* id)
    if ((impl->mFlags&OBJECT_LIFETIME_WEAK) != OBJECT_LIFETIME_WEAK) {
    if ((impl->mFlags&OBJECT_LIFETIME_WEAK) != OBJECT_LIFETIME_WEAK) {
        if (impl->mStrong == INITIAL_STRONG_VALUE) {
        if (impl->mStrong == INITIAL_STRONG_VALUE) {
            if (impl->mBase) {
            if (impl->mBase) {
                impl->mBase->destroy();
                if (impl->mDestroyer) {
                    impl->mDestroyer->destroy(impl->mBase);
                } else {
                    delete impl->mBase;
                }
            }
            }
        } else {
        } else {
            // LOGV("Freeing refs %p of old RefBase %p\n", this, impl->mBase);
            // LOGV("Freeing refs %p of old RefBase %p\n", this, impl->mBase);
@@ -430,7 +442,11 @@ void RefBase::weakref_type::decWeak(const void* id)
        impl->mBase->onLastWeakRef(id);
        impl->mBase->onLastWeakRef(id);
        if ((impl->mFlags&OBJECT_LIFETIME_FOREVER) != OBJECT_LIFETIME_FOREVER) {
        if ((impl->mFlags&OBJECT_LIFETIME_FOREVER) != OBJECT_LIFETIME_FOREVER) {
            if (impl->mBase) {
            if (impl->mBase) {
                impl->mBase->destroy();
                if (impl->mDestroyer) {
                    impl->mDestroyer->destroy(impl->mBase);
                } else {
                    delete impl->mBase;
                }
            }
            }
        }
        }
    }
    }
+3 −2
Original line number Original line Diff line number Diff line
@@ -61,6 +61,7 @@ Layer::Layer(SurfaceFlinger* flinger,
        mBufferManager(mTextureManager),
        mBufferManager(mTextureManager),
        mWidth(0), mHeight(0), mNeedsScaling(false), mFixedSize(false)
        mWidth(0), mHeight(0), mNeedsScaling(false), mFixedSize(false)
{
{
    setDestroyer(this);
}
}


Layer::~Layer()
Layer::~Layer()
@@ -77,8 +78,8 @@ Layer::~Layer()
    }
    }
}
}


void Layer::destroy() const {
void Layer::destroy(RefBase const* base) {
    mFlinger->destroyLayer(this);
    mFlinger->destroyLayer(static_cast<LayerBase const*>(base));
}
}


status_t Layer::setToken(const sp<UserClient>& userClient,
status_t Layer::setToken(const sp<UserClient>& userClient,
+2 −2
Original line number Original line Diff line number Diff line
@@ -44,7 +44,7 @@ class UserClient;


// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------


class Layer : public LayerBaseClient
class Layer : public LayerBaseClient, private RefBase::Destroyer
{
{
public:
public:
            Layer(SurfaceFlinger* flinger, DisplayID display,
            Layer(SurfaceFlinger* flinger, DisplayID display,
@@ -92,7 +92,7 @@ public:
        return mFreezeLock; }
        return mFreezeLock; }


protected:
protected:
    virtual void destroy() const;
    virtual void destroy(RefBase const* base);
    virtual void dump(String8& result, char* scratch, size_t size) const;
    virtual void dump(String8& result, char* scratch, size_t size) const;


private:
private: