GNOME Bugzilla – Bug 668738
g_get_monotonic_time() incorrectly uses g_once_init_leave()
Last modified: 2012-01-26 14:44:59 UTC
The second argument to g_once_init_leave() must be non-zero. In environments which #define the clockid to be used (CLOCK_MONOTONIC or CLOCK_REALTIME) as 0, the current code in g_get_monotonic_time() triggers an assertion in g_once_init_leave() and apparently can not function as expected. A possible fix might be like --- glib/gmain.c.ori 2012-01-25 21:27:35.000000000 +0100 +++ glib/gmain.c 2012-01-25 21:38:43.000000000 +0100 @@ -2043,22 +2043,21 @@ /* librt clock_gettime() is our first choice */ { #ifdef HAVE_MONOTONIC_CLOCK - static volatile gsize clockid = 0; + static volatile gsize clockid = CLOCK_REALTIME; + static volatile gsize clockid_guard = 0; #else static clockid_t clockid = CLOCK_REALTIME; #endif struct timespec ts; #ifdef HAVE_MONOTONIC_CLOCK - if (g_once_init_enter (&clockid)) + if (g_once_init_enter (&clockid_guard)) { - clockid_t best_clockid; - if (sysconf (_SC_MONOTONIC_CLOCK) >= 0) - best_clockid = CLOCK_MONOTONIC; + clockid = CLOCK_MONOTONIC; else - best_clockid = CLOCK_REALTIME; - g_once_init_leave (&clockid, (gsize)best_clockid); + clockid = CLOCK_REALTIME; + g_once_init_leave (&clockid_guard, (gsize)1); } #endif
already fixed in master *** This bug has been marked as a duplicate of bug 661421 ***