Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Eterfree
ThreadPool
提交
55b96d75
T
ThreadPool
项目概览
Eterfree
/
ThreadPool
9 个月 前同步成功
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
ThreadPool
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
55b96d75
编写于
10月 15, 2023
作者:
独孤过
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update v2.3.0
上级
de1b4faa
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
20 addition
and
13 deletion
+20
-13
Sample/ThreadPool/Eterfree.cpp
Sample/ThreadPool/Eterfree.cpp
+1
-0
Source/DoubleQueue.hpp
Source/DoubleQueue.hpp
+14
-10
Source/Thread.cpp
Source/Thread.cpp
+2
-0
Source/Thread.h
Source/Thread.h
+1
-1
Source/ThreadPool.cpp
Source/ThreadPool.cpp
+1
-1
Source/ThreadPool.h
Source/ThreadPool.h
+1
-1
未找到文件。
Sample/ThreadPool/Eterfree.cpp
浏览文件 @
55b96d75
...
...
@@ -40,6 +40,7 @@ static void execute(ThreadPool& _threadPool)
static
void
terminate
(
ThreadPool
&&
_threadPool
)
{
_threadPool
.
clearTask
();
auto
threadPool
(
std
::
forward
<
ThreadPool
>
(
_threadPool
));
(
void
)
threadPool
;
}
...
...
Source/DoubleQueue.hpp
浏览文件 @
55b96d75
...
...
@@ -88,6 +88,8 @@ private:
std
::
memory_order_relaxed
);
}
bool
valid
(
QueueType
&
_queue
)
const
noexcept
;
public:
// 若_capacity小于等于零,则无限制,否则其为上限值
DoubleQueue
(
SizeType
_capacity
=
0
)
:
\
...
...
@@ -151,6 +153,16 @@ void DoubleQueue<_Element>::move(DoubleQueue& _left, \
set
(
_left
.
_capacity
,
exchange
(
_right
.
_capacity
,
0
));
}
template
<
typename
_Element
>
bool
DoubleQueue
<
_Element
>::
valid
(
QueueType
&
_queue
)
const
noexcept
{
auto
capacity
=
this
->
capacity
();
if
(
capacity
<=
0
)
return
true
;
auto
size
=
this
->
size
();
return
size
<
capacity
&&
_queue
.
size
()
<=
capacity
-
size
;
}
template
<
typename
_Element
>
DoubleQueue
<
_Element
>::
DoubleQueue
(
const
DoubleQueue
&
_another
)
{
...
...
@@ -224,11 +236,7 @@ auto DoubleQueue<_Element>::push(QueueType& _queue) \
->
std
::
optional
<
SizeType
>
{
std
::
lock_guard
lock
(
_entryMutex
);
if
(
auto
capacity
=
this
->
capacity
(),
\
size
=
this
->
size
();
\
capacity
>
0
&&
(
size
>=
capacity
\
||
_queue
.
size
()
>=
capacity
-
size
))
return
std
::
nullopt
;
if
(
not
valid
(
_queue
))
return
std
::
nullopt
;
auto
size
=
_queue
.
size
();
_entryQueue
.
splice
(
_entryQueue
.
cend
(),
_queue
);
...
...
@@ -240,11 +248,7 @@ auto DoubleQueue<_Element>::push(QueueType&& _queue) \
->
std
::
optional
<
SizeType
>
{
std
::
lock_guard
lock
(
_entryMutex
);
if
(
auto
capacity
=
this
->
capacity
(),
\
size
=
this
->
size
();
\
capacity
>
0
&&
(
size
>=
capacity
\
||
_queue
.
size
()
>=
capacity
-
size
))
return
std
::
nullopt
;
if
(
not
valid
(
_queue
))
return
std
::
nullopt
;
auto
size
=
_queue
.
size
();
_entryQueue
.
splice
(
_entryQueue
.
cend
(),
\
...
...
Source/Thread.cpp
浏览文件 @
55b96d75
...
...
@@ -138,6 +138,8 @@ bool Thread::getTask(DataType& _data)
if
(
!
_data
->
_taskQueue
->
pop
(
task
))
return
false
;
if
(
!
task
)
task
=
[]
{};
_data
->
setState
(
State
::
RUNNABLE
);
_data
->
setTask
(
std
::
move
(
task
));
return
true
;
...
...
Source/Thread.h
浏览文件 @
55b96d75
...
...
@@ -3,7 +3,7 @@
* 语言标准:C++17
*
* 创建日期:2017年09月22日
* 更新日期:2023年
09月11
日
* 更新日期:2023年
10月15
日
*
* 摘要
* 1. 线程类Thread定义于此文件,实现于Thread.cpp。
...
...
Source/ThreadPool.cpp
浏览文件 @
55b96d75
...
...
@@ -457,7 +457,7 @@ void ThreadPool::execute(DataType _data)
_data
->
_condition
.
wait
(
predicate
);
}
// 清空线程
// 清空线程
表
_data
->
_threadTable
.
clear
();
}
...
...
Source/ThreadPool.h
浏览文件 @
55b96d75
...
...
@@ -49,7 +49,7 @@
* 2.确保移动构造函数和析构函数的异常安全性。
* v2.3.0
* 1.确保移动赋值运算符函数的异常安全性。
* 2.在销毁线程池时,当任务队列为空,并且所有线程闲置,守护线程才
可以退出,否则守护线程阻塞
直至满足退出条件。
* 2.在销毁线程池时,当任务队列为空,并且所有线程闲置,守护线程才
退出,否则守护线程阻塞,
直至满足退出条件。
*/
#pragma once
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录