mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-14 14:46:12 -04:00
internal update
PiperOrigin-RevId: 547982511
This commit is contained in:
committed by
Copybara-Service
parent
99de15aef5
commit
a72be2bc8c
@@ -15,9 +15,7 @@
|
||||
#include "internal/test/fake_timer.h"
|
||||
|
||||
#include <functional>
|
||||
#include <future> // NOLINT
|
||||
#include <string>
|
||||
#include <thread> // NOLINT
|
||||
#include <utility>
|
||||
|
||||
#include "absl/time/clock.h"
|
||||
@@ -62,6 +60,10 @@ void FakeTimer::ClockUpdated() {
|
||||
absl::Time now = clock_->Now();
|
||||
int64_t duration = absl::ToInt64Milliseconds(now - start_time_);
|
||||
FakeClock* clock = clock_;
|
||||
// The timer may be released during callback, save period and delay to avoid
|
||||
// access exception.
|
||||
int period = period_;
|
||||
int delay = delay_;
|
||||
|
||||
if (duration >= delay_ && fired_count_ == 0) {
|
||||
++fired_count_;
|
||||
@@ -70,12 +72,12 @@ void FakeTimer::ClockUpdated() {
|
||||
}
|
||||
}
|
||||
|
||||
if (period_ == 0 || duration < delay_ ||
|
||||
if (period == 0 || duration < delay ||
|
||||
((clock_ != nullptr) && (clock_ != clock))) {
|
||||
return;
|
||||
}
|
||||
|
||||
int count = (duration - delay_) / period_;
|
||||
int count = (duration - delay) / period;
|
||||
int should_fire_count = count - fired_count_ + 1;
|
||||
for (int i = 0; i < should_fire_count; ++i) {
|
||||
++fired_count_;
|
||||
|
||||
@@ -39,7 +39,7 @@ class FakeTimer : public Timer {
|
||||
|
||||
std::string id_;
|
||||
int delay_ = 0;
|
||||
int period_ = false;
|
||||
int period_ = 0;
|
||||
int fired_count_ = 0;
|
||||
absl::Time start_time_;
|
||||
bool is_started_ = false;
|
||||
|
||||
Reference in New Issue
Block a user