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

Commit 0ebc6b37 authored by Jason Sams's avatar Jason Sams
Browse files

Force merge of remaining KLP changes to fix build.

Change-Id: I389a23c6615663c325980fcb30350ea6635d2d17
parent fc15f899
Loading
Loading
Loading
Loading
+19 −3
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package android.renderscript;
import java.io.File;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.concurrent.locks.ReentrantReadWriteLock;

import android.content.Context;
import android.content.pm.ApplicationInfo;
@@ -165,6 +166,7 @@ public class RenderScript {
    }

    ContextType mContextType;
    ReentrantReadWriteLock mRWLock;

    // Methods below are wrapped to protect the non-threadsafe
    // lockless fifo.
@@ -192,7 +194,18 @@ public class RenderScript {
    native void rsnContextDestroy(int con);
    synchronized void nContextDestroy() {
        validate();
        rsnContextDestroy(mContext);

        // take teardown lock
        // teardown lock can only be taken when no objects are being destroyed
        ReentrantReadWriteLock.WriteLock wlock = mRWLock.writeLock();
        wlock.lock();

        int curCon = mContext;
        // context is considered dead as of this point
        mContext = 0;

        wlock.unlock();
        rsnContextDestroy(curCon);
    }
    native void rsnContextSetSurface(int con, int w, int h, Surface sur);
    synchronized void nContextSetSurface(int w, int h, Surface sur) {
@@ -277,8 +290,9 @@ public class RenderScript {
        validate();
        return rsnGetName(mContext, obj);
    }
    // nObjDestroy is explicitly _not_ synchronous to prevent crashes in finalizers
    native void rsnObjDestroy(int con, int id);
    synchronized void nObjDestroy(int id) {
    void nObjDestroy(int id) {
        // There is a race condition here.  The calling code may be run
        // by the gc while teardown is occuring.  This protects againts
        // deleting dead objects.
@@ -1150,6 +1164,7 @@ public class RenderScript {
        if (ctx != null) {
            mApplicationContext = ctx.getApplicationContext();
        }
        mRWLock = new ReentrantReadWriteLock();
    }

    /**
@@ -1244,6 +1259,8 @@ public class RenderScript {
     */
    public void destroy() {
        validate();
        nContextFinish();

        nContextDeinitToClient(mContext);
        mMessageThread.mRun = false;
        try {
@@ -1252,7 +1269,6 @@ public class RenderScript {
        }

        nContextDestroy();
        mContext = 0;

        nDeviceDestroy(mDev);
        mDev = 0;