[glibmm/glibmm-2-54] Glib::TimeoutSource: Use monotonic time consistently
- From: Kjell Ahlstedt <kjellahl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glibmm/glibmm-2-54] Glib::TimeoutSource: Use monotonic time consistently
- Date: Thu, 25 Jan 2018 09:07:16 +0000 (UTC)
commit e9330a8ec08f587b9a01bf33f14dbc5ddacf33db
Author: Kjell Ahlstedt <kjellahlstedt gmail com>
Date: Thu Jan 25 10:03:04 2018 +0100
Glib::TimeoutSource: Use monotonic time consistently
* glib/glibmm/main.[cc|h]: Use Source::get_time() consistently.
Remove a misleading sentence from the documentation of
Source::get_current_time(). Bug 792524
glib/glibmm/main.cc | 21 +++++----------------
glib/glibmm/main.h | 7 +++----
2 files changed, 8 insertions(+), 20 deletions(-)
---
diff --git a/glib/glibmm/main.cc b/glib/glibmm/main.cc
index 68f2176..25ae0a7 100644
--- a/glib/glibmm/main.cc
+++ b/glib/glibmm/main.cc
@@ -32,7 +32,6 @@
namespace
{
-#ifdef GLIBMM_DISABLE_DEPRECATED
void
time64_to_time_val(gint64 time64, Glib::TimeVal& time_val)
{
@@ -42,7 +41,6 @@ time64_to_time_val(gint64 time64, Glib::TimeVal& time_val)
static_cast<long>(time64 - static_cast<gint64>(seconds) * G_GINT64_CONSTANT(1000000));
time_val = Glib::TimeVal(seconds, microseconds);
}
-#endif // GLIBMM_DISABLE_DEPRECATED
// TODO: At the next ABI break, replace ExtraSourceData by new data members in Source.
// Then the mutex is not necessary, but to keep the code thread-safe, use the
@@ -1031,7 +1029,10 @@ G_GNUC_END_IGNORE_DEPRECATIONS
gint64
Source::get_time() const
{
- return g_source_get_time(const_cast<GSource*>(gobject_));
+ if (g_source_get_context(const_cast<GSource*>(gobject_)))
+ return g_source_get_time(const_cast<GSource*>(gobject_));
+ else
+ return g_get_monotonic_time();
}
inline // static
@@ -1167,7 +1168,7 @@ TimeoutSource::connect(const sigc::slot<bool>& slot)
TimeoutSource::TimeoutSource(unsigned int interval) : interval_(interval)
{
- expiration_.assign_current_time();
+ time64_to_time_val(get_time(), expiration_);
expiration_.add_milliseconds(std::min<unsigned long>(G_MAXLONG, interval_));
}
@@ -1179,11 +1180,7 @@ bool
TimeoutSource::prepare(int& timeout)
{
Glib::TimeVal current_time;
-#ifndef GLIBMM_DISABLE_DEPRECATED
- get_current_time(current_time);
-#else
time64_to_time_val(get_time(), current_time);
-#endif // GLIBMM_DISABLE_DEPRECATED
Glib::TimeVal remaining = expiration_;
remaining.subtract(current_time);
@@ -1220,11 +1217,7 @@ bool
TimeoutSource::check()
{
Glib::TimeVal current_time;
-#ifndef GLIBMM_DISABLE_DEPRECATED
- get_current_time(current_time);
-#else
time64_to_time_val(get_time(), current_time);
-#endif // GLIBMM_DISABLE_DEPRECATED
return (expiration_ <= current_time);
}
@@ -1236,11 +1229,7 @@ TimeoutSource::dispatch(sigc::slot_base* slot)
if (again)
{
-#ifndef GLIBMM_DISABLE_DEPRECATED
- get_current_time(expiration_);
-#else
time64_to_time_val(get_time(), expiration_);
-#endif // GLIBMM_DISABLE_DEPRECATED
expiration_.add_milliseconds(std::min<unsigned long>(G_MAXLONG, interval_));
}
diff --git a/glib/glibmm/main.h b/glib/glibmm/main.h
index 1b9a853..3b5e75e 100644
--- a/glib/glibmm/main.h
+++ b/glib/glibmm/main.h
@@ -790,10 +790,9 @@ protected:
void remove_poll(PollFD& poll_fd);
#ifndef GLIBMM_DISABLE_DEPRECATED
- /** Gets the "current time" to be used when checking this source. The advantage of calling this
- * function over calling get_current_time() directly is that when checking multiple sources, GLib
- * can cache a single value instead of having to repeatedly get the system time.
- * @param current_time Glib::TimeVal in which to store current time.
+ /** Gets the "current time" to be used when checking this source.
+ *
+ * @param[out] current_time Glib::TimeVal in which to store current time.
*
* @deprecated Use get_time() instead.
*/
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]