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 <yvesg@google.com>
Commit-Queue: Seth Hampson <shampson@webrtc.org>
Reviewed-by: Seth Hampson <shampson@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#28692}
This commit is contained in:
Yves Gerey
2019-07-26 18:51:59 +02:00
committed by Commit Bot
parent 1704801226
commit cb11a310a6

View File

@ -10,6 +10,7 @@
#include "pc/rtp_sender.h"
#include <atomic>
#include <utility>
#include <vector>
@ -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<int> g_unique_id{0};
return ++g_unique_id;
}