Implement support for Chrome task origin tracing. #4/4

This CL forwards BlockingCall client locations to
BlockingCallImpl.

Fixed: chromium:1416199
Change-Id: Ic5865280ec5c72a09a64419940b8343e8a54986b
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/295624
Commit-Queue: Markus Handell <handellm@webrtc.org>
Reviewed-by: Harald Alvestrand <hta@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#39442}
This commit is contained in:
Markus Handell 2023-03-01 14:55:50 +01:00 committed by WebRTC LUCI CQ
parent 0925fe36cf
commit 8cb31cf125
3 changed files with 12 additions and 8 deletions

View file

@ -309,18 +309,20 @@ class RTC_LOCKABLE RTC_EXPORT Thread : public webrtc::TaskQueueBase {
// See ScopedDisallowBlockingCalls for details.
// NOTE: Blocking calls are DISCOURAGED, consider if what you're doing can
// be achieved with PostTask() and callbacks instead.
// TODO(crbug.com/1416199): Remove virtual and pass location of the caller
// once subclasses migrated.
virtual void BlockingCall(FunctionView<void()> functor) {
BlockingCallImpl(std::move(functor), webrtc::Location::Current());
void BlockingCall(
FunctionView<void()> functor,
const webrtc::Location& location = webrtc::Location::Current()) {
BlockingCallImpl(std::move(functor), location);
}
template <typename Functor,
typename ReturnT = std::invoke_result_t<Functor>,
typename = typename std::enable_if_t<!std::is_void_v<ReturnT>>>
ReturnT BlockingCall(Functor&& functor) {
ReturnT BlockingCall(
Functor&& functor,
const webrtc::Location& location = webrtc::Location::Current()) {
ReturnT result;
BlockingCall([&] { result = std::forward<Functor>(functor)(); });
BlockingCall([&] { result = std::forward<Functor>(functor)(); }, location);
return result;
}

View file

@ -61,7 +61,8 @@ void SimulatedThread::RunReady(Timestamp at_time) {
}
}
void SimulatedThread::BlockingCall(rtc::FunctionView<void()> functor) {
void SimulatedThread::BlockingCallImpl(rtc::FunctionView<void()> functor,
const Location& /*location*/) {
if (IsQuitting())
return;

View file

@ -36,7 +36,8 @@ class SimulatedThread : public rtc::Thread,
TaskQueueBase* GetAsTaskQueue() override { return this; }
// Thread interface
void BlockingCall(rtc::FunctionView<void()> functor) override;
void BlockingCallImpl(rtc::FunctionView<void()> functor,
const Location& location) override;
void PostTaskImpl(absl::AnyInvocable<void() &&> task,
const PostTaskTraits& traits,
const Location& location) override;