Skip to content

Commit

Permalink
Implement support for Chrome task origin tracing. #4/4
Browse files Browse the repository at this point in the history
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}
  • Loading branch information
Markus Handell authored and WebRTC LUCI CQ committed Mar 1, 2023
1 parent 0925fe3 commit 8cb31cf
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
14 changes: 8 additions & 6 deletions rtc_base/thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
3 changes: 2 additions & 1 deletion test/time_controller/simulated_thread.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
3 changes: 2 additions & 1 deletion test/time_controller/simulated_thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 8cb31cf

Please sign in to comment.