bluez: atomic operations

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

using gcc atomic buildins breaks support for older gcc/platforms.

src/bluetoothd-adapter.o: In function `btd_adapter_unref':
adapter.c:(.text+0x63f8): undefined reference to `__sync_sub_and_fetch_4'

I suggest to use glib g_atomic_* group of functions.
They fall back to traditional locking if buildins are not available.

kind regrads

andy
From 7bef8490ba50b03ce204844ef8c63c9da910b5f4 Mon Sep 17 00:00:00 2001
From: Andreas Kling <Andreas.Kling@xxxxxxxxx>
Date: Wed, 16 Jan 2013 11:44:07 +0100
Subject: [PATCH 1/2] shared: use g_atomic_* functions for ref counts

---
 src/shared/mgmt.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/shared/mgmt.c b/src/shared/mgmt.c
index f96897d..eb1a48a 100644
--- a/src/shared/mgmt.c
+++ b/src/shared/mgmt.c
@@ -410,7 +410,7 @@ struct mgmt *mgmt_ref(struct mgmt *mgmt)
 	if (!mgmt)
 		return NULL;
 
-	__sync_fetch_and_add(&mgmt->ref_count, 1);
+	g_atomic_int_inc(&mgmt->ref_count);
 
 	return mgmt;
 }
@@ -420,7 +420,7 @@ void mgmt_unref(struct mgmt *mgmt)
 	if (!mgmt)
 		return;
 
-	if (__sync_sub_and_fetch(&mgmt->ref_count, 1))
+	if (!g_atomic_int_dec_and_test(&mgmt->ref_count))
 		return;
 
 	mgmt_unregister_all(mgmt);
-- 
1.7.2.5

From cba07c715a6de4f7fd297723e2b991ee32a2ca76 Mon Sep 17 00:00:00 2001
From: Andreas Kling <Andreas.Kling@xxxxxxxxx>
Date: Wed, 16 Jan 2013 11:46:20 +0100
Subject: [PATCH 2/2] adapter: use g_atomic_* functions for ref counts

---
 src/adapter.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/adapter.c b/src/adapter.c
index 1a5b1ad..e38d54c 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -2629,14 +2629,14 @@ static void adapter_free(gpointer user_data)
 
 struct btd_adapter *btd_adapter_ref(struct btd_adapter *adapter)
 {
-	__sync_fetch_and_add(&adapter->ref_count, 1);
+	g_atomic_int_inc(&adapter->ref_count);
 
 	return adapter;
 }
 
 void btd_adapter_unref(struct btd_adapter *adapter)
 {
-	if (__sync_sub_and_fetch(&adapter->ref_count, 1))
+	if (!g_atomic_int_dec_and_test(&adapter->ref_count))
 		return;
 
 	if (!adapter->path) {
-- 
1.7.2.5


[Index of Archives]     [Bluez Devel]     [Linux Wireless Networking]     [Linux Wireless Personal Area Networking]     [Linux ATH6KL]     [Linux USB Devel]     [Linux Media Drivers]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Big List of Linux Books]

  Powered by Linux