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:
@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user