aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCharles Kerr <charles.kerr@canonical.com>2014-06-10 09:06:46 -0500
committerCharles Kerr <charles.kerr@canonical.com>2014-06-10 09:06:46 -0500
commitce7397dce272c913d93a6bd3852907bc917a4e6f (patch)
tree2e9a29b004a51c73b0d074bd6c748a7dde930c55
parent79372164fe92a3022df32ef2c6812445126ac00e (diff)
downloadayatana-indicator-datetime-ce7397dce272c913d93a6bd3852907bc917a4e6f.tar.gz
ayatana-indicator-datetime-ce7397dce272c913d93a6bd3852907bc917a4e6f.tar.bz2
ayatana-indicator-datetime-ce7397dce272c913d93a6bd3852907bc917a4e6f.zip
in wakeup-timer-uha, sync with platform-api changes and add a safeguard to ensure the service doesn't try to sleep for an event that's already passed.
-rw-r--r--src/wakeup-timer-uha.cpp24
1 files changed, 16 insertions, 8 deletions
diff --git a/src/wakeup-timer-uha.cpp b/src/wakeup-timer-uha.cpp
index 0db9fb0..7e19075 100644
--- a/src/wakeup-timer-uha.cpp
+++ b/src/wakeup-timer-uha.cpp
@@ -71,16 +71,23 @@ public:
g_debug("%s %s", G_STRLOC, G_STRFUNC);
std::lock_guard<std::recursive_mutex> lg(m_mutex);
- const auto diff_usec = d - m_clock->localtime();
- struct timespec ts;
- ts.tv_sec = diff_usec / G_USEC_PER_SEC;
- ts.tv_nsec = (diff_usec % G_USEC_PER_SEC) * 1000;
- g_debug("%s setting hardware wakeup time to %s (%zu seconds from now)",
- G_STRFUNC, (size_t)ts.tv_sec, d.format("%F %T").c_str());
+ const auto wakeup_time = d.to_unix();
+
+ // simple sanity check: don't try to wait for something that's already passed
+ const auto now = m_clock->localtime().to_unix();
+ g_return_if_fail (wakeup_time >= now);
+
+ struct timespec sleep_interval;
+ sleep_interval.tv_sec = wakeup_time;
+ sleep_interval.tv_nsec = 0;
+ g_debug("%s %s setting hardware wakeup time to %s (%zu seconds from now)",
+ G_STRLOC, G_STRFUNC,
+ d.format("%F %T").c_str(),
+ (size_t)(wakeup_time - now));
u_hardware_alarm_set_relative_to_with_behavior(m_hardware_alarm,
- U_HARDWARE_ALARM_TIME_REFERENCE_NOW,
+ U_HARDWARE_ALARM_TIME_REFERENCE_RTC,
U_HARDWARE_ALARM_SLEEP_BEHAVIOR_WAKEUP_DEVICE,
- &ts);
+ &sleep_interval);
}
core::Signal<>& timeout() { return m_timeout; }
@@ -106,6 +113,7 @@ private:
{
// wait for the next hw alarm
UHardwareAlarmWaitResult wait_result;
+ g_debug ("calling wait_for_next_alarm");
auto rc = u_hardware_alarm_wait_for_next_alarm(m_hardware_alarm, &wait_result);
g_return_if_fail (rc == U_STATUS_SUCCESS);