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}
diff --git a/pc/rtp_receiver.cc b/pc/rtp_receiver.cc
index a2b3353..9431aab 100644
--- a/pc/rtp_receiver.cc
+++ b/pc/rtp_receiver.cc
@@ -12,6 +12,7 @@
 
 #include <stddef.h>
 
+#include <atomic>
 #include <utility>
 #include <vector>
 
@@ -22,8 +23,10 @@
 namespace webrtc {
 
 // 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() {
-  static int g_unique_id = 0;
+  static std::atomic<int> g_unique_id{0};
 
   return ++g_unique_id;
 }