Skip to content

Commit

Permalink
Bluetooth: Host: Ensure conn_ready access is thread safe
Browse files Browse the repository at this point in the history
* The `bt_dev.le.conn_ready` list is accessed by the tx_processor
which runs in a workqueue, but `bt_conn_data_ready` can be called
from different threads so we need to make sure that nothing will
trigger a context switch while we are manipulating the list since
sys_slist_*() functions are not thread safe.
* This only happens if call to `bt_conn_data_ready` is performed
from a preemptive task which can happen depending on the
application.

Signed-off-by: Yago Fontoura do Rosario <[email protected]>
  • Loading branch information
Yago Fontoura do Rosario authored and kartben committed Jan 13, 2025
1 parent b4667e0 commit 9f77362
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions subsys/bluetooth/host/conn.c
Original file line number Diff line number Diff line change
Expand Up @@ -854,10 +854,18 @@ void bt_conn_data_ready(struct bt_conn *conn)
*
* This reference will be consumed when the conn is popped off
* the list (in `get_conn_ready`).
*
* The `bt_dev.le.conn_ready` list is accessed by the tx_processor
* which runs in a workqueue, but `bt_conn_data_ready` can be called
* from different threads so we need to make sure that nothing will
* trigger a thread switch while we are manipulating the list since
* sys_slist_*() functions are not thread safe.
*/
bt_conn_ref(conn);
k_sched_lock();
sys_slist_append(&bt_dev.le.conn_ready,
&conn->_conn_ready);
k_sched_unlock();
LOG_DBG("raised");
} else {
LOG_DBG("already in list");
Expand Down

0 comments on commit 9f77362

Please sign in to comment.