diff --git a/wrap/gcache/cache.h b/wrap/gcache/cache.h index c7db7475..6f28cfe7 100644 --- a/wrap/gcache/cache.h +++ b/wrap/gcache/cache.h @@ -1,12 +1,14 @@ #ifndef GCACHE_CACHE_H #define GCACHE_CACHE_H +#include #include #include #include #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 { 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 diff --git a/wrap/gcache/controller.h b/wrap/gcache/controller.h index 62e2eb32..8f13bf81 100644 --- a/wrap/gcache/controller.h +++ b/wrap/gcache/controller.h @@ -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 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! diff --git a/wrap/gcache/dheap.h b/wrap/gcache/dheap.h index faf6d060..2e474139 100644 --- a/wrap/gcache/dheap.h +++ b/wrap/gcache/dheap.h @@ -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; } diff --git a/wrap/gcache/door.h b/wrap/gcache/door.h index ed0e687c..7dfbca1d 100644 --- a/wrap/gcache/door.h +++ b/wrap/gcache/door.h @@ -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;