dl
dl_list_mt.h
浏览该文件的文档.
1
12#pragma once
13
14#include <list>
15
16#include "base/dl_type_def.h"
17
18namespace dl
19{
21template<typename T>
23{
24public:
29 bool PopFront(T& a)
30 {
31 _mutex.lock();
32 if (_list.empty())
33 {
34 _mutex.unlock();
35 return false;
36 }
37 a = _list.front();
38 _list.pop_front();
39 _mutex.unlock();
40 return true;
41 }
42
45 void Add(const T& buf)
46 {
47 _mutex.lock();
48 _list.push_back(buf);
49 _mutex.unlock();
50 }
51
54 void Add(T&& buf)
55 {
56 _mutex.lock();
57 _list.push_back(buf);
58 _mutex.unlock();
59 }
60
63 size_t GetSize()
64 {
65 std::lock_guard guard{ _mutex };
66 return _list.size();
67 }
68
71 bool IsEmpty()
72 {
73 std::lock_guard guard{ _mutex };
74 return _list.empty();
75 }
76
79 void Clear()
80 {
81 _mutex.lock();
82 _list.clear();
83 _mutex.unlock();
84 }
85
87 {
88 _mode = mode;
89 }
90
92 _mode{ mode }
93 {}
94private:
95 std::mutex _mutex;// 队列锁
96 std::list<T> _list;// 队列
97 QueueMode _mode;
98};
99}
void Add(T &&buf)
添加
bool PopFront(T &a)
取第一个,顺序通过 SetQueueMode 指定,默认FIFO
size_t GetSize()
当前数量
ListMultiThread(QueueMode mode=QueueMode::FIFO)
void SetQueueMode(QueueMode mode)
void Add(const T &buf)
添加
通用类型定义