Skip to content
This repository was archived by the owner on Mar 22, 2022. It is now read-only.

Commit aeb1879

Browse files
committed
Cache field access in RemoveDataChannel
Minimize the changes of a deadlock by caching accesses to data channel fields before entering the data channel lock, to not block the signaling thread.
1 parent 0246aae commit aeb1879

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

libs/Microsoft.MixedReality.WebRTC.Native/src/peer_connection.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,11 @@ webrtc::RTCErrorOr<std::shared_ptr<DataChannel>> PeerConnection::AddDataChannel(
294294

295295
void PeerConnection::RemoveDataChannel(
296296
const DataChannel& data_channel) noexcept {
297+
// Cache variables which require a dispatch to the signaling thread
298+
// to minimize the risk of a deadlock with the data channel lock below.
299+
const int id = data_channel.id();
300+
const str label = data_channel.label();
301+
297302
// Move the channel to destroy out of the internal data structures
298303
std::shared_ptr<DataChannel> data_channel_ptr;
299304
{
@@ -313,11 +318,10 @@ void PeerConnection::RemoveDataChannel(
313318
data_channels_.erase(it);
314319

315320
// Clean-up interop maps
316-
auto it_id = data_channel_from_id_.find(data_channel.id());
321+
auto it_id = data_channel_from_id_.find(id);
317322
if (it_id != data_channel_from_id_.end()) {
318323
data_channel_from_id_.erase(it_id);
319324
}
320-
const str label = data_channel.label();
321325
if (!label.empty()) {
322326
auto it_label = data_channel_from_label_.find(label);
323327
if (it_label != data_channel_from_label_.end()) {

0 commit comments

Comments
 (0)