Open Source Telephony
 help / color / mirror / Atom feed
From: Marcel Holtmann <marcel@holtmann.org>
To: ofono@ofono.org
Subject: Re: [PATCH v3] bluetooth: Add reference count for bluetooth utils
Date: Thu, 20 Jan 2011 11:16:32 +0100	[thread overview]
Message-ID: <1295518592.3873.266.camel@aeonflux> (raw)
In-Reply-To: <1295435871-3462-1-git-send-email-frederic.danis@linux.intel.com>

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

Hi Fred,

> diff --git a/plugins/bluetooth.c b/plugins/bluetooth.c
> index 602c6da..8202381 100644
> --- a/plugins/bluetooth.c
> +++ b/plugins/bluetooth.c
> @@ -40,6 +40,7 @@
>  static DBusConnection *connection;
>  static GHashTable *uuid_hash = NULL;
>  static GHashTable *adapter_address_hash = NULL;
> +static gint ref_count;

you need a better name for this. This is too generic. Maybe using
bluetooth_refcount is better.

>  void bluetooth_create_path(const char *dev_addr, const char *adapter_addr,
>  				char *buf, int size)
> @@ -504,12 +505,12 @@ static guint adapter_added_watch;
>  static guint adapter_removed_watch;
>  static guint property_watch;
>  
> -int bluetooth_register_uuid(const char *uuid, struct bluetooth_profile *profile)
> +static int bluetooth_ref(void)
>  {
>  	int err;
>  
> -	if (uuid_hash)
> -		goto done;
> +	if (ref_count > 0)
> +		return 0;

This is pretty much wrong. A reference count can't work this way. You
need to track the number of times this has been taken.

	g_atomic_int_inc(&bluetooth_refcount);

	if (bluetooth_refcount > 1)
		return 0;

In addition, I think the return value is pointless, just make sure to
decrease the reference count in an error case.

> +static void bluetooth_unref(void)
>  {
> -	g_hash_table_remove(uuid_hash, uuid);
> +	gboolean is_zero;
> +
> +	is_zero = g_atomic_int_dec_and_test(&ref_count);
>  
> -	if (g_hash_table_size(uuid_hash))
> +	if (is_zero == FALSE)
>  		return;

I know that we have it like this in GAtChat, but just do the check right
away is fine.

	if (g_atomic_int_dec_and_test(&bluetooth_refcount) == FALSE)
		return;

Regards

Marcel



      parent reply	other threads:[~2011-01-20 10:16 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-01-19 11:17 [PATCH v3] bluetooth: Add reference count for bluetooth utils =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis
2011-01-19 12:57 ` Gustavo F. Padovan
2011-01-20 10:16 ` Marcel Holtmann [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1295518592.3873.266.camel@aeonflux \
    --to=marcel@holtmann.org \
    --cc=ofono@ofono.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox