summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Diego Perez <diegoperez@google.com> 2015-08-11 20:49:51 +0000
committer Android Git Automerger <android-git-automerger@android.com> 2015-08-11 20:49:51 +0000
commitaf8c19e770717b209ca0c0cf0549eaeff8f1c78e (patch)
treef8552706eefe743fe35fbb896a4c61103056a2ce
parentbb03bf055437c21180026b8c8227c52ca2809286 (diff)
parent7d85b5435d01f8d4856a718d655e30fb5a703560 (diff)
am 7d85b543: Merge "Make DelegateManager thread safe" into mnc-dev
* commit '7d85b5435d01f8d4856a718d655e30fb5a703560': Make DelegateManager thread safe
-rw-r--r--tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/DelegateManager.java16
1 files changed, 10 insertions, 6 deletions
diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/DelegateManager.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/DelegateManager.java
index 47258b6ac72b..baf2e2e11564 100644
--- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/DelegateManager.java
+++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/DelegateManager.java
@@ -97,13 +97,13 @@ public final class DelegateManager<T> {
* @return the delegate or null if not found.
*/
@Nullable
- public T getDelegate(long native_object) {
+ public synchronized T getDelegate(long native_object) {
if (native_object > 0) {
- T delegate = mDelegates.get(native_object);
+ T delegate = mDelegates.get(native_object);
if (Debug.DEBUG) {
if (delegate == null) {
- System.out.println("Unknown " + mClass.getSimpleName() + " with int " +
+ System.err.println("Unknown " + mClass.getSimpleName() + " with int " +
native_object);
}
}
@@ -119,14 +119,18 @@ public final class DelegateManager<T> {
* @param newDelegate the delegate to add
* @return a unique native int to identify the delegate
*/
- public long addNewDelegate(T newDelegate) {
+ public synchronized long addNewDelegate(T newDelegate) {
long native_object = ++mDelegateCounter;
+
mDelegates.put(native_object, newDelegate);
assert !mJavaReferences.contains(newDelegate);
mJavaReferences.add(newDelegate);
if (Debug.DEBUG) {
- System.out.println("New " + mClass.getSimpleName() + " with int " + native_object);
+ System.out.println(
+ "New " + mClass.getSimpleName() + " " +
+ "with int " +
+ native_object);
}
return native_object;
@@ -136,7 +140,7 @@ public final class DelegateManager<T> {
* Removes the main reference on the given delegate.
* @param native_object the native integer representing the delegate.
*/
- public void removeJavaReferenceFor(long native_object) {
+ public synchronized void removeJavaReferenceFor(long native_object) {
T delegate = getDelegate(native_object);
if (Debug.DEBUG) {