[thread-safety] understand that Pools.Pool.acquire returns ownership

Summary: We had a model for `Pools.SimplePool`, but were missing models for `Pools.Pool`. Since `SimplePool` and `SynchronizedPool` both extend `Pool`, modeling it should cover all of the cases.

Reviewed By: ngorogiannis

Differential Revision: D5236280

fbshipit-source-id: 9bbdb25
master
Sam Blackshear 8 years ago committed by Facebook Github Bot
parent d4d8db4025
commit 03703e316c

@ -330,7 +330,7 @@ module TransferFunctions (CFG : ProcCfg.S) = struct
| ("android.app.Activity" | "android.view.View"), "findViewById" ->
(* assume findViewById creates fresh View's (note: not always true) *)
true
| "android.support.v4.util.Pools$SimplePool", "acquire" ->
| "android.support.v4.util.Pools$Pool", "acquire" ->
(* a pool should own all of its objects *)
true
| _ ->

@ -24,6 +24,7 @@ import android.support.v4.util.Pools.SynchronizedPool;
import android.support.v4.util.SparseArrayCompat;
import android.util.SparseArray;
import android.support.v4.util.SimpleArrayMap;
import android.support.v4.util.Pools;
import android.support.v4.util.Pools.SimplePool;
class ContainerWrapper {
@ -175,7 +176,7 @@ class Containers {
static boolean sUsePooling;
private Obj poolWrapper() {
private Obj poolWrapper1() {
Obj obj = sUsePooling ? sPool.acquire() : null;
if (obj == null) {
obj = new Obj();
@ -184,8 +185,28 @@ class Containers {
return obj;
}
void poolWrapperOk() {
Obj obj = poolWrapper();
void poolWrapperOk1() {
Obj obj = poolWrapper1();
obj.f = new Object();
}
private Pools.Pool<Obj> mPool;
private boolean mIsSync;
private Obj poolWrapper2() {
Obj item;
if (mIsSync) {
synchronized (this) {
item = mPool.acquire();
}
} else {
item = mPool.acquire();
}
return item;
}
void poolWrapperOk2() {
Obj obj = poolWrapper2();
obj.f = new Object();
}
@ -265,4 +286,5 @@ class Containers {
}
simplePool.release(a);
}
}

Loading…
Cancel
Save