ipc: do not hold a spinlock when calling schedule_ipc_worker() #10170
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Calling schedule_ipc_worker() with spinlock held is not stricly required. schedule_ipc_worker() calls k_work_schedule_for_queue() and the Zephyr workqueue has an internal lock protecting the workqueue structures. Keeping spinlock held during the call does lead to complex scenarios to debug and verify as schedule_ipc_worker() itself is dispatched from a work queue.
Simplify the flow and release spinlock before rescheduling the worker. In ipc_work_handler(), this leaves a small window where the message is just sent after we release the spinlock, and before we call schedule_ipc_worker(). This is however harmless, as in worst case the IPC worker is woken up one extra time.