Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
Z
ZLMediaKit
概览
Overview
Details
Activity
Cycle Analytics
版本库
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
问题
0
Issues
0
列表
Board
标记
里程碑
合并请求
0
Merge Requests
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
Snippets
成员
Collapse sidebar
Close sidebar
活动
图像
聊天
创建新问题
作业
提交
Issue Boards
Open sidebar
张翔宇
ZLMediaKit
Commits
45c5f1ec
Commit
45c5f1ec
authored
4 years ago
by
xiongziliang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
避免死锁
parent
e1929314
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
28 行增加
和
8 行删除
+28
-8
3rdpart/ZLToolKit
+1
-1
src/Common/MediaSource.cpp
+9
-2
src/Extension/Frame.h
+18
-5
没有找到文件。
ZLToolKit
@
58a74f8c
Subproject commit
69227690e1b6e63f43969aafda0263e05f41a14a
Subproject commit
58a74f8c5ab802a0dd9fdcdcc0fe4c5a3d841964
This diff is collapsed.
Click to expand it.
src/Common/MediaSource.cpp
查看文件 @
45c5f1ec
...
...
@@ -119,8 +119,15 @@ bool MediaSource::isRecording(Recorder::type type){
}
void
MediaSource
::
for_each_media
(
const
function
<
void
(
const
MediaSource
::
Ptr
&
src
)
>
&
cb
)
{
lock_guard
<
recursive_mutex
>
lock
(
g_mtxMediaSrc
);
for
(
auto
&
pr0
:
g_mapMediaSrc
)
{
decltype
(
g_mapMediaSrc
)
copy
;
{
//拷贝g_mapMediaSrc后再遍历,考虑到是高频使用的全局单例锁,并且在上锁时会执行回调代码
//很容易导致多个锁交叉死锁的情况,而且该函数使用频率不高,拷贝开销相对来说是可以接受的
lock_guard
<
recursive_mutex
>
lock
(
g_mtxMediaSrc
);
copy
=
g_mapMediaSrc
;
}
for
(
auto
&
pr0
:
copy
)
{
for
(
auto
&
pr1
:
pr0
.
second
)
{
for
(
auto
&
pr2
:
pr1
.
second
)
{
for
(
auto
&
pr3
:
pr2
.
second
)
{
...
...
This diff is collapsed.
Click to expand it.
src/Extension/Frame.h
查看文件 @
45c5f1ec
...
...
@@ -192,13 +192,17 @@ public:
virtual
~
FrameDispatcher
(){}
void
addDelegate
(
const
FrameWriterInterface
::
Ptr
&
delegate
){
//_delegates_write可能多线程同时操作
lock_guard
<
mutex
>
lck
(
_mtx
);
_delegateMap
.
emplace
(
delegate
.
get
(),
delegate
);
_delegates_write
.
emplace
(
delegate
.
get
(),
delegate
);
_need_update
=
true
;
}
void
delDelegate
(
void
*
ptr
){
//_delegates_write可能多线程同时操作
lock_guard
<
mutex
>
lck
(
_mtx
);
_delegateMap
.
erase
(
ptr
);
_delegates_write
.
erase
(
ptr
);
_need_update
=
true
;
}
/**
...
...
@@ -206,14 +210,23 @@ public:
* @param frame 帧
*/
void
inputFrame
(
const
Frame
::
Ptr
&
frame
)
override
{
lock_guard
<
mutex
>
lck
(
_mtx
);
for
(
auto
&
pr
:
_delegate
Map
){
//_delegates_read能确保是单线程操作的
for
(
auto
&
pr
:
_delegate
s_read
){
pr
.
second
->
inputFrame
(
frame
);
}
if
(
_need_update
){
//发现代理列表发生变化了,这里同步一次
lock_guard
<
mutex
>
lck
(
_mtx
);
_delegates_read
=
_delegates_write
;
_need_update
=
false
;
}
}
private
:
mutex
_mtx
;
map
<
void
*
,
FrameWriterInterface
::
Ptr
>
_delegateMap
;
map
<
void
*
,
FrameWriterInterface
::
Ptr
>
_delegates_read
;
map
<
void
*
,
FrameWriterInterface
::
Ptr
>
_delegates_write
;
bool
_need_update
=
false
;
};
/**
...
...
This diff is collapsed.
Click to expand it.
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论