Skip to content
Snippets Groups Projects
Commit 274403c9 authored by Tobias Pietzsch's avatar Tobias Pietzsch
Browse files

Add a full clear() to BlockingFetchQueues. The old clear(), now renamed to

clearToPrefetch moves stuff from the per-priority queues to the prefetch
deque.
parent b5e380f3
Branches
Tags
No related merge requests found
...@@ -204,7 +204,7 @@ public final class LoadingVolatileCache< K, V extends VolatileCacheValue > imple ...@@ -204,7 +204,7 @@ public final class LoadingVolatileCache< K, V extends VolatileCacheValue > imple
@Override @Override
public void prepareNextFrame() public void prepareNextFrame()
{ {
queue.clear(); queue.clearToPrefetch();
cache.cleanUp(); cache.cleanUp();
++currentQueueFrame; ++currentQueueFrame;
} }
...@@ -245,10 +245,9 @@ public final class LoadingVolatileCache< K, V extends VolatileCacheValue > imple ...@@ -245,10 +245,9 @@ public final class LoadingVolatileCache< K, V extends VolatileCacheValue > imple
*/ */
public void invalidateAll() public void invalidateAll()
{ {
queue.clear();
cache.invalidateAll(); cache.invalidateAll();
prepareNextFrame(); prepareNextFrame();
// TODO: add a full clear to BlockingFetchQueues.
// (BlockingFetchQueues.clear() moves stuff to the prefetchQueue.)
} }
public FetcherThreads< K > getFetcherThreads() public FetcherThreads< K > getFetcherThreads()
......
...@@ -39,7 +39,7 @@ import java.util.concurrent.locks.ReentrantLock; ...@@ -39,7 +39,7 @@ import java.util.concurrent.locks.ReentrantLock;
* {@link #put(Object, int, boolean)} with a priority and added to one of the * {@link #put(Object, int, boolean)} with a priority and added to one of the
* queues, accordingly. {@link #take()} returns an element from the highest * queues, accordingly. {@link #take()} returns an element from the highest
* priority non-empty queue. Furthermore, there is a prefetch deque of bounded * priority non-empty queue. Furthermore, there is a prefetch deque of bounded
* size to provides elements when all the queues are exhausted. {@link #clear()} * size to provides elements when all the queues are exhausted. {@link #clearToPrefetch()}
* empties all queues, and moves the removed elements to the prefetch queue. * empties all queues, and moves the removed elements to the prefetch queue.
* <p> * <p>
* Locking is adapted from {@link ArrayBlockingQueue}. * Locking is adapted from {@link ArrayBlockingQueue}.
...@@ -175,11 +175,11 @@ public class BlockingFetchQueues< E > ...@@ -175,11 +175,11 @@ public class BlockingFetchQueues< E >
} }
/** /**
* Atomically removes all of the elements from this queue. The queue will be * Atomically removes all of the elements from this queue. All queues will
* empty after this call returns. Removed elements are moved to the * be empty after this call returns. Removed elements are moved to the
* {@link #prefetch} deque. * {@link #prefetch} deque.
*/ */
public void clear() public void clearToPrefetch()
{ {
final ReentrantLock lock = this.lock; final ReentrantLock lock = this.lock;
lock.lock(); lock.lock();
...@@ -219,7 +219,29 @@ public class BlockingFetchQueues< E > ...@@ -219,7 +219,29 @@ public class BlockingFetchQueues< E >
// update count: only prefetch is non-empty now // update count: only prefetch is non-empty now
count = prefetch.size(); count = prefetch.size();
// System.out.println( "prefetch size after clear = " + prefetch.size() ); // System.out.println( "prefetch size after clearToPrefetch = " + prefetch.size() );
}
finally
{
lock.unlock();
}
}
/**
* Atomically removes all of the elements from this queue. All queues, as
* well as the {@link #prefetch} deque, will be empty after this call
* returns.
*/
public void clear()
{
final ReentrantLock lock = this.lock;
lock.lock();
try
{
for ( final ArrayDeque< E > queue : queues )
queue.clear();
prefetch.clear();
count = 0;
} }
finally finally
{ {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment