You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: time-alarm-service/src/lib.rs
+6-5Lines changed: 6 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -205,8 +205,8 @@ impl Service {
205
205
206
206
// TODO [POWER_SOURCE] we need to subscribe to messages that tell us if we're on AC or DC power so we can decide which alarms to trigger, but those notifications are not yet implemented - revisit when they are.
207
207
// TODO [POWER_SOURCE] if it's possible to learn which power source is active at init time, we should set that one active rather than defaulting to the AC timer.
let total_seconds_elapsed_on_policy_delay:u32 = seconds_elapsed_before_wait
231
-
+ (Self::get_current_datetime(clock_state)
232
-
.to_unix_time_seconds()
233
-
.saturating_sub(wait_start_time.to_unix_time_seconds())asu32);// The ACPI spec expresses timeouts in terms of u32s - it's impossible to schedule a timer u32::MAX seconds in the future
253
+
let total_seconds_elapsed_on_policy_delay = matchSelf::get_current_datetime(clock_state){
let now = Self::get_current_datetime(clock_state);
287
-
let expiration_time = timer_state.persistent_storage.get_expiration_time().unwrap_or_else(|| {
288
-
error!("[Time/Alarm] Timer expired when no expiration time was set - this should never happen");
289
-
Datetime::from_unix_time_seconds(0)
290
-
});
291
-
if now.to_unix_time_seconds() < expiration_time.to_unix_time_seconds(){
292
-
// Time hasn't actually passed the mark yet - this can happen if we were reprogrammed with a different time right as the old timer was expiring. Reset the timer.
293
-
timer_state.wake_state = WakeState::Armed;
294
-
self.timer_signal.signal(Some(
295
-
expiration_time
296
-
.to_unix_time_seconds()
297
-
.saturating_sub(now.to_unix_time_seconds())asu32,
298
-
));
299
-
returnfalse;
325
+
let expiration_time = match timer_state.persistent_storage.get_expiration_time(){
326
+
Some(now) => now,
327
+
None => {
328
+
error!(
329
+
"[Time/Alarm] Timer expired when no expiration time was set - this should never happen"
330
+
);
331
+
returnfalse;
332
+
}
333
+
};
334
+
335
+
matchSelf::get_current_datetime(clock_state){
336
+
Ok(now) => {
337
+
if now.to_unix_time_seconds() < expiration_time.to_unix_time_seconds(){
338
+
// Time hasn't actually passed the mark yet - this can happen if we were reprogrammed with a different time right as the old timer was expiring. Reset the timer.
339
+
timer_state.wake_state = WakeState::Armed;
340
+
self.timer_signal.signal(Some(
341
+
expiration_time
342
+
.to_unix_time_seconds()
343
+
.saturating_sub(now.to_unix_time_seconds())
344
+
asu32,
345
+
));
346
+
returnfalse;
347
+
}
348
+
}
349
+
Err(_) => {
350
+
// This should never happen, because it means the clock is not working after we've successfully initialized (which
351
+
// requires the clock to be working).
352
+
// If it does, though, we don't have a way to communicate failure to the host PC at this point, so we'll just
353
+
// wake the device immediately on the assumption that the alarm has actually expired. This gets it wrong in the case
354
+
// where the timer is reprogrammed immediately as it expires, but that's an extremely rare case and we can't do better
355
+
// than that if our clock is broken.
356
+
error!("[Time/Alarm] Failed to get current datetime when processing expired timer");
0 commit comments