diff options
author | Daniel Wagner <daniel.wagner@bmw-carit.de> | 2011-10-31 13:19:09 +0100 |
---|---|---|
committer | Samuel Ortiz <sameo@linux.intel.com> | 2011-11-10 13:09:50 +0100 |
commit | 9232d39e6a0738b750e97efd04124c81b7b2e583 (patch) | |
tree | 23b4bc3d39f0c6b16a55e8bc9df760e220f2c749 /src/ipconfig.c | |
parent | 6bd851d905799dfb02e66eadc37c2e85b4b8f402 (diff) | |
download | connman-9232d39e6a0738b750e97efd04124c81b7b2e583.tar.gz connman-9232d39e6a0738b750e97efd04124c81b7b2e583.tar.bz2 connman-9232d39e6a0738b750e97efd04124c81b7b2e583.zip |
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.
Diffstat (limited to 'src/ipconfig.c')
-rw-r--r-- | src/ipconfig.c | 33 |
1 files changed, 16 insertions, 17 deletions
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); } /** |