fixed flush
This commit is contained in:
parent
129d4edbaf
commit
2ad7d34050
|
@ -1,12 +1,14 @@
|
|||
#ifndef GCACHE_CACHE_H
|
||||
#define GCACHE_CACHE_H
|
||||
|
||||
#include <iostream>
|
||||
#include <limits.h>
|
||||
#include <vector>
|
||||
|
||||
#include <QThread>
|
||||
#include "provider.h"
|
||||
|
||||
using namespace std;
|
||||
/* this cache system enforce the rule that the items in a cache are always in all the cache below */
|
||||
/* two mechanism to remove tokens from the cache:
|
||||
1) set token count to something low
|
||||
|
@ -79,7 +81,7 @@ class Cache: public Provider<Token> {
|
|||
if(functor(token)) { //drop it
|
||||
tokens.push_back(token);
|
||||
s_curr -= drop(token);
|
||||
assert(!token->count >= Token::LOCKED);
|
||||
assert(token->count < Token::LOCKED);
|
||||
if(final)
|
||||
token->count.testAndSetOrdered(Token::READY, Token::CACHE);
|
||||
} else
|
||||
|
|
|
@ -47,13 +47,12 @@ 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(); //this might actually be unnecessary if you mark tokens to be removed
|
||||
for(quint32 i = 0; i < caches.size(); i++)
|
||||
pause(); //this might actually be unnecessary if you mark tokens to be removed
|
||||
for(int i = (int)caches.size()-1; i >= 0; i--)
|
||||
caches[i]->flush(functor);
|
||||
|
||||
provider.flush(functor);
|
||||
|
||||
start();
|
||||
resume();
|
||||
}
|
||||
|
||||
///if more tokens than m present in the provider, lowest priority ones will be removed
|
||||
|
@ -109,17 +108,25 @@ class Controller {
|
|||
|
||||
void pause() {
|
||||
if(paused) return;
|
||||
provider.heap_lock.lock();
|
||||
provider.check_queue.lock();
|
||||
for(unsigned int i = 0; i < caches.size()-1; i++)
|
||||
caches[i]->check_queue.lock();
|
||||
/* provider.heap_lock.lock();
|
||||
for(unsigned int i = 0; i < caches.size(); i++)
|
||||
caches[i]->heap_lock.lock();
|
||||
caches[i]->heap_lock.lock(); */
|
||||
paused = true;
|
||||
}
|
||||
|
||||
void resume() {
|
||||
if(!paused) return;
|
||||
provider.heap_lock.unlock();
|
||||
provider.check_queue.unlock();
|
||||
for(unsigned int i = 0; i < caches.size()-1; i++)
|
||||
caches[i]->check_queue.unlock();
|
||||
|
||||
|
||||
/* provider.heap_lock.unlock();
|
||||
for(unsigned int i = 0; i < caches.size(); i++)
|
||||
caches[i]->heap_lock.unlock();
|
||||
caches[i]->heap_lock.unlock(); */
|
||||
paused = false;
|
||||
}
|
||||
///empty all caches AND REMOVES ALL TOKENS!
|
||||
|
|
|
@ -255,7 +255,7 @@ class PtrDHeap {
|
|||
heap.push_back(Item(t));
|
||||
}
|
||||
int size() { return heap.size(); }
|
||||
void resize(int n) { assert(n < (int)heap.size()); return heap.resize(n, Item(NULL)); }
|
||||
void resize(int n) { assert(n <= (int)heap.size()); return heap.resize(n, Item(NULL)); }
|
||||
void clear() { heap.clear(); }
|
||||
T &min() { Item &i = heap.min(); return *i.value; }
|
||||
T *popMin() { Item i = heap.popMin(); return i.value; }
|
||||
|
|
|
@ -99,6 +99,12 @@ class QDoor {
|
|||
m.unlock();
|
||||
return w;
|
||||
}
|
||||
void lock() { //prevend door opening and entering
|
||||
m.lock();
|
||||
}
|
||||
void unlock() { //reverse effect of lock
|
||||
m.unlock();
|
||||
}
|
||||
private:
|
||||
QMutex m;
|
||||
QWaitCondition c;
|
||||
|
|
Loading…
Reference in New Issue