Skip to content

Commit 6298e07

Browse files
committed
更新无锁队列
1 parent 8c25caf commit 6298e07

1 file changed

Lines changed: 9 additions & 5 deletions

File tree

webserver/lock/KLockFreeQueue.h

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,14 @@ class LockFreeQueue
3030
LockFreeQueue() : head_(new Node()), tail_(head_) {}
3131
~LockFreeQueue()
3232
{
33-
// Todo: 完成队列的析构
34-
// 暂时好像没有必要
35-
// 1. 任务队列与程序生命期相同
36-
// 2. 肯定是要完成队列里面所有任务的
33+
Node *tmp;
34+
while (head_ != nullptr) {
35+
tmp = head_;
36+
head_ = head_->next_;
37+
delete tmp;
38+
}
39+
tmp = nullptr;
40+
tail_ = nullptr;
3741
}
3842

3943
bool Try_Dequeue(T &data)
@@ -127,4 +131,4 @@ class LockFreeQueue
127131
// 重置尾节点, (也有可能已经被别的线程重置,那么当前线程就不用管了
128132
::__sync_bool_compare_and_swap(&tail_, old_tail, enqueue_node);
129133
}
130-
};
134+
};

0 commit comments

Comments
 (0)