am 83ec22a8: am af8c19e7: am 7d85b543: Merge "Make DelegateManager thread safe" into mnc-dev

* commit '83ec22a8826f3939b8161de5d68ef35b5f2e7c2e':
  Make DelegateManager thread safe
This commit is contained in:
Diego Perez
2015-08-11 21:02:30 +00:00
committed by Android Git Automerger

View File

@ -97,13 +97,13 @@ public final class DelegateManager<T> {
* @return the delegate or null if not found. * @return the delegate or null if not found.
*/ */
@Nullable @Nullable
public T getDelegate(long native_object) { public synchronized T getDelegate(long native_object) {
if (native_object > 0) { if (native_object > 0) {
T delegate = mDelegates.get(native_object); T delegate = mDelegates.get(native_object);
if (Debug.DEBUG) { if (Debug.DEBUG) {
if (delegate == null) { if (delegate == null) {
System.out.println("Unknown " + mClass.getSimpleName() + " with int " + System.err.println("Unknown " + mClass.getSimpleName() + " with int " +
native_object); native_object);
} }
} }
@ -119,14 +119,18 @@ public final class DelegateManager<T> {
* @param newDelegate the delegate to add * @param newDelegate the delegate to add
* @return a unique native int to identify the delegate * @return a unique native int to identify the delegate
*/ */
public long addNewDelegate(T newDelegate) { public synchronized long addNewDelegate(T newDelegate) {
long native_object = ++mDelegateCounter; long native_object = ++mDelegateCounter;
mDelegates.put(native_object, newDelegate); mDelegates.put(native_object, newDelegate);
assert !mJavaReferences.contains(newDelegate); assert !mJavaReferences.contains(newDelegate);
mJavaReferences.add(newDelegate); mJavaReferences.add(newDelegate);
if (Debug.DEBUG) { 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; return native_object;
@ -136,7 +140,7 @@ public final class DelegateManager<T> {
* Removes the main reference on the given delegate. * Removes the main reference on the given delegate.
* @param native_object the native integer representing the 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); T delegate = getDelegate(native_object);
if (Debug.DEBUG) { if (Debug.DEBUG) {