[09_queue] concurrency, lock_free_queue, updated.
This commit is contained in:
parent
ee3253afdd
commit
038359ef26
@ -24,11 +24,21 @@ class LockFreeQueue {
|
|||||||
public:
|
public:
|
||||||
LockFreeQueue() head(new node), tail(head.load()) {}
|
LockFreeQueue() head(new node), tail(head.load()) {}
|
||||||
LockFreeQueue(const LockFreeQueue&) = delete;
|
LockFreeQueue(const LockFreeQueue&) = delete;
|
||||||
|
LockFreeQueue(LockFreeQueue&& other) : head(other.head.load()), tail(other.tail.load()) {
|
||||||
|
other.head.store(nullptr);
|
||||||
|
other.tail.store(nullptr);
|
||||||
|
}
|
||||||
LockFreeQueue& operator=(const LockFreeQueue&) = delete;
|
LockFreeQueue& operator=(const LockFreeQueue&) = delete;
|
||||||
// TODO(Liam Huang): move constructor and move assignment should be well implemented later,
|
LockFreeQueue& operator=(LockFreeQueue&& rhs) {
|
||||||
// and hance marked "delete".
|
while (node* const old_head = head.load()) {
|
||||||
LockFreeQueue(LockFreeQueue&&) = delete;
|
head.store(old_head->next);
|
||||||
LockFreeQueue& operator=(LockFreeQueue&&) = delete;
|
delete old_head;
|
||||||
|
}
|
||||||
|
head.store(rhs.head.load());
|
||||||
|
tail.store(rhs.tail.load());
|
||||||
|
rhs.head.store(nullptr);
|
||||||
|
rhs.tail.store(nullptr);
|
||||||
|
}
|
||||||
~LockFreeQueue() {
|
~LockFreeQueue() {
|
||||||
while (node* const old_head = head.load()) {
|
while (node* const old_head = head.load()) {
|
||||||
head.store(old_head->next);
|
head.store(old_head->next);
|
||||||
|
Loading…
Reference in New Issue
Block a user