From e1c9f212dad13de007ce4836f0f8ac931814623c Mon Sep 17 00:00:00 2001 From: cnr-isti-vclab Date: Wed, 14 Dec 2011 17:42:23 +0000 Subject: [PATCH] Updated to use the threading classes defined in wrap/system/multithreading --- wrap/gcache/cache.h | 20 ++++++++++---------- wrap/gcache/controller.h | 4 ++-- wrap/gcache/door.h | 23 ++++++++++++----------- wrap/gcache/provider.h | 15 +++++++-------- 4 files changed, 31 insertions(+), 31 deletions(-) diff --git a/wrap/gcache/cache.h b/wrap/gcache/cache.h index a7d01740..c01e7d60 100644 --- a/wrap/gcache/cache.h +++ b/wrap/gcache/cache.h @@ -6,8 +6,8 @@ #include #include #include +#include -#include #include "provider.h" using namespace std; @@ -91,7 +91,7 @@ public: std::vector tokens; { int count = 0; - QMutexLocker locker(&(this->heap_lock)); + mt::mutexlocker locker(&(this->heap_lock)); for(int k = 0; k < this->heap.size(); k++) { Token *token = &this->heap[k]; if(functor(token)) { //drop it @@ -107,7 +107,7 @@ public: this->heap_dirty = true; } { - QMutexLocker locker(&(input->heap_lock)); + mt::mutexlocker locker(&(input->heap_lock)); for(unsigned int i = 0; i < tokens.size(); i++) { input->heap.push(tokens[i]); } @@ -165,7 +165,7 @@ protected: //1 we need to make room (capacity < current) if(size() > capacity()) { - QMutexLocker locker(&(this->heap_lock)); + mt::mutexlocker locker(&(this->heap_lock)); //2 we have some element not in the upper caches (heap.size() > 0 if(this->heap.size()) { @@ -194,7 +194,7 @@ protected: if(remove) { { - QMutexLocker input_locker(&(input->heap_lock)); + mt::mutexlocker input_locker(&(input->heap_lock)); int size = drop(remove); assert(size >= 0); s_curr -= size; @@ -214,7 +214,7 @@ protected: empty heap is bad: we cannot drop anything to make room, and cache above has nothing to get. this should not happen if we set correct cache sizes, but if it happens.... */ { - QMutexLocker locker(&(this->heap_lock)); + mt::mutexlocker locker(&(this->heap_lock)); this->rebuild(); if(size() > capacity() && this->heap.size() > 0) { last = &(this->heap.min()); //no room, set last so we might check for a swap. @@ -222,7 +222,7 @@ protected: } { - QMutexLocker input_locker(&(input->heap_lock)); + mt::mutexlocker input_locker(&(input->heap_lock)); input->rebuild(); //if dirty rebuild if(input->heap.size()) { //we need something in input to tranfer. Token &first = input->heap.max(); @@ -240,7 +240,7 @@ protected: if(size >= 0) { //success s_curr += size; { - QMutexLocker locker(&(this->heap_lock)); + mt::mutexlocker locker(&(this->heap_lock)); if(final) insert->count.ref(); //now lock is 0 and can be locked @@ -250,7 +250,7 @@ protected: return true; } else { //failed transfer put it back, we will keep trying to transfer it... - QMutexLocker input_locker(&(input->heap_lock)); + mt::mutexlocker input_locker(&(input->heap_lock)); input->heap.push(insert); return false; } @@ -263,7 +263,7 @@ protected: /* template -class Transfer: public QThread { +class Transfer: public mt::thread { public: Transfer(Cache *_cache): cache(_cache) {} private: diff --git a/wrap/gcache/controller.h b/wrap/gcache/controller.h index f3a2e60f..14bd791e 100644 --- a/wrap/gcache/controller.h +++ b/wrap/gcache/controller.h @@ -60,7 +60,7 @@ class Controller { ///if more tokens than m present in the provider, lowest priority ones will be removed void setMaxTokens(int m) { - QMutexLocker l(&provider.heap_lock); + mt::mutexlocker l(&provider.heap_lock); provider.max_tokens = m; } @@ -68,7 +68,7 @@ class Controller { void updatePriorities() { if(tokens.size()) { - QMutexLocker l(&provider.heap_lock); + mt::mutexlocker l(&provider.heap_lock); for(unsigned int i = 0; i < tokens.size(); i++) provider.heap.push(tokens[i]); tokens.clear(); diff --git a/wrap/gcache/door.h b/wrap/gcache/door.h index b51b34d0..29f8ac88 100644 --- a/wrap/gcache/door.h +++ b/wrap/gcache/door.h @@ -25,12 +25,13 @@ #ifndef CACHE_DOOR_H #define CACHE_DOOR_H -#include -#include -#include -#include -#include +#include +#ifdef QT_CORE_LIB +#include +#endif + +#include #define METHOD_2 @@ -38,8 +39,8 @@ class QDoor { private: - QSemaphore door; - QMutex room; //lock when entering. unlock when exiting + mt::semaphore door; + mt::mutex room; //lock when entering. unlock when exiting QAtomicInt key; //keep tracks of door status public: @@ -77,11 +78,11 @@ class QDoor { class QDoor { private: - QSemaphore _open; - QSemaphore _close; + mt::semaphore _open; + mt::semaphore _close; public: - QMutex room; + mt::mutex room; QDoor(): _open(0), _close(1) {} //this means closed void open() { @@ -175,7 +176,7 @@ class QDoor { m.unlock(); } private: - QMutex m; + mt::mutex m; QWaitCondition c; bool doorOpen; bool waiting; diff --git a/wrap/gcache/provider.h b/wrap/gcache/provider.h index cfc637a0..9da0d29d 100644 --- a/wrap/gcache/provider.h +++ b/wrap/gcache/provider.h @@ -1,8 +1,7 @@ #ifndef GCACHE_PROVIDER_H #define GCACHE_PROVIDER_H - -#include +#include #include "dheap.h" #include "door.h" @@ -19,7 +18,7 @@ */ template -class Provider: public QThread { +class Provider: public mt::thread { public: ///holds the resources in this cache but not in the cache above PtrDHeap heap; @@ -28,9 +27,9 @@ class Provider: public QThread { ///signals we need to rebuild heap. bool heap_dirty; ///lock this before manipulating heap. - QMutex heap_lock; + mt::mutex heap_lock; ///used to sincronize priorities update - QMutex priority_lock; + mt::mutex priority_lock; ///signals (to next cache!) priorities have changed or something is available QDoor check_queue; @@ -39,7 +38,7 @@ class Provider: public QThread { /// [should be protected, do not use] void pushPriorities() { - QMutexLocker locker(&priority_lock); + mt::mutexlocker locker(&priority_lock); for(int i = 0; i < heap.size(); i++) heap[i].pushPriority(); heap_dirty = true; @@ -50,7 +49,7 @@ class Provider: public QThread { if(!this->heap_dirty) return; { - QMutexLocker locker(&priority_lock); + mt::mutexlocker locker(&priority_lock); for(int i = 0; i < this->heap.size(); i++) this->heap[i].pullPriority(); this->heap_dirty = false; @@ -70,7 +69,7 @@ class Provider: public QThread { ///ensure no locked item are to be removed [should be protected, do not use] template void flush(FUNCTOR functor) { int count = 0; - QMutexLocker locker(&(this->heap_lock)); + mt::mutexlocker locker(&(this->heap_lock)); for(int k = 0; k < this->heap.size(); k++) { Token *token = &this->heap[k]; if(functor(token)) { //drop it