From 987a4e0234b9aed9d655fdd88e4715c2e24acf15 Mon Sep 17 00:00:00 2001 From: ponchio Date: Mon, 6 Jun 2011 15:54:47 +0000 Subject: [PATCH] some comment, flush now REMOVES TOKENS. --- wrap/gcache/cache.h | 4 +--- wrap/gcache/controller.h | 10 ++++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/wrap/gcache/cache.h b/wrap/gcache/cache.h index 674f4a13..c7db7475 100644 --- a/wrap/gcache/cache.h +++ b/wrap/gcache/cache.h @@ -44,11 +44,10 @@ class Cache: public Provider { ///return true if the cache is waiting for priority to change bool isWaiting() { return input->check_queue.isWaiting(); } - ///empty the cache. Make sure no resource is locked before calling this. + ///empty the cache. Make sure no resource is locked before calling this. Require pause or stop before. void flush() { std::vector tokens; { - QMutexLocker locker(&(this->heap_lock)); for(int i = 0; i < this->heap.size(); i++) { Token *token = &(this->heap[i]); tokens.push_back(token); @@ -63,7 +62,6 @@ class Cache: public Provider { assert(s_curr == 0); { - QMutexLocker locker(&(input->heap_lock)); for(unsigned int i = 0; i < tokens.size(); i++) { input->heap.push(tokens[i]); } diff --git a/wrap/gcache/controller.h b/wrap/gcache/controller.h index 59b6cd36..62e2eb32 100644 --- a/wrap/gcache/controller.h +++ b/wrap/gcache/controller.h @@ -47,9 +47,7 @@ class Controller { ///WARNING: migh stall for the time needed to drop tokens from cache. //FUNCTOR has bool operator(Token *) and return true to remove template void removeTokens(FUNCTOR functor) { - stop(); - - std::vector tmp; + stop(); //this might actually be unnecessary if you mark tokens to be removed for(quint32 i = 0; i < caches.size(); i++) caches[i]->flush(functor); @@ -124,11 +122,15 @@ class Controller { caches[i]->heap_lock.unlock(); paused = false; } - ///empty all caches + ///empty all caches AND REMOVES ALL TOKENS! void flush() { + pause(); for(int i = (int)caches.size()-1; i >= 0; i--) caches[i]->flush(); + provider.heap.clear(); + resume(); } + bool isWaiting() { for(int i = (int)caches.size() -1; i >= 0; i--) { if(!caches[i]->input->check_queue.isWaiting()) return false;