We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 8c25caf commit 6298e07Copy full SHA for 6298e07
1 file changed
webserver/lock/KLockFreeQueue.h
@@ -30,10 +30,14 @@ class LockFreeQueue
30
LockFreeQueue() : head_(new Node()), tail_(head_) {}
31
~LockFreeQueue()
32
{
33
- // Todo: 完成队列的析构
34
- // 暂时好像没有必要
35
- // 1. 任务队列与程序生命期相同
36
- // 2. 肯定是要完成队列里面所有任务的
+ Node *tmp;
+ while (head_ != nullptr) {
+ tmp = head_;
+ head_ = head_->next_;
37
+ delete tmp;
38
+ }
39
+ tmp = nullptr;
40
+ tail_ = nullptr;
41
}
42
43
bool Try_Dequeue(T &data)
@@ -127,4 +131,4 @@ class LockFreeQueue
127
131
// 重置尾节点, (也有可能已经被别的线程重置,那么当前线程就不用管了
128
132
::__sync_bool_compare_and_swap(&tail_, old_tail, enqueue_node);
129
133
130
-};
134
+};
0 commit comments