gweb: Use gcc atomics instead glib's ones
authorDaniel Wagner <daniel.wagner@bmw-carit.de>
Mon, 31 Oct 2011 12:19:11 +0000 (13:19 +0100)
committerSamuel Ortiz <sameo@linux.intel.com>
Thu, 10 Nov 2011 12:09:50 +0000 (13:09 +0100)
g_atomic_int_exchange_and_add() has been removed from glib 2.30
and g_atomic_int_add() should be used. Though there are still
quite a few distros out which do not ship a glib version with
g_atomic_int_add().

Instead of maintaing a compatiblilty glib layer we just use
the built-in functions for atomic memory access.

gweb/giognutls.c
gweb/gresolv.c
gweb/gweb.c

index a9b734f..d92ae95 100644 (file)
@@ -54,11 +54,11 @@ struct _GIOGnuTLSWatch {
        GIOCondition condition;
 };
 
-static volatile gint global_init_done = 0;
+static volatile int global_init_done = 0;
 
 static inline void g_io_gnutls_global_init(void)
 {
-       if (g_atomic_int_compare_and_exchange(&global_init_done, 0, 1) == TRUE)
+       if (__sync_bool_compare_and_swap(&global_init_done, 0, 1) == TRUE)
                gnutls_global_init();
 }
 
index 326b5f9..6bfc20a 100644 (file)
@@ -97,7 +97,7 @@ struct resolv_nameserver {
 };
 
 struct _GResolv {
-       gint ref_count;
+       int ref_count;
 
        int result_family;
 
@@ -826,7 +826,7 @@ GResolv *g_resolv_ref(GResolv *resolv)
        if (resolv == NULL)
                return NULL;
 
-       g_atomic_int_inc(&resolv->ref_count);
+       __sync_fetch_and_add(&resolv->ref_count, 1);
 
        return resolv;
 }
@@ -838,7 +838,7 @@ void g_resolv_unref(GResolv *resolv)
        if (resolv == NULL)
                return;
 
-       if (g_atomic_int_dec_and_test(&resolv->ref_count) == FALSE)
+       if (__sync_fetch_and_sub(&resolv->ref_count, 1) != 1)
                return;
 
        while ((query = g_queue_pop_head(resolv->query_queue)))
index b7cfe62..5c3305e 100644 (file)
@@ -97,7 +97,7 @@ struct web_session {
 };
 
 struct _GWeb {
-       gint ref_count;
+       int ref_count;
 
        guint next_query_id;
 
@@ -228,7 +228,7 @@ GWeb *g_web_ref(GWeb *web)
        if (web == NULL)
                return NULL;
 
-       g_atomic_int_inc(&web->ref_count);
+       __sync_fetch_and_add(&web->ref_count, 1);
 
        return web;
 }
@@ -238,7 +238,7 @@ void g_web_unref(GWeb *web)
        if (web == NULL)
                return;
 
-       if (g_atomic_int_dec_and_test(&web->ref_count) == FALSE)
+       if (__sync_fetch_and_sub(&web->ref_count, 1) != 1)
                return;
 
        flush_sessions(web);
@@ -1316,7 +1316,7 @@ GWebParser *g_web_parser_ref(GWebParser *parser)
        if (parser == NULL)
                return NULL;
 
-       g_atomic_int_inc(&parser->ref_count);
+       __sync_fetch_and_add(&parser->ref_count, 1);
 
        return parser;
 }
@@ -1326,7 +1326,7 @@ void g_web_parser_unref(GWebParser *parser)
        if (parser == NULL)
                return;
 
-       if (g_atomic_int_dec_and_test(&parser->ref_count) == FALSE)
+       if (__sync_fetch_and_sub(&parser->ref_count, 1) != 1)
                return;
 
        g_string_free(parser->content, TRUE);