gdhcp: Use gcc atomics instead glib's ones
authorDaniel Wagner <daniel.wagner@bmw-carit.de>
Mon, 31 Oct 2011 12:19:12 +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.

gdhcp/client.c
gdhcp/server.c

index 24614c7..3270346 100644 (file)
@@ -72,7 +72,7 @@ typedef enum _dhcp_client_state {
 } ClientState;
 
 struct _GDHCPClient {
-       gint ref_count;
+       int ref_count;
        GDHCPType type;
        ClientState state;
        int ifindex;
@@ -1506,7 +1506,7 @@ GDHCPClient *g_dhcp_client_ref(GDHCPClient *dhcp_client)
        if (dhcp_client == NULL)
                return NULL;
 
-       g_atomic_int_inc(&dhcp_client->ref_count);
+       __sync_fetch_and_add(&dhcp_client->ref_count, 1);
 
        return dhcp_client;
 }
@@ -1516,7 +1516,7 @@ void g_dhcp_client_unref(GDHCPClient *dhcp_client)
        if (dhcp_client == NULL)
                return;
 
-       if (g_atomic_int_dec_and_test(&dhcp_client->ref_count) == FALSE)
+       if (__sync_fetch_and_sub(&dhcp_client->ref_count, 1) != 1)
                return;
 
        g_dhcp_client_stop(dhcp_client);
index 54c068b..4f0b5b7 100644 (file)
@@ -49,7 +49,7 @@
 #define OFFER_TIME (5*60)
 
 struct _GDHCPServer {
-       gint ref_count;
+       int ref_count;
        GDHCPType type;
        gboolean started;
        int ifindex;
@@ -821,7 +821,7 @@ GDHCPServer *g_dhcp_server_ref(GDHCPServer *dhcp_server)
        if (dhcp_server == NULL)
                return NULL;
 
-       g_atomic_int_inc(&dhcp_server->ref_count);
+       __sync_fetch_and_add(&dhcp_server->ref_count, 1);
 
        return dhcp_server;
 }
@@ -846,7 +846,7 @@ void g_dhcp_server_unref(GDHCPServer *dhcp_server)
        if (dhcp_server == NULL)
                return;
 
-       if (g_atomic_int_dec_and_test(&dhcp_server->ref_count) == FALSE)
+       if (__sync_fetch_and_sub(&dhcp_server->ref_count, 1) != 1)
                return;
 
        g_dhcp_server_stop(dhcp_server);