From 9232d39e6a0738b750e97efd04124c81b7b2e583 Mon Sep 17 00:00:00 2001 From: Daniel Wagner Date: Mon, 31 Oct 2011 13:19:09 +0100 Subject: core: 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. --- src/ipconfig.c | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) (limited to 'src/ipconfig.c') diff --git a/src/ipconfig.c b/src/ipconfig.c index da61446e..b4729903 100644 --- a/src/ipconfig.c +++ b/src/ipconfig.c @@ -40,7 +40,7 @@ #include "connman.h" struct connman_ipconfig { - gint refcount; + int refcount; int index; enum connman_ipconfig_type type; @@ -1307,10 +1307,9 @@ struct connman_ipconfig *connman_ipconfig_create(int index, */ struct connman_ipconfig *connman_ipconfig_ref(struct connman_ipconfig *ipconfig) { - DBG("ipconfig %p refcount %d", ipconfig, - g_atomic_int_get(&ipconfig->refcount) + 1); + DBG("ipconfig %p refcount %d", ipconfig, ipconfig->refcount + 1); - g_atomic_int_inc(&ipconfig->refcount); + __sync_fetch_and_add(&ipconfig->refcount, 1); return ipconfig; } @@ -1326,24 +1325,24 @@ void connman_ipconfig_unref(struct connman_ipconfig *ipconfig) if (ipconfig == NULL) return; - DBG("ipconfig %p refcount %d", ipconfig, - g_atomic_int_get(&ipconfig->refcount) - 1); + DBG("ipconfig %p refcount %d", ipconfig, ipconfig->refcount - 1); - if (g_atomic_int_dec_and_test(&ipconfig->refcount) == TRUE) { - __connman_ipconfig_disable(ipconfig); + if (__sync_fetch_and_sub(&ipconfig->refcount, 1) != 1) + return; - connman_ipconfig_set_ops(ipconfig, NULL); + __connman_ipconfig_disable(ipconfig); - if (ipconfig->origin != NULL) { - connman_ipconfig_unref(ipconfig->origin); - ipconfig->origin = NULL; - } + connman_ipconfig_set_ops(ipconfig, NULL); - connman_ipaddress_free(ipconfig->system); - connman_ipaddress_free(ipconfig->address); - g_free(ipconfig->last_dhcp_address); - g_free(ipconfig); + if (ipconfig->origin != NULL) { + connman_ipconfig_unref(ipconfig->origin); + ipconfig->origin = NULL; } + + connman_ipaddress_free(ipconfig->system); + connman_ipaddress_free(ipconfig->address); + g_free(ipconfig->last_dhcp_address); + g_free(ipconfig); } /** -- cgit v1.2.3