From: Daniel Wagner Date: Mon, 31 Oct 2011 12:19:11 +0000 (+0100) Subject: gweb: Use gcc atomics instead glib's ones X-Git-Tag: 0.78~57 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=1b45ea1b9fb70daa4b4a2905ebd9d12b9c7140d0;p=platform%2Fupstream%2Fconnman.git gweb: Use gcc atomics instead glib's ones 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. --- diff --git a/gweb/giognutls.c b/gweb/giognutls.c index a9b734f..d92ae95 100644 --- a/gweb/giognutls.c +++ b/gweb/giognutls.c @@ -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(); } diff --git a/gweb/gresolv.c b/gweb/gresolv.c index 326b5f9..6bfc20a 100644 --- a/gweb/gresolv.c +++ b/gweb/gresolv.c @@ -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))) diff --git a/gweb/gweb.c b/gweb/gweb.c index b7cfe62..5c3305e 100644 --- a/gweb/gweb.c +++ b/gweb/gweb.c @@ -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);