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

Commit bfbd5668 authored by Jared Duke's avatar Jared Duke Committed by Android (Google) Code Review
Browse files

Merge "Use double-checked locking in (Java) Singleton type" into main

parents 035a7f01 f10f941c
Loading
Loading
Loading
Loading
+9 −5
Original line number Diff line number Diff line
@@ -33,17 +33,21 @@ public abstract class Singleton<T> {
    }

    @UnsupportedAppUsage
    private T mInstance;
    private volatile T mInstance;

    protected abstract T create();

    @UnsupportedAppUsage
    public final T get() {
        T instance = mInstance;
        if (instance == null) {
            synchronized (this) {
                if (mInstance == null) {
                    mInstance = create();
                }
            return mInstance;
                instance = mInstance;
            }
        }
        return instance;
    }
}