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

Commit 64c4c1c1 authored by Yang Ni's avatar Yang Ni Committed by Gerrit Code Review
Browse files

Merge "Added CloseGuard for BaseObj"

parents 41014488 eb4dd08e
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -380,6 +380,7 @@ public class Allocation extends BaseObj {
            Log.e(RenderScript.LOG_TAG, "Couldn't invoke registerNativeAllocation:" + e);
            throw new RSRuntimeException("Couldn't invoke registerNativeAllocation:" + e);
        }
        guard.open("destroy");
    }

    Allocation(long id, RenderScript rs, Type t, int usage, MipmapControl mips) {
@@ -1915,6 +1916,7 @@ public class Allocation extends BaseObj {
            if (type.getID(rs) == 0) {
                throw new RSInvalidStateException("Bad Type");
            }
            // TODO: What if there is an exception after this? The native allocation would leak.
            long id = rs.nAllocationCreateTyped(type.getID(rs), mips.mID, usage, 0);
            if (id == 0) {
                throw new RSRuntimeException("Allocation creation failed.");
+11 −2
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package android.renderscript;

import dalvik.system.CloseGuard;
import java.util.concurrent.locks.ReentrantReadWriteLock;

/**
@@ -69,6 +70,7 @@ public class BaseObj {
    }

    private long mID;
    final CloseGuard guard = CloseGuard.get();
    private boolean mDestroyed;
    private String mName;
    RenderScript mRS;
@@ -119,6 +121,7 @@ public class BaseObj {
        }

        if (shouldDestroy) {
            guard.close();
            // must include nObjDestroy in the critical section
            ReentrantReadWriteLock.ReadLock rlock = mRS.mRWLock.readLock();
            rlock.lock();
@@ -133,9 +136,15 @@ public class BaseObj {
    }

    protected void finalize() throws Throwable {
        try {
            if (guard != null) {
                guard.warnIfOpen();
            }
            helpDestroy();
        } finally {
            super.finalize();
        }
    }

    /**
     * Frees any native resources associated with this object.  The
+2 −0
Original line number Diff line number Diff line
@@ -808,6 +808,7 @@ public class Element extends BaseObj {
            mSize += mElements[ct].mSize * mArraySizes[ct];
        }
        updateVisibleSubElements();
        guard.open("destroy");
    }

    Element(long id, RenderScript rs, DataType dt, DataKind dk, boolean norm, int size) {
@@ -827,6 +828,7 @@ public class Element extends BaseObj {
        mKind = dk;
        mNormalized = norm;
        mVectorSize = size;
        guard.open("destroy");
    }

    Element(long id, RenderScript rs) {
+1 −0
Original line number Diff line number Diff line
@@ -170,6 +170,7 @@ public class FileA3D extends BaseObj {
    FileA3D(long id, RenderScript rs, InputStream stream) {
        super(id, rs);
        mInputStream = stream;
        guard.open("destroy");
    }

    private void initEntries() {
+1 −0
Original line number Diff line number Diff line
@@ -150,6 +150,7 @@ public class Font extends BaseObj {

    Font(long id, RenderScript rs) {
        super(id, rs);
        guard.open("destroy");
    }

    /**
Loading