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

Commit 37355870 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Fix a minor data race in PropertyInvalidatedCache" into main

parents 78e4429c 9b36f3fd
Loading
Loading
Loading
Loading
+30 −23
Original line number Diff line number Diff line
@@ -974,8 +974,8 @@ public class PropertyInvalidatedCache<Query, Result> {
        //
        // If the "update" boolean is true, then the property is registered with the nonce store
        // before the associated handle is fetched.
        private int initialize(boolean update) {
            synchronized (mLock) {
        @GuardedBy("mLock")
        private int initializeLocked(boolean update) {
            int handle = mHandle;
            if (handle == NonceStore.INVALID_NONCE_INDEX) {
                if (mStore == null) {
@@ -996,7 +996,6 @@ public class PropertyInvalidatedCache<Query, Result> {
            }
            return handle;
        }
        }

        // Fetch the nonce from shared memory.  If the shared memory is not available, return
        // UNSET.  If the shared memory is available but the nonce name is not known (it may not
@@ -1005,11 +1004,13 @@ public class PropertyInvalidatedCache<Query, Result> {
        long getNonceInternal() {
            int handle = mHandle;
            if (handle == NonceStore.INVALID_NONCE_INDEX) {
                handle = initialize(false);
                synchronized (mLock) {
                    handle = initializeLocked(false);
                    if (handle == NonceStore.INVALID_NONCE_INDEX) {
                        return NONCE_UNSET;
                    }
                }
            }
            return mStore.getNonce(handle);
        }

@@ -1019,10 +1020,16 @@ public class PropertyInvalidatedCache<Query, Result> {
        void setNonceInternal(long value) {
            int handle = mHandle;
            if (handle == NonceStore.INVALID_NONCE_INDEX) {
                handle = initialize(true);
                synchronized (mLock) {
                    handle = initializeLocked(true);
                    if (handle == NonceStore.INVALID_NONCE_INDEX) {
                        throw new IllegalStateException("unable to assign nonce handle: " + mName);
                    }
                    // Note that we set the value within the lock, ensuring it takes effect
                    // immediately upon initialization, before any pending getNonce reads.
                    mStore.setNonce(handle, value);
                    return;
                }
            }
            mStore.setNonce(handle, value);
        }