am a206efcf: Merge "android.os.Message: respect sPoolSize"
* commit 'a206efcf8d2e56cbd0d1de125b29b45fc6cc8431':
android.os.Message: respect sPoolSize
diff --git a/core/java/android/os/Message.java b/core/java/android/os/Message.java
index 49b72fe..7d128ec 100644
--- a/core/java/android/os/Message.java
+++ b/core/java/android/os/Message.java
@@ -85,9 +85,9 @@
// 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 @@
* 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 @@
* 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 @@
replyTo = Messenger.readMessengerOrNullFromParcel(source);
}
}
-