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