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
_______________________________________________
ofono mailing list
[email protected]
http://lists.ofono.org/listinfo/ofono