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
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<Token *> 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<Token> {
assert(s_curr == 0);
{
QMutexLocker locker(&(input->heap_lock));
for(unsigned int i = 0; i < tokens.size(); 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.
//FUNCTOR has bool operator(Token *) and return true to remove
template<class FUNCTOR> void removeTokens(FUNCTOR functor) {
stop();
std::vector<Token *> 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;