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

Commit adb52ef7 authored by Jason Sams's avatar Jason Sams Committed by Gerrit Code Review
Browse files

Merge "Implement finalizer for RS contexts."

parents 0a7936b7 d22a6f09
Loading
Loading
Loading
Loading
+35 −13
Original line number Diff line number Diff line
@@ -938,6 +938,8 @@ public class RenderScript {

    long     mDev;
    long     mContext;
    private boolean mDestroyed = false;

    @SuppressWarnings({"FieldCanBeLocal"})
    MessageThread mMessageThread;

@@ -1382,14 +1384,16 @@ public class RenderScript {
        nContextFinish();
    }

    /**
     * Destroys this RenderScript context.  Once this function is called,
     * using this context or any objects belonging to this context is
     * illegal.
     *
     */
    public void destroy() {
        validate();
    private void helpDestroy() {
        boolean shouldDestroy = false;
        synchronized(this) {
            if (!mDestroyed) {
                shouldDestroy = true;
                mDestroyed = true;
            }
        }

        if (shouldDestroy) {
            nContextFinish();

            nContextDeinitToClient(mContext);
@@ -1404,6 +1408,24 @@ public class RenderScript {
            nDeviceDestroy(mDev);
            mDev = 0;
        }
    }

    protected void finalize() throws Throwable {
        helpDestroy();
        super.finalize();
    }


    /**
     * Destroys this RenderScript context.  Once this function is called,
     * using this context or any objects belonging to this context is
     * illegal.
     *
     */
    public void destroy() {
        validate();
        helpDestroy();
    }

    boolean isAlive() {
        return mContext != 0;