diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 01:13:27 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 01:13:27 +0000 |
commit | 40a355a42d4a9444dc753c04c6608dade2f06a23 (patch) | |
tree | 871fc667d2de662f171103ce5ec067014ef85e61 /third_party/libwebrtc/net/dcsctp/timer/fake_timeout.h | |
parent | Adding upstream version 124.0.1. (diff) | |
download | firefox-40a355a42d4a9444dc753c04c6608dade2f06a23.tar.xz firefox-40a355a42d4a9444dc753c04c6608dade2f06a23.zip |
Adding upstream version 125.0.1.upstream/125.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/libwebrtc/net/dcsctp/timer/fake_timeout.h')
-rw-r--r-- | third_party/libwebrtc/net/dcsctp/timer/fake_timeout.h | 37 |
1 files changed, 19 insertions, 18 deletions
diff --git a/third_party/libwebrtc/net/dcsctp/timer/fake_timeout.h b/third_party/libwebrtc/net/dcsctp/timer/fake_timeout.h index 4621b2ce83..cac49287d4 100644 --- a/third_party/libwebrtc/net/dcsctp/timer/fake_timeout.h +++ b/third_party/libwebrtc/net/dcsctp/timer/fake_timeout.h @@ -19,6 +19,7 @@ #include "absl/types/optional.h" #include "api/task_queue/task_queue_base.h" +#include "api/units/timestamp.h" #include "net/dcsctp/public/timeout.h" #include "net/dcsctp/public/types.h" #include "rtc_base/checks.h" @@ -29,46 +30,46 @@ namespace dcsctp { // A timeout used in tests. class FakeTimeout : public Timeout { public: - FakeTimeout(std::function<TimeMs()> get_time, + FakeTimeout(std::function<webrtc::Timestamp()> get_time, std::function<void(FakeTimeout*)> on_delete) : get_time_(std::move(get_time)), on_delete_(std::move(on_delete)) {} ~FakeTimeout() override { on_delete_(this); } void Start(DurationMs duration_ms, TimeoutID timeout_id) override { - RTC_DCHECK(expiry_ == TimeMs::InfiniteFuture()); + RTC_DCHECK(expiry_.IsPlusInfinity()); timeout_id_ = timeout_id; - expiry_ = get_time_() + duration_ms; + expiry_ = get_time_() + duration_ms.ToTimeDelta(); } void Stop() override { - RTC_DCHECK(expiry_ != TimeMs::InfiniteFuture()); - expiry_ = TimeMs::InfiniteFuture(); + RTC_DCHECK(!expiry_.IsPlusInfinity()); + expiry_ = webrtc::Timestamp::PlusInfinity(); } - bool EvaluateHasExpired(TimeMs now) { + bool EvaluateHasExpired(webrtc::Timestamp now) { if (now >= expiry_) { - expiry_ = TimeMs::InfiniteFuture(); + expiry_ = webrtc::Timestamp::PlusInfinity(); return true; } return false; } TimeoutID timeout_id() const { return timeout_id_; } - TimeMs expiry() const { return expiry_; } + webrtc::Timestamp expiry() const { return expiry_; } private: - const std::function<TimeMs()> get_time_; + const std::function<webrtc::Timestamp()> get_time_; const std::function<void(FakeTimeout*)> on_delete_; TimeoutID timeout_id_ = TimeoutID(0); - TimeMs expiry_ = TimeMs::InfiniteFuture(); + webrtc::Timestamp expiry_ = webrtc::Timestamp::PlusInfinity(); }; class FakeTimeoutManager { public: // The `get_time` function must return the current time, relative to any // epoch. - explicit FakeTimeoutManager(std::function<TimeMs()> get_time) + explicit FakeTimeoutManager(std::function<webrtc::Timestamp()> get_time) : get_time_(std::move(get_time)) {} std::unique_ptr<FakeTimeout> CreateTimeout() { @@ -89,7 +90,7 @@ class FakeTimeoutManager { // Timer::is_running_ to false before you operate on the Timer or Timeout // again. absl::optional<TimeoutID> GetNextExpiredTimeout() { - TimeMs now = get_time_(); + webrtc::Timestamp now = get_time_(); std::vector<TimeoutID> expired_timers; for (auto& timer : timers_) { if (timer->EvaluateHasExpired(now)) { @@ -99,21 +100,21 @@ class FakeTimeoutManager { return absl::nullopt; } - DurationMs GetTimeToNextTimeout() const { - TimeMs next_expiry = TimeMs::InfiniteFuture(); + webrtc::TimeDelta GetTimeToNextTimeout() const { + webrtc::Timestamp next_expiry = webrtc::Timestamp::PlusInfinity(); for (const FakeTimeout* timer : timers_) { if (timer->expiry() < next_expiry) { next_expiry = timer->expiry(); } } - TimeMs now = get_time_(); - return next_expiry != TimeMs::InfiniteFuture() && next_expiry >= now + webrtc::Timestamp now = get_time_(); + return !next_expiry.IsPlusInfinity() && next_expiry >= now ? next_expiry - now - : DurationMs::InfiniteDuration(); + : webrtc::TimeDelta::PlusInfinity(); } private: - const std::function<TimeMs()> get_time_; + const std::function<webrtc::Timestamp()> get_time_; webrtc::flat_set<FakeTimeout*> timers_; }; |