dl
dl
base
dl_list_mt.h
浏览该文件的文档.
1
12
#pragma once
13
14
#include <list>
15
16
#include "
base/dl_type_def.h
"
17
18
namespace
dl
19
{
21
template
<
typename
T>
22
class
ListMultiThread
23
{
24
public
:
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
86
void
SetQueueMode
(
QueueMode
mode)
87
{
88
_mode = mode;
89
}
90
91
ListMultiThread
(
QueueMode
mode =
QueueMode::FIFO
) :
92
_mode{ mode }
93
{}
94
private
:
95
std::mutex _mutex;
// 队列锁
96
std::list<T> _list;
// 队列
97
QueueMode
_mode;
98
};
99
}
dl::ListMultiThread::Clear
void Clear()
清除
定义
dl_list_mt.h:79
dl::ListMultiThread::Add
void Add(T &&buf)
添加
定义
dl_list_mt.h:54
dl::ListMultiThread::PopFront
bool PopFront(T &a)
取第一个,顺序通过 SetQueueMode 指定,默认FIFO
定义
dl_list_mt.h:29
dl::ListMultiThread::IsEmpty
bool IsEmpty()
空
定义
dl_list_mt.h:71
dl::ListMultiThread::GetSize
size_t GetSize()
当前数量
定义
dl_list_mt.h:63
dl::ListMultiThread::ListMultiThread
ListMultiThread(QueueMode mode=QueueMode::FIFO)
定义
dl_list_mt.h:91
dl::ListMultiThread::SetQueueMode
void SetQueueMode(QueueMode mode)
定义
dl_list_mt.h:86
dl::ListMultiThread::Add
void Add(const T &buf)
添加
定义
dl_list_mt.h:45
dl_type_def.h
通用类型定义
dl
定义
dl_array.h:22
dl::KeyCode::T
@ T
定义
dl_input.h:121
dl::QueueMode
QueueMode
定义
dl_type_def.h:106
dl::QueueMode::FIFO
@ FIFO
定义
dl_type_def.h:107
制作者
1.13.1