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

Commit 47864180 authored by Brad Fitzpatrick's avatar Brad Fitzpatrick Committed by Android Git Automerger
Browse files

am 6af61b84: am a206efcf: Merge "android.os.Message: respect sPoolSize"

* commit '6af61b84':
  android.os.Message: respect sPoolSize
parents f7f46dda 6af61b84
Loading
Loading
Loading
Loading
+13 −12
Original line number Diff line number Diff line
@@ -96,9 +96,9 @@ public final class Message implements Parcelable {
    // sometimes we store linked lists of these things
    /*package*/ Message next;

    private static Object mPoolSync = new Object();
    private static Message mPool;
    private static int mPoolSize = 0;
    private static final Object sPoolSync = new Object();
    private static Message sPool;
    private static int sPoolSize = 0;

    private static final int MAX_POOL_SIZE = 10;
    
@@ -107,11 +107,12 @@ public final class Message implements Parcelable {
     * avoid allocating new objects in many cases.
     */
    public static Message obtain() {
        synchronized (mPoolSync) {
            if (mPool != null) {
                Message m = mPool;
                mPool = m.next;
        synchronized (sPoolSync) {
            if (sPool != null) {
                Message m = sPool;
                sPool = m.next;
                m.next = null;
                sPoolSize--;
                return m;
            }
        }
@@ -248,12 +249,12 @@ public final class Message implements Parcelable {
     * freed.
     */
    public void recycle() {
        synchronized (mPoolSync) {
            if (mPoolSize < MAX_POOL_SIZE) {
        synchronized (sPoolSync) {
            if (sPoolSize < MAX_POOL_SIZE) {
                clearForRecycle();
                
                next = mPool;
                mPool = this;
                next = sPool;
                sPool = this;
                sPoolSize++;
            }
        }
    }