Use void* instead of uintptr_t for tracking pointers.

RTCStatsCollector internally keeps track of open data channels but
does not need (or want) to interact directly with those channels,
hence uintptr_t was used instead of pointers to the channel objects.
This changes that to use void* to avoid having to do the cast.

This is a follow-up action item to
https://webrtc-review.googlesource.com/c/src/+/295781

This CL also changes the container type:
std::set -> webrtc::flat_set

Bug: webrtc:12689
Change-Id: I13d3f4a41ef83dab38411193187e872b9d6d3cff
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/295871
Reviewed-by: Harald Alvestrand <hta@webrtc.org>
Commit-Queue: Tomas Gunnarsson <tommi@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#39468}
This commit is contained in:
Tommi 2023-03-03 13:34:42 +01:00 committed by WebRTC LUCI CQ
parent c2429a080d
commit 60d4adcde0
3 changed files with 9 additions and 7 deletions

View File

@ -1063,6 +1063,7 @@ rtc_source_set("rtc_stats_collector") {
"../rtc_base:stringutils",
"../rtc_base:threading",
"../rtc_base:timeutils",
"../rtc_base/containers:flat_set",
"../rtc_base/synchronization:mutex",
]
absl_deps = [

View File

@ -16,6 +16,7 @@
#include <cstdint>
#include <map>
#include <memory>
#include <set>
#include <string>
#include <type_traits>
#include <utility>
@ -2496,16 +2497,13 @@ void RTCStatsCollector::OnSctpDataChannelStateChanged(
DataChannelInterface::DataState state) {
RTC_DCHECK_RUN_ON(signaling_thread_);
if (state == DataChannelInterface::DataState::kOpen) {
bool result = internal_record_.opened_data_channels
.insert(reinterpret_cast<uintptr_t>(channel))
.second;
bool result = internal_record_.opened_data_channels.insert(channel).second;
RTC_DCHECK(result);
++internal_record_.data_channels_opened;
} else if (state == DataChannelInterface::DataState::kClosed) {
// Only channels that have been fully opened (and have increased the
// `data_channels_opened_` counter) increase the closed counter.
if (internal_record_.opened_data_channels.erase(
reinterpret_cast<uintptr_t>(channel))) {
if (internal_record_.opened_data_channels.erase(channel)) {
++internal_record_.data_channels_closed;
}
}

View File

@ -16,7 +16,6 @@
#include <cstdint>
#include <map>
#include <memory>
#include <set>
#include <string>
#include <vector>
@ -39,6 +38,7 @@
#include "pc/track_media_info_map.h"
#include "pc/transport_stats.h"
#include "rtc_base/checks.h"
#include "rtc_base/containers/flat_set.h"
#include "rtc_base/event.h"
#include "rtc_base/ref_count.h"
#include "rtc_base/ssl_certificate.h"
@ -323,7 +323,10 @@ class RTCStatsCollector : public rtc::RefCountInterface {
uint32_t data_channels_closed;
// Identifies by address channels that have been opened, which remain in the
// set until they have been fully closed.
std::set<uintptr_t> opened_data_channels;
// NOTE: There is no reference held here or any other type of guarantee that
// these pointers remain valid. So they MUST NOT be followed; hence, void*
// is used and not the explicit type.
webrtc::flat_set<void*> opened_data_channels;
};
InternalRecord internal_record_;
};