diff --git a/attrib/gatt.c b/attrib/gatt.c
index 38d455a..749e820 100644
--- a/attrib/gatt.c
+++ b/attrib/gatt.c
static struct included_discovery *isd_ref(struct included_discovery *isd)
{
- g_atomic_int_inc(&isd->refs);
+ __sync_fetch_and_add(&isd->refs, 1);
return isd;
}
static void isd_unref(struct included_discovery *isd)
{
- if (g_atomic_int_dec_and_test(&isd->refs) == FALSE)
+ if (__sync_sub_and_fetch(&isd->refs, 1) > 0)
return;
if (isd->err)
{
struct read_long_data *long_read = user_data;
- if (g_atomic_int_dec_and_test(&long_read->ref) == FALSE)
+ if (__sync_sub_and_fetch(&long_read->ref, 1) > 0)
return;
if (long_read->buffer != NULL)
read_blob_helper, long_read, read_long_destroy);
if (id != 0) {
- g_atomic_int_inc(&long_read->ref);
+ __sync_fetch_and_add(&long_read->ref, 1);
return;
}
id = g_attrib_send(long_read->attrib, long_read->id, buf, plen,
read_blob_helper, long_read, read_long_destroy);
if (id != 0) {
- g_atomic_int_inc(&long_read->ref);
+ __sync_fetch_and_add(&long_read->ref, 1);
return;
}
if (id == 0)
g_free(long_read);
else {
- g_atomic_int_inc(&long_read->ref);
+ __sync_fetch_and_add(&long_read->ref, 1);
long_read->id = id;
}
diff --git a/attrib/gattrib.c b/attrib/gattrib.c
index 37581a3..e6d6022 100644
--- a/attrib/gattrib.c
+++ b/attrib/gattrib.c
GAttrib *g_attrib_ref(GAttrib *attrib)
{
+ int refs;
+
if (!attrib)
return NULL;
- g_atomic_int_inc(&attrib->refs);
+ refs = __sync_add_and_fetch(&attrib->refs, 1);
- DBG("%p: ref=%d", attrib, attrib->refs);
+ DBG("%p: ref=%d", attrib, refs);
return attrib;
}
void g_attrib_unref(GAttrib *attrib)
{
- gboolean ret;
+ int refs;
if (!attrib)
return;
- ret = g_atomic_int_dec_and_test(&attrib->refs);
+ refs = __sync_sub_and_fetch(&attrib->refs, 1);
- DBG("%p: ref=%d", attrib, attrib->refs);
+ DBG("%p: ref=%d", attrib, refs);
- if (ret == FALSE)
+ if (refs > 0)
return;
attrib_destroy(attrib);