summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohan Hedberg <johan.hedberg@nokia.com>2010-10-29 04:16:24 -0400
committerJohan Hedberg <johan.hedberg@nokia.com>2010-10-29 04:16:24 -0400
commitd5d0fa3be8f7a20d128dcbaf8fc529c38bc52395 (patch)
tree8370cf9fde2b62fa0eb9914408bc988e5ea6d504 /src
parent2b205dd16e6a157c2da212c71939c8887b0b46d7 (diff)
downloadbluez-d5d0fa3be8f7a20d128dcbaf8fc529c38bc52395.tar.gz
Optimize device disconnect callback processing
There's no need to iterate the callback list twice upon disconnect.
Diffstat (limited to 'src')
-rw-r--r--src/device.c17
1 files changed, 6 insertions, 11 deletions
diff --git a/src/device.c b/src/device.c
index b14865c27..c2b66827e 100644
--- a/src/device.c
+++ b/src/device.c
@@ -775,7 +775,6 @@ static void bonding_request_cancel(struct bonding_req *bonding)
void device_request_disconnect(struct btd_device *device, DBusMessage *msg)
{
- GSList *l;
DBusConnection *conn = get_dbus_connection();
if (device->bonding)
@@ -791,21 +790,17 @@ void device_request_disconnect(struct btd_device *device, DBusMessage *msg)
if (device->disconn_timer)
return;
- l = device->watches;
- while (l) {
- struct btd_disconnect_data *data = l->data;
-
- l = l->next;
+ while (device->watches) {
+ struct btd_disconnect_data *data = device->watches->data;
if (data->watch)
/* temporary is set if device is going to be removed */
data->watch(device, device->temporary,
- data->user_data);
- }
+ data->user_data);
- g_slist_foreach(device->watches, (GFunc) g_free, NULL);
- g_slist_free(device->watches);
- device->watches = NULL;
+ device->watches = g_slist_remove(device->watches, data);
+ g_free(data);
+ }
device->disconn_timer = g_timeout_add_seconds(DISCONNECT_TIMER,
do_disconnect, device);