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/tethering.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/tethering.c')
-rw-r--r-- | src/tethering.c | 83 |
1 files changed, 43 insertions, 40 deletions
diff --git a/src/tethering.c b/src/tethering.c index c362b8d6..b4ab993c 100644 --- a/src/tethering.c +++ b/src/tethering.c @@ -65,7 +65,7 @@ #define PRIVATE_NETWORK_SECONDARY_DNS "8.8.4.4" static char *default_interface = NULL; -static volatile gint tethering_enabled; +static volatile int tethering_enabled; static GDHCPServer *tethering_dhcp_server = NULL; static DBusConnection *connection; static GHashTable *pn_hash; @@ -336,44 +336,44 @@ static void disable_nat(const char *interface) void __connman_tethering_set_enabled(void) { int err; + const char *dns; DBG("enabled %d", tethering_enabled + 1); - if (g_atomic_int_exchange_and_add(&tethering_enabled, 1) == 0) { - const char *dns; + if (__sync_fetch_and_add(&tethering_enabled, 1) != 0) + return; - err = create_bridge(BRIDGE_NAME); - if (err < 0) - return; + err = create_bridge(BRIDGE_NAME); + if (err < 0) + return; - err = enable_bridge(BRIDGE_NAME); - if (err < 0) { - remove_bridge(BRIDGE_NAME); - return; - } + err = enable_bridge(BRIDGE_NAME); + if (err < 0) { + remove_bridge(BRIDGE_NAME); + return; + } - dns = BRIDGE_IP; - if (__connman_dnsproxy_add_listener(BRIDGE_NAME) < 0) { - connman_error("Can't add listener %s to DNS proxy", + dns = BRIDGE_IP; + if (__connman_dnsproxy_add_listener(BRIDGE_NAME) < 0) { + connman_error("Can't add listener %s to DNS proxy", BRIDGE_NAME); - dns = BRIDGE_DNS; - } - - tethering_dhcp_server = - dhcp_server_start(BRIDGE_NAME, - BRIDGE_IP, BRIDGE_SUBNET, - BRIDGE_IP_START, BRIDGE_IP_END, - 24 * 3600, dns); - if (tethering_dhcp_server == NULL) { - disable_bridge(BRIDGE_NAME); - remove_bridge(BRIDGE_NAME); - return; - } - - enable_nat(default_interface); - - DBG("tethering started"); + dns = BRIDGE_DNS; + } + + tethering_dhcp_server = + dhcp_server_start(BRIDGE_NAME, + BRIDGE_IP, BRIDGE_SUBNET, + BRIDGE_IP_START, BRIDGE_IP_END, + 24 * 3600, dns); + if (tethering_dhcp_server == NULL) { + disable_bridge(BRIDGE_NAME); + remove_bridge(BRIDGE_NAME); + return; } + + enable_nat(default_interface); + + DBG("tethering started"); } void __connman_tethering_set_disabled(void) @@ -382,17 +382,18 @@ void __connman_tethering_set_disabled(void) __connman_dnsproxy_remove_listener(BRIDGE_NAME); - if (g_atomic_int_dec_and_test(&tethering_enabled) == TRUE) { - disable_nat(default_interface); + if (__sync_fetch_and_sub(&tethering_enabled, 1) != 1) + return; + + disable_nat(default_interface); - dhcp_server_stop(tethering_dhcp_server); + dhcp_server_stop(tethering_dhcp_server); - disable_bridge(BRIDGE_NAME); + disable_bridge(BRIDGE_NAME); - remove_bridge(BRIDGE_NAME); + remove_bridge(BRIDGE_NAME); - DBG("tethering stopped"); - } + DBG("tethering stopped"); } void __connman_tethering_update_interface(const char *interface) @@ -410,7 +411,8 @@ void __connman_tethering_update_interface(const char *interface) default_interface = g_strdup(interface); - if (!g_atomic_int_get(&tethering_enabled)) + __sync_synchronize(); + if (tethering_enabled == 0) return; enable_nat(interface); @@ -613,7 +615,8 @@ void __connman_tethering_cleanup(void) { DBG(""); - if (g_atomic_int_get(&tethering_enabled)) { + __sync_synchronize(); + if (tethering_enabled == 0) { if (tethering_dhcp_server) dhcp_server_stop(tethering_dhcp_server); disable_bridge(BRIDGE_NAME); |