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

Commit 2405c278 authored by Brad Fitzpatrick's avatar Brad Fitzpatrick
Browse files

android.os.Message: respect sPoolSize

Also rename some static members from mFoo to sFoo.

Bug: http://code.google.com/p/android/issues/detail?id=13866
Change-Id: I5c5075eb6f529d1534c7aa72b6881873cd08676a
parent 996de2dd
Loading
Loading
Loading
Loading
+13 −13
Original line number Diff line number Diff line
@@ -85,9 +85,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;
    
@@ -96,11 +96,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;
            }
        }
@@ -237,12 +238,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++;
            }
        }
    }
@@ -453,4 +454,3 @@ public final class Message implements Parcelable {
        replyTo = Messenger.readMessengerOrNullFromParcel(source);
    }
}