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/timer.cc | |
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/timer.cc')
-rw-r--r-- | third_party/libwebrtc/net/dcsctp/timer/timer.cc | 35 |
1 files changed, 19 insertions, 16 deletions
diff --git a/third_party/libwebrtc/net/dcsctp/timer/timer.cc b/third_party/libwebrtc/net/dcsctp/timer/timer.cc index 208f26fdf9..07c9f3d786 100644 --- a/third_party/libwebrtc/net/dcsctp/timer/timer.cc +++ b/third_party/libwebrtc/net/dcsctp/timer/timer.cc @@ -22,21 +22,23 @@ namespace dcsctp { namespace { +using ::webrtc::TimeDelta; + TimeoutID MakeTimeoutId(TimerID timer_id, TimerGeneration generation) { return TimeoutID(static_cast<uint64_t>(*timer_id) << 32 | *generation); } -DurationMs GetBackoffDuration(const TimerOptions& options, - DurationMs base_duration, - int expiration_count) { +TimeDelta GetBackoffDuration(const TimerOptions& options, + TimeDelta base_duration, + int expiration_count) { switch (options.backoff_algorithm) { case TimerBackoffAlgorithm::kFixed: return base_duration; case TimerBackoffAlgorithm::kExponential: { - DurationMs duration = base_duration; + TimeDelta duration = base_duration; while (expiration_count > 0 && duration < Timer::kMaxTimerDuration) { - duration *= 2; + duration = duration * 2; --expiration_count; if (duration > options.max_backoff_duration) { @@ -44,13 +46,13 @@ DurationMs GetBackoffDuration(const TimerOptions& options, } } - return DurationMs(std::min(duration, Timer::kMaxTimerDuration)); + return TimeDelta(std::min(duration, Timer::kMaxTimerDuration)); } } } } // namespace -constexpr DurationMs Timer::kMaxTimerDuration; +constexpr TimeDelta Timer::kMaxTimerDuration; Timer::Timer(TimerID id, absl::string_view name, @@ -76,12 +78,12 @@ void Timer::Start() { if (!is_running()) { is_running_ = true; generation_ = TimerGeneration(*generation_ + 1); - timeout_->Start(duration_, MakeTimeoutId(id_, generation_)); + timeout_->Start(DurationMs(duration_), MakeTimeoutId(id_, generation_)); } else { // Timer was running - stop and restart it, to make it expire in `duration_` // from now. generation_ = TimerGeneration(*generation_ + 1); - timeout_->Restart(duration_, MakeTimeoutId(id_, generation_)); + timeout_->Restart(DurationMs(duration_), MakeTimeoutId(id_, generation_)); } } @@ -103,23 +105,24 @@ void Timer::Trigger(TimerGeneration generation) { // timer. Note that it might be very quickly restarted again, if the // `on_expired_` callback returns a new duration. is_running_ = true; - DurationMs duration = + TimeDelta duration = GetBackoffDuration(options_, duration_, expiration_count_); generation_ = TimerGeneration(*generation_ + 1); - timeout_->Start(duration, MakeTimeoutId(id_, generation_)); + timeout_->Start(DurationMs(duration), MakeTimeoutId(id_, generation_)); } - absl::optional<DurationMs> new_duration = on_expired_(); - if (new_duration.has_value() && new_duration != duration_) { - duration_ = new_duration.value(); + TimeDelta new_duration = on_expired_(); + RTC_DCHECK(new_duration != TimeDelta::PlusInfinity()); + if (new_duration > TimeDelta::Zero() && new_duration != duration_) { + duration_ = new_duration; if (is_running_) { // Restart it with new duration. timeout_->Stop(); - DurationMs duration = + TimeDelta duration = GetBackoffDuration(options_, duration_, expiration_count_); generation_ = TimerGeneration(*generation_ + 1); - timeout_->Start(duration, MakeTimeoutId(id_, generation_)); + timeout_->Start(DurationMs(duration), MakeTimeoutId(id_, generation_)); } } } |