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

Commit 28c7c788 authored by Jason Sams's avatar Jason Sams Committed by Android Git Automerger
Browse files

am a15ac5fe: am adb52ef7: Merge "Implement finalizer for RS contexts."

* commit 'a15ac5fe':
  Implement finalizer for RS contexts.
parents 309b71e5 a15ac5fe
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;