Skip to content

Commit

Permalink
pbio/task: don't run task from cancel function
Browse files Browse the repository at this point in the history
Since efda5d0 ("drv/bluetooth_stm32_bluenrg: strict ordering of BLE
tasks"), it is no longer safe to call pbio_task_run_once() anywhere but
in the main contiki process loop of Bluetooth drivers.

This could break canceling some Bluetooth operations (causing them to
hang), but this will need to be fixed in a different way. A FIXME
comment with some suggestions is added to remind us to fix this.
  • Loading branch information
dlech committed Oct 29, 2023
1 parent da7565e commit 75bfdfd
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions lib/pbio/src/task.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,15 @@ bool pbio_task_run_once(pbio_task_t *task) {
}

/**
* Cancels @p task and runs one iteration unless the task is already complete.
* Sets cancel flag for @p task.
* @param [in] task The task.
*/
void pbio_task_cancel(pbio_task_t *task) {
if (task->status != PBIO_ERROR_AGAIN) {
return;
}

task->cancel = true;
pbio_task_run_once(task);
// FIXME: need a way to poll the process that has the task queue to
// expedite the cancellation. e.g. if the task is not the first in the
// queue, it can just be removed from the queue. For btstack, we probably
// need to create a synthetic event. For others drivers, we can probably
// do something with contiki events. Since it is driver-specific, this
// means we probably need to add a cancel callback to the task struct.
}

0 comments on commit 75bfdfd

Please sign in to comment.