[glib/glib-2-28] Document g_timeout_add_seconds first call latency
- From: Emilio Pozuelo Monfort <epm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib/glib-2-28] Document g_timeout_add_seconds first call latency
- Date: Sat, 12 Mar 2011 19:05:49 +0000 (UTC)
commit 7fc46fa278922b29358845531eaff4b18cd8f035
Author: Emilio Pozuelo Monfort <pochu27 gmail com>
Date: Sat Mar 12 10:08:52 2011 +0000
Document g_timeout_add_seconds first call latency
And fix /timeout/rounding to not fail if the first call
happens after 2 seconds.
https://bugzilla.gnome.org/show_bug.cgi?id=644552
glib/gmain.c | 6 +++++-
glib/tests/timeout.c | 8 +++++++-
2 files changed, 12 insertions(+), 2 deletions(-)
---
diff --git a/glib/gmain.c b/glib/gmain.c
index 3a480f3..d4f393e 100644
--- a/glib/gmain.c
+++ b/glib/gmain.c
@@ -4118,7 +4118,11 @@ g_timeout_add_seconds_full (gint priority,
* g_timeout_source_new_seconds() and attaches it to the main loop context
* using g_source_attach(). You can do these steps manually if you need
* greater control. Also see g_timout_add_seconds_full().
- *
+ *
+ * Note that the first call of the timer may not be precise for timeouts
+ * of one second. If you need finer precision and have such a timeout,
+ * you may want to use g_timeout_add() instead.
+ *
* Return value: the ID (greater than 0) of the event source.
*
* Since: 2.14
diff --git a/glib/tests/timeout.c b/glib/tests/timeout.c
index cdf5a11..825449b 100644
--- a/glib/tests/timeout.c
+++ b/glib/tests/timeout.c
@@ -53,7 +53,13 @@ test_func (gpointer data)
current_time = g_get_monotonic_time ();
- g_assert (current_time / 1000000 - last_time / 1000000 == 1);
+ /* We accept 2 on the first iteration because _add_seconds() can
+ * have an initial latency of 1 second, see its documentation.
+ */
+ if (count == 0)
+ g_assert (current_time / 1000000 - last_time / 1000000 <= 2);
+ else
+ g_assert (current_time / 1000000 - last_time / 1000000 == 1);
last_time = current_time;
count++;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]