Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
jami-daemon
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
savoirfairelinux
jami-daemon
Commits
dd317b60
Commit
dd317b60
authored
2 years ago
by
Sébastien Blin
Browse files
Options
Downloads
Patches
Plain Diff
sync_module: avoid double lock on syncConnectionsMtx_
GitLab:
#843
Change-Id: I5b9de9c38e6b8307db531cf75babd02426a914f6
parent
d4f13b41
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/jamidht/sync_module.cpp
+6
-6
6 additions, 6 deletions
src/jamidht/sync_module.cpp
with
6 additions
and
6 deletions
src/jamidht/sync_module.cpp
+
6
−
6
View file @
dd317b60
...
@@ -34,7 +34,7 @@ public:
...
@@ -34,7 +34,7 @@ public:
std
::
weak_ptr
<
JamiAccount
>
account_
;
std
::
weak_ptr
<
JamiAccount
>
account_
;
// Sync connections
// Sync connections
std
::
mutex
syncConnectionsMtx_
;
std
::
recursive_
mutex
syncConnectionsMtx_
;
std
::
map
<
DeviceId
/* deviceId */
,
std
::
vector
<
std
::
shared_ptr
<
ChannelSocket
>>>
syncConnections_
;
std
::
map
<
DeviceId
/* deviceId */
,
std
::
vector
<
std
::
shared_ptr
<
ChannelSocket
>>>
syncConnections_
;
std
::
weak_ptr
<
Impl
>
weak
()
{
return
std
::
static_pointer_cast
<
Impl
>
(
shared_from_this
());
}
std
::
weak_ptr
<
Impl
>
weak
()
{
return
std
::
static_pointer_cast
<
Impl
>
(
shared_from_this
());
}
...
@@ -155,14 +155,14 @@ SyncModule::cacheSyncConnection(std::shared_ptr<ChannelSocket>&& socket,
...
@@ -155,14 +155,14 @@ SyncModule::cacheSyncConnection(std::shared_ptr<ChannelSocket>&& socket,
const
std
::
string
&
peerId
,
const
std
::
string
&
peerId
,
const
DeviceId
&
device
)
const
DeviceId
&
device
)
{
{
std
::
lock_guard
<
std
::
mutex
>
lk
(
pimpl_
->
syncConnectionsMtx_
);
std
::
lock_guard
<
std
::
recursive_
mutex
>
lk
(
pimpl_
->
syncConnectionsMtx_
);
pimpl_
->
syncConnections_
[
device
].
emplace_back
(
socket
);
pimpl_
->
syncConnections_
[
device
].
emplace_back
(
socket
);
socket
->
onShutdown
([
w
=
pimpl_
->
weak
(),
peerId
,
device
,
socket
]()
{
socket
->
onShutdown
([
w
=
pimpl_
->
weak
(),
peerId
,
device
,
socket
]()
{
auto
shared
=
w
.
lock
();
auto
shared
=
w
.
lock
();
if
(
!
shared
)
if
(
!
shared
)
return
;
return
;
std
::
lock_guard
<
std
::
mutex
>
lk
(
shared
->
syncConnectionsMtx_
);
std
::
lock_guard
<
std
::
recursive_
mutex
>
lk
(
shared
->
syncConnectionsMtx_
);
auto
&
connections
=
shared
->
syncConnections_
[
device
];
auto
&
connections
=
shared
->
syncConnections_
[
device
];
auto
conn
=
connections
.
begin
();
auto
conn
=
connections
.
begin
();
while
(
conn
!=
connections
.
end
())
{
while
(
conn
!=
connections
.
end
())
{
...
@@ -205,13 +205,13 @@ SyncModule::syncWith(const DeviceId& deviceId,
...
@@ -205,13 +205,13 @@ SyncModule::syncWith(const DeviceId& deviceId,
if
(
!
socket
)
if
(
!
socket
)
return
;
return
;
{
{
std
::
lock_guard
<
std
::
mutex
>
lk
(
pimpl_
->
syncConnectionsMtx_
);
std
::
lock_guard
<
std
::
recursive_
mutex
>
lk
(
pimpl_
->
syncConnectionsMtx_
);
socket
->
onShutdown
([
w
=
pimpl_
->
weak
(),
socket
,
deviceId
]()
{
socket
->
onShutdown
([
w
=
pimpl_
->
weak
(),
socket
,
deviceId
]()
{
// When sock is shutdown update syncConnections_ to be able to resync asap
// When sock is shutdown update syncConnections_ to be able to resync asap
auto
shared
=
w
.
lock
();
auto
shared
=
w
.
lock
();
if
(
!
shared
)
if
(
!
shared
)
return
;
return
;
std
::
lock_guard
<
std
::
mutex
>
lk
(
shared
->
syncConnectionsMtx_
);
std
::
lock_guard
<
std
::
recursive_
mutex
>
lk
(
shared
->
syncConnectionsMtx_
);
auto
&
connections
=
shared
->
syncConnections_
[
deviceId
];
auto
&
connections
=
shared
->
syncConnections_
[
deviceId
];
auto
conn
=
connections
.
begin
();
auto
conn
=
connections
.
begin
();
while
(
conn
!=
connections
.
end
())
{
while
(
conn
!=
connections
.
end
())
{
...
@@ -232,7 +232,7 @@ SyncModule::syncWith(const DeviceId& deviceId,
...
@@ -232,7 +232,7 @@ SyncModule::syncWith(const DeviceId& deviceId,
void
void
SyncModule
::
syncWithConnected
(
const
std
::
shared_ptr
<
SyncMsg
>&
syncMsg
,
const
DeviceId
&
deviceId
)
SyncModule
::
syncWithConnected
(
const
std
::
shared_ptr
<
SyncMsg
>&
syncMsg
,
const
DeviceId
&
deviceId
)
{
{
std
::
lock_guard
<
std
::
mutex
>
lk
(
pimpl_
->
syncConnectionsMtx_
);
std
::
lock_guard
<
std
::
recursive_
mutex
>
lk
(
pimpl_
->
syncConnectionsMtx_
);
for
(
auto
&
[
did
,
sockets
]
:
pimpl_
->
syncConnections_
)
{
for
(
auto
&
[
did
,
sockets
]
:
pimpl_
->
syncConnections_
)
{
if
(
not
sockets
.
empty
())
{
if
(
not
sockets
.
empty
())
{
if
(
!
deviceId
||
deviceId
==
did
)
{
if
(
!
deviceId
||
deviceId
==
did
)
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment