Guard GenerateUniqueId aginst concurrent access.

Similar to https://webrtc-review.googlesource.com/c/src/+/147020.

Bug: b/264473017
Change-Id: I40a6239f28c01b90f521f3cadcb4aea4f6d6461c
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/336180
Reviewed-by: Harald Alvestrand <hta@webrtc.org>
Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#41609}
This commit is contained in:
Mirko Bonadei 2024-01-25 08:34:26 +00:00 committed by WebRTC LUCI CQ
parent c3624d02d0
commit cc70a6d174

View file

@ -12,6 +12,7 @@
#include <stddef.h> #include <stddef.h>
#include <atomic>
#include <utility> #include <utility>
#include <vector> #include <vector>
@ -22,8 +23,10 @@
namespace webrtc { namespace webrtc {
// This function is only expected to be called on the signalling thread. // This function is only expected to be called on the signalling thread.
// On the other hand, some test or even production setups may use
// several signaling threads.
int RtpReceiverInternal::GenerateUniqueId() { int RtpReceiverInternal::GenerateUniqueId() {
static int g_unique_id = 0; static std::atomic<int> g_unique_id{0};
return ++g_unique_id; return ++g_unique_id;
} }