1
This commit is contained in:
parent
987da1b7c3
commit
88c5624334
30
a8/queue.cc
Normal file
30
a8/queue.cc
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
#include <a8/a8.h>
|
||||||
|
|
||||||
|
namespace a8
|
||||||
|
{
|
||||||
|
|
||||||
|
Queue::Queue()
|
||||||
|
{
|
||||||
|
INIT_LIST_HEAD(&msg_list_);
|
||||||
|
INIT_LIST_HEAD(&work_list_);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Queue::Push(list_head* node)
|
||||||
|
{
|
||||||
|
msg_mutex_.lock();
|
||||||
|
list_add_tail(node, &msg_list_);
|
||||||
|
msg_mutex_.unlock();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Queue::Fetch()
|
||||||
|
{
|
||||||
|
if (list_empty(&work_list_)) {
|
||||||
|
msg_mutex_.lock();
|
||||||
|
if (!list_empty(&msg_list_)) {
|
||||||
|
list_replace_init(&msg_list_, &work_list_);
|
||||||
|
}
|
||||||
|
msg_mutex_.unlock();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
23
a8/queue.h
Normal file
23
a8/queue.h
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <mutex>
|
||||||
|
|
||||||
|
namespace a8
|
||||||
|
{
|
||||||
|
|
||||||
|
class Queue
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
Queue();
|
||||||
|
list_head* GetWorkList() { return &work_list_; }
|
||||||
|
void Push(list_head* node);
|
||||||
|
void Fetch();
|
||||||
|
|
||||||
|
private:
|
||||||
|
list_head msg_list_;
|
||||||
|
list_head work_list_;
|
||||||
|
std::mutex msg_mutex_;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user