ported to qt5 (but not workinng in qt4.8)
This commit is contained in:
parent
2b47dcbb3d
commit
7a12add219
|
@ -1,17 +1,17 @@
|
|||
#ifndef GCACHE_CACHE_H
|
||||
#define GCACHE_CACHE_H
|
||||
|
||||
#ifdef _MSC_VER
|
||||
|
||||
typedef __int16 int16_t;
|
||||
typedef unsigned __int16 uint16_t;
|
||||
typedef __int32 int32_t;
|
||||
typedef unsigned __int32 uint32_t;
|
||||
typedef __int64 int64_t;
|
||||
typedef unsigned __int64 uint64_t;
|
||||
|
||||
#else
|
||||
#include <stdint.h>
|
||||
#ifdef _MSC_VER
|
||||
|
||||
typedef __int16 int16_t;
|
||||
typedef unsigned __int16 uint16_t;
|
||||
typedef __int32 int32_t;
|
||||
typedef unsigned __int32 uint32_t;
|
||||
typedef __int64 int64_t;
|
||||
typedef unsigned __int64 uint64_t;
|
||||
|
||||
#else
|
||||
#include <stdint.h>
|
||||
#endif
|
||||
|
||||
#include <iostream>
|
||||
|
@ -87,7 +87,7 @@ public:
|
|||
Token *token = &(this->heap[i]);
|
||||
//tokens.push_back(token);
|
||||
s_curr -= drop(token);
|
||||
assert(!(token->count >= Token::LOCKED));
|
||||
assert(!(token->count.load() >= Token::LOCKED));
|
||||
if(final)
|
||||
token->count.testAndSetOrdered(Token::READY, Token::CACHE);
|
||||
input->heap.push(token);
|
||||
|
@ -112,7 +112,7 @@ public:
|
|||
if(functor(token)) { //drop it
|
||||
tokens.push_back(token);
|
||||
s_curr -= drop(token);
|
||||
assert(token->count < Token::LOCKED);
|
||||
assert(token->count.load() < Token::LOCKED);
|
||||
if(final)
|
||||
token->count.testAndSetOrdered(Token::READY, Token::CACHE);
|
||||
} else
|
||||
|
@ -198,7 +198,7 @@ protected:
|
|||
remove = this->heap.popMin();
|
||||
} else {
|
||||
last.count.testAndSetOrdered(Token::READY, Token::CACHE);
|
||||
if(last.count <= Token::CACHE) { //was not locked and now can't be locked, remove it.
|
||||
if(last.count.load() <= Token::CACHE) { //was not locked and now can't be locked, remove it.
|
||||
remove = this->heap.popMin();
|
||||
} else { //last item is locked need to reorder stack
|
||||
remove = this->heap.popMin();
|
||||
|
@ -245,7 +245,7 @@ protected:
|
|||
input->rebuild(); //if dirty rebuild
|
||||
if(input->heap.size()) { //we need something in input to tranfer.
|
||||
Token &first = input->heap.max();
|
||||
if(first.count > Token::REMOVE &&
|
||||
if(first.count.load() > Token::REMOVE &&
|
||||
(!last || first.priority > last->priority)) { //if !last we already decided we want a transfer., otherwise check for a swap
|
||||
insert = input->heap.popMax(); //remove item from heap, while we transfer it.
|
||||
}
|
||||
|
|
|
@ -61,10 +61,10 @@ class Token {
|
|||
bool remove() {
|
||||
count.testAndSetOrdered(READY, REMOVE);
|
||||
count.testAndSetOrdered(CACHE, REMOVE);
|
||||
return count <= REMOVE; //might have become OUSIDE in the meanwhile
|
||||
return count.load() <= REMOVE; //might have become OUSIDE in the meanwhile
|
||||
}
|
||||
|
||||
bool isLocked() { return count > 0; }
|
||||
bool isLocked() { return count.load() > 0; }
|
||||
bool isInCache() { return count != OUTSIDE; } //careful, can be used only when provider thread is locked.
|
||||
|
||||
///copy priority to swap space [do not use, should be private]
|
||||
|
@ -73,14 +73,14 @@ class Token {
|
|||
}
|
||||
|
||||
bool operator<(const Token &a) const {
|
||||
if(count == a.count)
|
||||
if(count.load() == a.count.load())
|
||||
return priority < a.priority;
|
||||
return count < a.count;
|
||||
return count.load() < a.count.load();
|
||||
}
|
||||
bool operator>(const Token &a) const {
|
||||
if(count == a.count)
|
||||
if(count.load() == a.count.load())
|
||||
return priority > a.priority;
|
||||
return count > a.count;
|
||||
return count.load() > a.count.load();
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue