some comment, flush now REMOVES TOKENS.

This commit is contained in:
Federico Ponchio 2011-06-06 15:54:47 +00:00
parent 62a5d3856d
commit 987a4e0234
2 changed files with 7 additions and 7 deletions

View File

@ -44,11 +44,10 @@ class Cache: public Provider<Token> {
///return true if the cache is waiting for priority to change ///return true if the cache is waiting for priority to change
bool isWaiting() { return input->check_queue.isWaiting(); } 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() { void flush() {
std::vector<Token *> tokens; std::vector<Token *> tokens;
{ {
QMutexLocker locker(&(this->heap_lock));
for(int i = 0; i < this->heap.size(); i++) { for(int i = 0; i < this->heap.size(); i++) {
Token *token = &(this->heap[i]); Token *token = &(this->heap[i]);
tokens.push_back(token); tokens.push_back(token);
@ -63,7 +62,6 @@ class Cache: public Provider<Token> {
assert(s_curr == 0); assert(s_curr == 0);
{ {
QMutexLocker locker(&(input->heap_lock));
for(unsigned int i = 0; i < tokens.size(); i++) { for(unsigned int i = 0; i < tokens.size(); i++) {
input->heap.push(tokens[i]); input->heap.push(tokens[i]);
} }

View File

@ -47,9 +47,7 @@ class Controller {
///WARNING: migh stall for the time needed to drop tokens from cache. ///WARNING: migh stall for the time needed to drop tokens from cache.
//FUNCTOR has bool operator(Token *) and return true to remove //FUNCTOR has bool operator(Token *) and return true to remove
template<class FUNCTOR> void removeTokens(FUNCTOR functor) { template<class FUNCTOR> void removeTokens(FUNCTOR functor) {
stop(); stop(); //this might actually be unnecessary if you mark tokens to be removed
std::vector<Token *> tmp;
for(quint32 i = 0; i < caches.size(); i++) for(quint32 i = 0; i < caches.size(); i++)
caches[i]->flush(functor); caches[i]->flush(functor);
@ -124,11 +122,15 @@ class Controller {
caches[i]->heap_lock.unlock(); caches[i]->heap_lock.unlock();
paused = false; paused = false;
} }
///empty all caches ///empty all caches AND REMOVES ALL TOKENS!
void flush() { void flush() {
pause();
for(int i = (int)caches.size()-1; i >= 0; i--) for(int i = (int)caches.size()-1; i >= 0; i--)
caches[i]->flush(); caches[i]->flush();
provider.heap.clear();
resume();
} }
bool isWaiting() { bool isWaiting() {
for(int i = (int)caches.size() -1; i >= 0; i--) { for(int i = (int)caches.size() -1; i >= 0; i--) {
if(!caches[i]->input->check_queue.isWaiting()) return false; if(!caches[i]->input->check_queue.isWaiting()) return false;