shared/att: Use queue_remove_if
Luiz Augusto von Dentz
maintainerPATCH 1/3 shared/att: Use queue_remove_if
From: Luiz Augusto von Dentz <[email protected]>
This make use of queue_remove_if instead of queue_find + queue_remove whenever possible.
--- src/shared/att.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
src/shared/att.c +2 -4
@@ -978,12 +978,11 @@ bool bt_att_unregister_disconnect(struct bt_att *att, unsigned int id)if (!att || !id)return false; - disconn =queue_find (att->disconn_list, match_disconn_id, + disconn =queue_remove_if (att->disconn_list, match_disconn_id,UINT_TO_PTR (id));if (!disconn)return false; -queue_remove (att->disconn_list, disconn);destroy_att_disconn (disconn);return true; }
@@ -1196,12 +1195,11 @@ bool bt_att_unregister(struct bt_att *att, unsigned int id)if (!att || !id)return false; - notify =queue_find (att->notify_list, match_notify_id, + notify =queue_remove_if (att->notify_list, match_notify_id,UINT_TO_PTR (id));if (!notify)return false; -queue_remove (att->notify_list, notify);destroy_att_notify (notify);return true; }
Signature · 1 line
1.9.3
Luiz Augusto von Dentz
maintainerPATCH 1/1 shared/gatt-client: Remove unnecessary code
From: Luiz Augusto von Dentz <[email protected]>
This flags were added because calling function like queue_foreach were not safe as the callbacks may remove or destroy the queue before returning but this has been fixed and it is now safe to do that.
--- src/shared/att.c | 94 ++++---------------------------------------------------- 1 file changed, 6 insertions(+), 88 deletions(-)
src/shared/att.c +6 -88
@@ -66,12 +66,7 @@ struct bt_att {bool writer_active;struct queue *notify_list;/* List of registered callbacks */ -bool in_notify; -bool need_notify_cleanup; -struct queue *disconn_list;/* List of disconnect handlers */ -bool in_disconn; -bool need_disconn_cleanup;bool in_req;/* There's a pending incoming request */
@@ -216,7 +211,6 @@ static void cancel_att_send_op(struct att_send_op *op)struct att_notify {unsigned int id;uint16_t opcode; -bool removed;bt_att_notify_func_t callback;bt_att_destroy_func_t destroy;void *user_data;
@@ -240,20 +234,6 @@ static bool match_notify_id(const void *a, const void *b)return notify->id == id; } -static bool match_notify_removed (const void *a,const void *b) -{ -const struct att_notify *notify = a; - -return notify->removed; -} - -static void mark_notify_removed (void *data,void *user_data) -{ -struct att_notify *notify = data; - - notify->removed = true; -} -struct att_disconn {unsigned int id;bool removed;
@@ -280,20 +260,6 @@ static bool match_disconn_id(const void *a, const void *b)return disconn->id == id; } -static bool match_disconn_removed (const void *a,const void *b) -{ -const struct att_disconn *disconn = a; - -return disconn->removed; -} - -static void mark_disconn_removed (void *data,void *user_data) -{ -struct att_disconn *disconn = data; - - disconn->removed = true; -} -static bool encode_pdu (struct att_send_op *op,const void *pdu,uint16_t length,uint16_t mtu) {
@@ -557,16 +523,7 @@ static bool disconnect_cb(struct io *io, void *user_data)bt_att_cancel_all (att);bt_att_ref (att); - att->in_disconn = true;queue_foreach (att->disconn_list, disconn_handler,NULL ); - att->in_disconn = false; - -if (att->need_disconn_cleanup) { -queue_remove_all (att->disconn_list, match_disconn_removed,NULL , - destroy_att_disconn); - att->need_disconn_cleanup = false; - } -bt_att_unregister_all (att);bt_att_unref (att);
@@ -680,9 +637,6 @@ static void notify_handler(void *data, void *user_data)struct att_notify *notify = data;struct notify_data *not_data = user_data; -if (notify->removed) -return ; -if (!opcode_match (notify->opcode, not_data->opcode))return ;
@@ -712,7 +666,6 @@ static void handle_notify(struct bt_att *att, uint8_t opcode, uint8_t *pdu,struct notify_data data;bt_att_ref (att); - att->in_notify = true;memset (&data,0 ,sizeof (data)); data.opcode = opcode;
@@ -724,14 +677,6 @@ static void handle_notify(struct bt_att *att, uint8_t opcode, uint8_t *pdu,queue_foreach (att->notify_list, notify_handler, &data); - att->in_notify = false; - -if (att->need_notify_cleanup) { -queue_remove_all (att->notify_list, match_notify_removed,NULL , - destroy_att_notify); - att->need_notify_cleanup = false; - } -bt_att_unref (att);/*
@@ -1038,15 +983,8 @@ bool bt_att_unregister_disconnect(struct bt_att *att, unsigned int id)if (!disconn)return false; -if (!att->in_disconn) { -queue_remove (att->disconn_list, disconn); -destroy_att_disconn (disconn); -return true; - } - - disconn->removed = true; - att->need_disconn_cleanup = true; - +queue_remove (att->disconn_list, disconn); +destroy_att_disconn (disconn);return true; }
@@ -1263,15 +1201,8 @@ bool bt_att_unregister(struct bt_att *att, unsigned int id)if (!notify)return false; -if (!att->in_notify) { -queue_remove (att->notify_list, notify); -destroy_att_notify (notify); -return true; - } - - notify->removed = true; - att->need_notify_cleanup = true; - +queue_remove (att->notify_list, notify); +destroy_att_notify (notify);return true; }
@@ -1280,21 +1211,8 @@ bool bt_att_unregister_all(struct bt_att *att)if (!att)return false; -if (att->in_notify) { -queue_foreach (att->notify_list, mark_notify_removed,NULL ); - att->need_notify_cleanup = true; - }else { -queue_remove_all (att->notify_list,NULL ,NULL , - destroy_att_notify); - } - -if (att->in_disconn) { -queue_foreach (att->disconn_list, mark_disconn_removed,NULL ); - att->need_disconn_cleanup = true; - }else { -queue_remove_all (att->disconn_list,NULL ,NULL , - destroy_att_disconn); - } +queue_remove_all (att->notify_list,NULL ,NULL , destroy_att_notify); +queue_remove_all (att->disconn_list,NULL ,NULL , destroy_att_disconn);return true; }
Signature · 1 line
1.9.3
Luiz Augusto von Dentz
maintainerPATCH 2/3 shared/gatt-client: Remove removed flag
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
--- src/shared/gatt-client.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)
src/shared/gatt-client.c +1 -5
@@ -104,7 +104,6 @@ struct notify_chrc {struct notify_data {struct bt_gatt_client *client; -bool removed;bool invalid;unsigned int id;int ref_count;
@@ -1372,9 +1371,6 @@ static void notify_handler(void *data, void *user_data)uint16_t value_handle;const uint8_t *value =NULL ; -if (notify_data->removed) -return ; - value_handle =get_le16 (pdu_data->pdu);if (notify_data->chrc->value_handle != value_handle)
@@ -2420,7 +2416,7 @@ bool bt_gatt_client_unregister_notify(struct bt_gatt_client *client, notify_data =queue_find (client->notify_list, match_notify_data_id,UINT_TO_PTR (id)); -if (!notify_data || notify_data->removed) +if (!notify_data)return false;assert (notify_data->chrc->notify_count >0 );
Signature · 1 line
1.9.3
Luiz Augusto von Dentz
maintainerPATCH 3/3 shared/gatt-client: Use queue_remove_if
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
This make use of queue_remove_if instead of queue_find + queue_remove whenever possible.
--- src/shared/gatt-client.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
src/shared/gatt-client.c +1 -2
@@ -2414,7 +2414,7 @@ bool bt_gatt_client_unregister_notify(struct bt_gatt_client *client,if (!client || !id)return false; - notify_data =queue_find (client->notify_list, match_notify_data_id, + notify_data =queue_remove_if (client->notify_list, match_notify_data_id,UINT_TO_PTR (id));if (!notify_data)return false;
@@ -2422,7 +2422,6 @@ bool bt_gatt_client_unregister_notify(struct bt_gatt_client *client,assert (notify_data->chrc->notify_count >0 );assert (!notify_data->chrc->ccc_write_id); -queue_remove (client->notify_list, notify_data);complete_unregister_notify (notify_data);return true; }
Signature · 1 line
1.9.3
Luiz Augusto von Dentz
maintainerHi,
Quoted 41 lines · Luiz Augusto von Dentz
From: Luiz Augusto von Dentz <[email protected]>
This make use of
queue_remove_ifinstead ofqueue_find+queue_removewhenever possible.--- src/shared/att.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)src/shared/att.c +2
-5@@ -978,12 +978,11 @@ bool bt_att_unregister_disconnect(struct bt_att *att, unsigned int id)if (!att || !id)return false; - disconn =queue_find (att->disconn_list, match_disconn_id, + disconn =queue_remove_if (att->disconn_list, match_disconn_id,UINT_TO_PTR (id));if (!disconn)return false; -queue_remove (att->disconn_list, disconn);destroy_att_disconn (disconn);return true; }@@ -1196,12 +1195,11 @@ bool bt_att_unregister(struct bt_att *att, unsigned int id)if (!att || !id)return false; - notify =queue_find (att->notify_list, match_notify_id, + notify =queue_remove_if (att->notify_list, match_notify_id,UINT_TO_PTR (id));if (!notify)return false; -queue_remove (att->notify_list, notify);destroy_att_notify (notify);return true; } --
Quoted 1 line
1.9.3
Pushed.
Signature · 1 line
Luiz Augusto von Dentz