Fix race condition in CoverView

This commit is contained in:
Christopher Eby 2011-12-22 02:43:47 -06:00
parent e6101d6969
commit c0cf7cefd1

View File

@ -105,7 +105,7 @@ public class Cache<E> {
* *
* @param key The key of the item to touch. * @param key The key of the item to touch.
*/ */
public void touch(long key) public synchronized void touch(long key)
{ {
long[] keys = mKeys; long[] keys = mKeys;
Object[] values = mValues; Object[] values = mValues;
@ -129,7 +129,7 @@ public class Cache<E> {
* @return The item that was discarded, or null if the cache is not full. * @return The item that was discarded, or null if the cache is not full.
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public E discardOldest() public synchronized E discardOldest()
{ {
int count = count(); int count = count();
// Cache is not full. // Cache is not full.
@ -151,7 +151,7 @@ public class Cache<E> {
* existing key in the cache. * existing key in the cache.
* @param value The item. * @param value The item.
*/ */
public void put(long key, E value) public synchronized void put(long key, E value)
{ {
int count = count(); int count = count();
Assert.assertFalse(count == mKeys.length); // must not be full Assert.assertFalse(count == mKeys.length); // must not be full