linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* bluez: atomic operations
@ 2013-01-16 11:02 Kling, Andreas
  2013-01-17  5:25 ` Marcel Holtmann
  0 siblings, 1 reply; 4+ messages in thread
From: Kling, Andreas @ 2013-01-16 11:02 UTC (permalink / raw)
  To: linux-bluetooth@vger.kernel.org

[-- Attachment #1: Type: text/plain, Size: 359 bytes --]

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

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-shared-use-g_atomic_-functions-for-ref-counts.patch --]
[-- Type: text/x-patch; name="0001-shared-use-g_atomic_-functions-for-ref-counts.patch", Size: 872 bytes --]

From 7bef8490ba50b03ce204844ef8c63c9da910b5f4 Mon Sep 17 00:00:00 2001
From: Andreas Kling <Andreas.Kling@peiker.de>
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


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #3: 0002-adapter-use-g_atomic_-functions-for-ref-counts.patch --]
[-- Type: text/x-patch; name="0002-adapter-use-g_atomic_-functions-for-ref-counts.patch", Size: 888 bytes --]

From cba07c715a6de4f7fd297723e2b991ee32a2ca76 Mon Sep 17 00:00:00 2001
From: Andreas Kling <Andreas.Kling@peiker.de>
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


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* bluez: atomic operations
       [not found] <B3F251FD87EC894A88C2221EEEBDF54807096F7F3B@Exchange>
@ 2013-01-16 11:12 ` Kling, Andreas
  0 siblings, 0 replies; 4+ messages in thread
From: Kling, Andreas @ 2013-01-16 11:12 UTC (permalink / raw)
  To: linux-bluetooth@vger.kernel.org

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: bluez: atomic operations
  2013-01-16 11:02 bluez: atomic operations Kling, Andreas
@ 2013-01-17  5:25 ` Marcel Holtmann
  2013-01-18 12:51   ` Kling, Andreas
  0 siblings, 1 reply; 4+ messages in thread
From: Marcel Holtmann @ 2013-01-17  5:25 UTC (permalink / raw)
  To: Kling, Andreas; +Cc: linux-bluetooth@vger.kernel.org

Hi Andy,

> 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.

the GLib atomic API functions are not really stable. The GLib people for
some reason decided to break their own API/ABI guarantee. So we moved
away from using them. And I have no intention to get back to them.

Long term, we are moving away from GLib and want to switch to ELL. So
that means gcc atomics are required. My advise would be to get a modern
platform and not rely on workarounds.

Regards

Marcel



^ permalink raw reply	[flat|nested] 4+ messages in thread

* RE: bluez: atomic operations
  2013-01-17  5:25 ` Marcel Holtmann
@ 2013-01-18 12:51   ` Kling, Andreas
  0 siblings, 0 replies; 4+ messages in thread
From: Kling, Andreas @ 2013-01-18 12:51 UTC (permalink / raw)
  To: Marcel Holtmann; +Cc: linux-bluetooth@vger.kernel.org

Hi Marcel

>Hi Andy,
>
>> 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.
>
>the GLib atomic API functions are not really stable. The GLib people for
>some reason decided to break their own API/ABI guarantee. So we moved
>away from using them. And I have no intention to get back to them.
>
>Long term, we are moving away from GLib and want to switch to ELL. So
>that means gcc atomics are required. My advise would be to get a modern
>platform and not rely on workarounds.
>
>Regards
>
>Marcel

many thanks for your answer.

unfortunately a modern platform is not an option for me, hopefully changes =
some day.
so I will maintain another local patch (yieha) :P

ELL? sounds interesting... will have a look at it.

regards

andy=

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2013-01-18 12:51 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-01-16 11:02 bluez: atomic operations Kling, Andreas
2013-01-17  5:25 ` Marcel Holtmann
2013-01-18 12:51   ` Kling, Andreas
     [not found] <B3F251FD87EC894A88C2221EEEBDF54807096F7F3B@Exchange>
2013-01-16 11:12 ` Kling, Andreas

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).