ported to qt5 (but not workinng in qt4.8)
This commit is contained in:
parent
2b47dcbb3d
commit
7a12add219
|
@ -87,7 +87,7 @@ public:
|
||||||
Token *token = &(this->heap[i]);
|
Token *token = &(this->heap[i]);
|
||||||
//tokens.push_back(token);
|
//tokens.push_back(token);
|
||||||
s_curr -= drop(token);
|
s_curr -= drop(token);
|
||||||
assert(!(token->count >= Token::LOCKED));
|
assert(!(token->count.load() >= Token::LOCKED));
|
||||||
if(final)
|
if(final)
|
||||||
token->count.testAndSetOrdered(Token::READY, Token::CACHE);
|
token->count.testAndSetOrdered(Token::READY, Token::CACHE);
|
||||||
input->heap.push(token);
|
input->heap.push(token);
|
||||||
|
@ -112,7 +112,7 @@ public:
|
||||||
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.load() < Token::LOCKED);
|
||||||
if(final)
|
if(final)
|
||||||
token->count.testAndSetOrdered(Token::READY, Token::CACHE);
|
token->count.testAndSetOrdered(Token::READY, Token::CACHE);
|
||||||
} else
|
} else
|
||||||
|
@ -198,7 +198,7 @@ protected:
|
||||||
remove = this->heap.popMin();
|
remove = this->heap.popMin();
|
||||||
} else {
|
} else {
|
||||||
last.count.testAndSetOrdered(Token::READY, Token::CACHE);
|
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();
|
remove = this->heap.popMin();
|
||||||
} else { //last item is locked need to reorder stack
|
} else { //last item is locked need to reorder stack
|
||||||
remove = this->heap.popMin();
|
remove = this->heap.popMin();
|
||||||
|
@ -245,7 +245,7 @@ protected:
|
||||||
input->rebuild(); //if dirty rebuild
|
input->rebuild(); //if dirty rebuild
|
||||||
if(input->heap.size()) { //we need something in input to tranfer.
|
if(input->heap.size()) { //we need something in input to tranfer.
|
||||||
Token &first = input->heap.max();
|
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
|
(!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.
|
insert = input->heap.popMax(); //remove item from heap, while we transfer it.
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,10 +61,10 @@ class Token {
|
||||||
bool remove() {
|
bool remove() {
|
||||||
count.testAndSetOrdered(READY, REMOVE);
|
count.testAndSetOrdered(READY, REMOVE);
|
||||||
count.testAndSetOrdered(CACHE, 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.
|
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]
|
///copy priority to swap space [do not use, should be private]
|
||||||
|
@ -73,14 +73,14 @@ class Token {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator<(const Token &a) const {
|
bool operator<(const Token &a) const {
|
||||||
if(count == a.count)
|
if(count.load() == a.count.load())
|
||||||
return priority < a.priority;
|
return priority < a.priority;
|
||||||
return count < a.count;
|
return count.load() < a.count.load();
|
||||||
}
|
}
|
||||||
bool operator>(const Token &a) const {
|
bool operator>(const Token &a) const {
|
||||||
if(count == a.count)
|
if(count.load() == a.count.load())
|
||||||
return priority > a.priority;
|
return priority > a.priority;
|
||||||
return count > a.count;
|
return count.load() > a.count.load();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue