From d928d6837dee4df30b06529164326722075da063 Mon Sep 17 00:00:00 2001 From: Romain Guy <> Date: Tue, 31 Mar 2009 17:52:16 -0700 Subject: AI 143890: Fixes #1749387. Improve the pooling of the VelocityTracker class. This introduces a new, hidden, API for pooling objects easily. BUG=1749387 Automated import of CL 143890 --- core/java/android/util/SynchronizedPool.java | 48 ++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 core/java/android/util/SynchronizedPool.java (limited to 'core/java/android/util/SynchronizedPool.java') diff --git a/core/java/android/util/SynchronizedPool.java b/core/java/android/util/SynchronizedPool.java new file mode 100644 index 0000000..651e0c3 --- /dev/null +++ b/core/java/android/util/SynchronizedPool.java @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2009 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.util; + +/** + * + * @hide + */ +class SynchronizedPool> implements Pool { + private final Pool mPool; + private final Object mLock; + + public SynchronizedPool(Pool pool) { + mPool = pool; + mLock = this; + } + + public SynchronizedPool(Pool pool, Object lock) { + mPool = pool; + mLock = lock; + } + + public T acquire() { + synchronized (mLock) { + return mPool.acquire(); + } + } + + public void release(T element) { + synchronized (mLock) { + mPool.release(element); + } + } +} -- cgit v1.1