After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 668738 - g_get_monotonic_time() incorrectly uses g_once_init_leave()
g_get_monotonic_time() incorrectly uses g_once_init_leave()
Status: RESOLVED DUPLICATE of bug 661421
Product: glib
Classification: Platform
Component: general
2.30.x
Other Linux
: Normal major
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks:
 
 
Reported: 2012-01-26 13:02 UTC by rl
Modified: 2012-01-26 14:44 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description rl 2012-01-26 13:02:31 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
Comment 1 Dan Winship 2012-01-26 14:44:59 UTC
already fixed in master

*** This bug has been marked as a duplicate of bug 661421 ***