Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
youngwolf
ascs
提交
287b1a07
A
ascs
项目概览
youngwolf
/
ascs
通知
5
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
A
ascs
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
287b1a07
编写于
7月 20, 2022
作者:
Y
youngwolf
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add memory synchronization for st_asio_wrapper::queue's empty indication.
上级
7589a79f
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
8 addition
and
4 deletion
+8
-4
asio
asio
+1
-1
include/ascs/container.h
include/ascs/container.h
+7
-3
未找到文件。
asio
@
4915cfd8
比较
9902fe7d
...
4915cfd8
Subproject commit
9902fe7d1d6b5321f4ab2f4ddbfd19cf39160891
Subproject commit
4915cfd8a1653c157a1480162ae5601318553eb8
include/ascs/container.h
浏览文件 @
287b1a07
...
...
@@ -45,7 +45,7 @@ private:
//Container must at least has the following functions (like std::list):
// Container() constructor
// empty
, must be thread safe, but doesn't have to be consistent
// empty
// clear
// swap
// template<typename T> emplace_back(const T& item), if you call direct_(sync_)send_msg which accepts other than rvalue reference
...
...
@@ -67,13 +67,17 @@ public:
using
typename
Container
::
size_type
;
using
typename
Container
::
reference
;
using
typename
Container
::
const_reference
;
using
Container
::
empty
;
//since some implementations (such as gcc before 5.0) of std::list::size() have linear complexity, we don't expose this size() function
//using Container::size;
queue
()
:
total_size
(
0
)
{}
//thread safe
bool
is_thread_safe
()
const
{
return
Lockable
::
is_lockable
();}
size_t
size_in_byte
()
const
{
return
total_size
;}
//almost all implementations of list::empty() in the world are thread safe (not means correctness, but just no memory access violation),
// but we need a memory fence to synchronize memory with the IO thread, so we use a lock here.
bool
empty
()
{
typename
Lockable
::
lock_guard
lock
(
*
this
);
return
Container
::
empty
();}
void
clear
()
{
typename
Lockable
::
lock_guard
lock
(
*
this
);
Container
::
clear
();
total_size
=
0
;}
void
swap
(
Container
&
can
)
{
...
...
@@ -152,7 +156,7 @@ public:
total_size
+=
size_in_byte
;
}
bool
try_dequeue_
(
reference
item
)
{
if
(
this
->
empty
())
return
false
;
item
.
swap
(
this
->
front
());
this
->
pop_front
();
total_size
-=
item
.
size
();
return
true
;}
bool
try_dequeue_
(
reference
item
)
{
if
(
Container
::
empty
())
return
false
;
item
.
swap
(
this
->
front
());
this
->
pop_front
();
total_size
-=
item
.
size
();
return
true
;}
void
move_items_out_
(
Container
&
dest
,
size_t
max_item_num
=
-
1
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录