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

Commit 8ebabfb3 authored by Avichal Rakesh's avatar Avichal Rakesh Committed by Automerger Merge Worker
Browse files

Merge "Ensure that two threads cannot simultaneously close SurfaceImage" into...

Merge "Ensure that two threads cannot simultaneously close SurfaceImage" into tm-dev am: 2a3064a2 am: e8bffd4d

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/18152523



Change-Id: Idcf7131f5fc95b11cbdccf9baa98dd4b88d373e6
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents 3c8f5db8 e8bffd4d
Loading
Loading
Loading
Loading
+8 −1
Original line number Diff line number Diff line
@@ -643,6 +643,9 @@ public class ImageReader implements AutoCloseable {

    /**
     * <p>Return the frame to the ImageReader for reuse.</p>
     *
     * This method should only be called via {@link SurfaceImage#close} which ensures that image
     * closing is atomic.
     */
    private void releaseImage(Image i) {
        if (! (i instanceof SurfaceImage) ) {
@@ -1125,6 +1128,8 @@ public class ImageReader implements AutoCloseable {
    }

    private class SurfaceImage extends android.media.Image {
        private final Object mCloseLock = new Object();

        public SurfaceImage(int format) {
            mFormat = format;
            mHardwareBufferFormat = ImageReader.this.mHardwareBufferFormat;
@@ -1139,8 +1144,10 @@ public class ImageReader implements AutoCloseable {

        @Override
        public void close() {
            synchronized (this.mCloseLock) {
                ImageReader.this.releaseImage(this);
            }
        }

        public ImageReader getReader() {
            return ImageReader.this;