Skip to content

Commit

Permalink
[09_queue] concurrency, lock_free_queue, updated.
Browse files Browse the repository at this point in the history
  • Loading branch information
Liam0205 committed Oct 11, 2018
1 parent ee3253a commit 038359e
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions c-cpp/09_queue/lock_free_queue.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,21 @@ class LockFreeQueue {
public:
LockFreeQueue() head(new node), tail(head.load()) {}
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;
// TODO(Liam Huang): move constructor and move assignment should be well implemented later,
// and hance marked "delete".
LockFreeQueue(LockFreeQueue&&) = delete;
LockFreeQueue& operator=(LockFreeQueue&&) = delete;
LockFreeQueue& operator=(LockFreeQueue&& rhs) {
while (node* const old_head = head.load()) {
head.store(old_head->next);
delete old_head;
}
head.store(rhs.head.load());
tail.store(rhs.tail.load());
rhs.head.store(nullptr);
rhs.tail.store(nullptr);
}
~LockFreeQueue() {
while (node* const old_head = head.load()) {
head.store(old_head->next);
Expand Down

0 comments on commit 038359e

Please sign in to comment.