From cb11a310a65d60b1dbf49ff6d2bd4ae218d21b6f Mon Sep 17 00:00:00 2001 From: Yves Gerey Date: Fri, 26 Jul 2019 18:51:59 +0200 Subject: [PATCH] Guard GenerateUniqueId() against concurrent access. Both test and prod setups may use several signaling threads, this CL prevents race conditions on GenerateUniqueId(). Bug: webrtc:9849 Change-Id: Iaec98b7b4f99729a9ad0642873a5d87de252cb1a Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/147020 Commit-Queue: Yves Gerey Commit-Queue: Seth Hampson Reviewed-by: Seth Hampson Cr-Commit-Position: refs/heads/master@{#28692} --- pc/rtp_sender.cc | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/pc/rtp_sender.cc b/pc/rtp_sender.cc index 6ef7f9f873..9eaed311a7 100644 --- a/pc/rtp_sender.cc +++ b/pc/rtp_sender.cc @@ -10,6 +10,7 @@ #include "pc/rtp_sender.h" +#include #include #include @@ -28,9 +29,11 @@ namespace webrtc { namespace { -// This function is only expected to be called on the signalling thread. +// This function is only expected to be called on the signaling thread. +// On the other hand, some test or even production setups may use +// several signaling threads. int GenerateUniqueId() { - static int g_unique_id = 0; + static std::atomic g_unique_id{0}; return ++g_unique_id; }