
This reverts commit af1b9ceb62dce3462083f9a44e26ee6d79639cef. Reason for revert: Speculative reland after looking into downstream failures. It's possible that carryover state from unrelated tests running in parallel was causing failures. Original change's description: > Revert "Revert back to using the task_queue_ for guarding access." > > This reverts commit 475006d4a30f8bc47f82eb540a6a066da2829095. > > Reason for revert: Speculative revert. Breaks downstream project > > Original change's description: > > Revert back to using the task_queue_ for guarding access. > > > > This removes the SequenceChecker that was temporarily used while > > the rtc::Thread TQ implementation was being fixed. > > > > Bug: none > > Change-Id: Iaa46e47371211ac0a97b2dcaf23cef12b43ee8ea > > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/175081 > > Commit-Queue: Tommi <tommi@webrtc.org> > > Reviewed-by: Sebastian Jansson <srte@webrtc.org> > > Cr-Commit-Position: refs/heads/master@{#31256} > > TBR=tommi@webrtc.org,srte@webrtc.org > > Change-Id: I17a12bdca888a63f2fd161da30c0def5b9c3d04e > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Bug: none > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/175103 > Reviewed-by: Artem Titov <titovartem@webrtc.org> > Commit-Queue: Artem Titov <titovartem@webrtc.org> > Cr-Commit-Position: refs/heads/master@{#31258} TBR=tommi@webrtc.org,srte@webrtc.org,titovartem@webrtc.org # Not skipping CQ checks because this is a reland. Bug: none Change-Id: I23992643126d7d6dae63da1bb14420b2b8794fd9 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/175135 Reviewed-by: Tommi <tommi@webrtc.org> Reviewed-by: Sebastian Jansson <srte@webrtc.org> Reviewed-by: Artem Titov <titovartem@webrtc.org> Commit-Queue: Tommi <tommi@webrtc.org> Cr-Commit-Position: refs/heads/master@{#31283}
90 lines
2.6 KiB
C++
90 lines
2.6 KiB
C++
/*
|
|
* Copyright 2019 The WebRTC Project Authors. All rights reserved.
|
|
*
|
|
* Use of this source code is governed by a BSD-style license
|
|
* that can be found in the LICENSE file in the root of the source
|
|
* tree. An additional intellectual property rights grant can be found
|
|
* in the file PATENTS. All contributing project authors may
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
*/
|
|
|
|
#include "rtc_base/task_utils/repeating_task.h"
|
|
|
|
#include "absl/memory/memory.h"
|
|
#include "rtc_base/logging.h"
|
|
#include "rtc_base/task_utils/to_queued_task.h"
|
|
#include "rtc_base/time_utils.h"
|
|
|
|
namespace webrtc {
|
|
namespace webrtc_repeating_task_impl {
|
|
RepeatingTaskBase::RepeatingTaskBase(TaskQueueBase* task_queue,
|
|
TimeDelta first_delay)
|
|
: task_queue_(task_queue),
|
|
next_run_time_(Timestamp::Micros(rtc::TimeMicros()) + first_delay) {
|
|
}
|
|
|
|
RepeatingTaskBase::~RepeatingTaskBase() = default;
|
|
|
|
bool RepeatingTaskBase::Run() {
|
|
RTC_DCHECK_RUN_ON(task_queue_);
|
|
// Return true to tell the TaskQueue to destruct this object.
|
|
if (next_run_time_.IsPlusInfinity())
|
|
return true;
|
|
|
|
TimeDelta delay = RunClosure();
|
|
|
|
// The closure might have stopped this task, in which case we return true to
|
|
// destruct this object.
|
|
if (next_run_time_.IsPlusInfinity())
|
|
return true;
|
|
|
|
RTC_DCHECK(delay.IsFinite());
|
|
TimeDelta lost_time = Timestamp::Micros(rtc::TimeMicros()) - next_run_time_;
|
|
next_run_time_ += delay;
|
|
delay -= lost_time;
|
|
delay = std::max(delay, TimeDelta::Zero());
|
|
|
|
task_queue_->PostDelayedTask(absl::WrapUnique(this), delay.ms());
|
|
|
|
// Return false to tell the TaskQueue to not destruct this object since we
|
|
// have taken ownership with absl::WrapUnique.
|
|
return false;
|
|
}
|
|
|
|
void RepeatingTaskBase::Stop() {
|
|
RTC_DCHECK_RUN_ON(task_queue_);
|
|
RTC_DCHECK(next_run_time_.IsFinite());
|
|
next_run_time_ = Timestamp::PlusInfinity();
|
|
}
|
|
|
|
} // namespace webrtc_repeating_task_impl
|
|
|
|
RepeatingTaskHandle::RepeatingTaskHandle(RepeatingTaskHandle&& other)
|
|
: repeating_task_(other.repeating_task_) {
|
|
other.repeating_task_ = nullptr;
|
|
}
|
|
|
|
RepeatingTaskHandle& RepeatingTaskHandle::operator=(
|
|
RepeatingTaskHandle&& other) {
|
|
repeating_task_ = other.repeating_task_;
|
|
other.repeating_task_ = nullptr;
|
|
return *this;
|
|
}
|
|
|
|
RepeatingTaskHandle::RepeatingTaskHandle(
|
|
webrtc_repeating_task_impl::RepeatingTaskBase* repeating_task)
|
|
: repeating_task_(repeating_task) {}
|
|
|
|
void RepeatingTaskHandle::Stop() {
|
|
if (repeating_task_) {
|
|
repeating_task_->Stop();
|
|
repeating_task_ = nullptr;
|
|
}
|
|
}
|
|
|
|
bool RepeatingTaskHandle::Running() const {
|
|
return repeating_task_ != nullptr;
|
|
}
|
|
|
|
} // namespace webrtc
|