Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
youngwolf
ascs
提交
2a4ad2da
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 搜索 >>
提交
2a4ad2da
编写于
7月 04, 2021
作者:
Y
youngwolf
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Free function do_something_to_all/one support customizing mutex and lock types.
上级
ba2b6af4
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
15 addition
and
15 deletion
+15
-15
include/ascs/base.h
include/ascs/base.h
+10
-10
include/ascs/service_pump.h
include/ascs/service_pump.h
+2
-2
include/ascs/timer.h
include/ascs/timer.h
+2
-2
include/ascs/udp/socket.h
include/ascs/udp/socket.h
+1
-1
未找到文件。
include/ascs/base.h
浏览文件 @
2a4ad2da
...
...
@@ -500,16 +500,16 @@ template<typename T> struct obj_with_begin_time_promise : public obj_with_begin_
#endif
//free functions, used to do something to any container(except map and multimap) optionally with any mutex
template
<
typename
_Can
,
typename
_Mutex
,
typename
_Predicate
>
void
do_something_to_all
(
_Can
&
__can
,
_Mutex
&
__mutex
,
const
_Predicate
&
__pred
)
{
std
::
lock_guard
<
std
::
m
utex
>
lock
(
__mutex
);
for
(
auto
&
item
:
__can
)
__pred
(
item
);}
template
<
typename
_Can
,
typename
_Mutex
,
typename
_Predicate
,
template
<
typename
>
class
LockType
=
std
::
lock_guard
>
void
do_something_to_all
(
_Can
&
__can
,
_Mutex
&
__mutex
,
const
_Predicate
&
__pred
)
{
LockType
<
_M
utex
>
lock
(
__mutex
);
for
(
auto
&
item
:
__can
)
__pred
(
item
);}
template
<
typename
_Can
,
typename
_Predicate
>
void
do_something_to_all
(
_Can
&
__can
,
const
_Predicate
&
__pred
)
{
for
(
auto
&
item
:
__can
)
__pred
(
item
);}
template
<
typename
_Can
,
typename
_Mutex
,
typename
_Predicate
>
template
<
typename
_Can
,
typename
_Mutex
,
typename
_Predicate
,
template
<
typename
>
class
LockType
=
std
::
lock_guard
>
void
do_something_to_one
(
_Can
&
__can
,
_Mutex
&
__mutex
,
const
_Predicate
&
__pred
)
{
std
::
lock_guard
<
std
::
m
utex
>
lock
(
__mutex
);
LockType
<
_M
utex
>
lock
(
__mutex
);
for
(
auto
iter
=
std
::
begin
(
__can
);
iter
!=
std
::
end
(
__can
);
++
iter
)
if
(
__pred
(
*
iter
))
break
;
}
...
...
@@ -533,22 +533,22 @@ size_t get_size_in_byte(const _Can& __can, size_t& size)
}
//member functions, used to do something to any member container(except map and multimap) optionally with any member mutex
#define DO_SOMETHING_TO_ALL_MUTEX(CAN, MUTEX
) DO_SOMETHING_TO_ALL_MUTEX_NAME(do_something_to_all, CAN, MUTEX
)
#define DO_SOMETHING_TO_ALL_MUTEX(CAN, MUTEX
, LOCKTYPE) DO_SOMETHING_TO_ALL_MUTEX_NAME(do_something_to_all, CAN, MUTEX, LOCKTYPE
)
#define DO_SOMETHING_TO_ALL(CAN) DO_SOMETHING_TO_ALL_NAME(do_something_to_all, CAN)
#define DO_SOMETHING_TO_ALL_MUTEX_NAME(NAME, CAN, MUTEX) \
template<typename _Predicate> void NAME(const _Predicate& __pred) {
std::lock_guard<std::mutex>
lock(MUTEX); for (auto& item : CAN) __pred(item);}
#define DO_SOMETHING_TO_ALL_MUTEX_NAME(NAME, CAN, MUTEX
, LOCKTYPE
) \
template<typename _Predicate> void NAME(const _Predicate& __pred) {
LOCKTYPE
lock(MUTEX); for (auto& item : CAN) __pred(item);}
#define DO_SOMETHING_TO_ALL_NAME(NAME, CAN) \
template<typename _Predicate> void NAME(const _Predicate& __pred) {for (auto& item : CAN) __pred(item);} \
template<typename _Predicate> void NAME(const _Predicate& __pred) const {for (auto& item : CAN) __pred(item);}
#define DO_SOMETHING_TO_ONE_MUTEX(CAN, MUTEX
) DO_SOMETHING_TO_ONE_MUTEX_NAME(do_something_to_one, CAN, MUTEX
)
#define DO_SOMETHING_TO_ONE_MUTEX(CAN, MUTEX
, LOCKTYPE) DO_SOMETHING_TO_ONE_MUTEX_NAME(do_something_to_one, CAN, MUTEX, LOCKTYPE
)
#define DO_SOMETHING_TO_ONE(CAN) DO_SOMETHING_TO_ONE_NAME(do_something_to_one, CAN)
#define DO_SOMETHING_TO_ONE_MUTEX_NAME(NAME, CAN, MUTEX) \
#define DO_SOMETHING_TO_ONE_MUTEX_NAME(NAME, CAN, MUTEX
, LOCKTYPE
) \
template<typename _Predicate> void NAME(const _Predicate& __pred) \
{
std::lock_guard<std::mutex>
lock(MUTEX); for (auto iter = std::begin(CAN); iter != std::end(CAN); ++iter) if (__pred(*iter)) break;}
{
LOCKTYPE
lock(MUTEX); for (auto iter = std::begin(CAN); iter != std::end(CAN); ++iter) if (__pred(*iter)) break;}
#define DO_SOMETHING_TO_ONE_NAME(NAME, CAN) \
template<typename _Predicate> void NAME(const _Predicate& __pred) {for (auto iter = std::begin(CAN); iter != std::end(CAN); ++iter) if (__pred(*iter)) break;} \
...
...
include/ascs/service_pump.h
浏览文件 @
2a4ad2da
...
...
@@ -276,8 +276,8 @@ protected:
size_t
run
()
{
while
(
true
)
{
try
{
return
asio
::
io_context
::
run
();}
catch
(
const
std
::
exception
&
e
)
{
if
(
!
on_exception
(
e
))
return
0
;}}}
#endif
DO_SOMETHING_TO_ALL_MUTEX
(
service_can
,
service_can_mutex
)
DO_SOMETHING_TO_ONE_MUTEX
(
service_can
,
service_can_mutex
)
DO_SOMETHING_TO_ALL_MUTEX
(
service_can
,
service_can_mutex
,
std
::
lock_guard
<
std
::
mutex
>
)
DO_SOMETHING_TO_ONE_MUTEX
(
service_can
,
service_can_mutex
,
std
::
lock_guard
<
std
::
mutex
>
)
private:
void
add
(
object_type
i_service_
)
...
...
include/ascs/timer.h
浏览文件 @
2a4ad2da
...
...
@@ -118,8 +118,8 @@ public:
void
stop_all_timer
()
{
do_something_to_all
([
this
](
timer_info
&
item
)
{
this
->
stop_timer
(
item
);});}
void
stop_all_timer
(
tid
excepted_id
)
{
do_something_to_all
(
ASCS_COPY_ALL_AND_THIS
(
timer_info
&
item
)
{
if
(
excepted_id
!=
item
.
id
)
this
->
stop_timer
(
item
);});}
DO_SOMETHING_TO_ALL_MUTEX
(
timer_can
,
timer_can_mutex
)
DO_SOMETHING_TO_ONE_MUTEX
(
timer_can
,
timer_can_mutex
)
DO_SOMETHING_TO_ALL_MUTEX
(
timer_can
,
timer_can_mutex
,
std
::
lock_guard
<
std
::
mutex
>
)
DO_SOMETHING_TO_ONE_MUTEX
(
timer_can
,
timer_can_mutex
,
std
::
lock_guard
<
std
::
mutex
>
)
protected:
bool
start_timer
(
timer_info
&
ti
,
unsigned
interval_ms
)
...
...
include/ascs/udp/socket.h
浏览文件 @
2a4ad2da
...
...
@@ -475,7 +475,7 @@ protected:
return
true
;
}
else
unified_out
::
error_out
(
"invalid peer
ip address
"
);
unified_out
::
error_out
(
"invalid peer
path
"
);
return
false
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录