Commit b1ca434
async_context_threadsafe_background: fix incorrect mutex assertion in cross-core execute_sync() (#2528)
* async_context_threadsafe_background: fix incorrect mutex assertion in cross-core execute_sync()
In multicore configurations, `async_context_threadsafe_background_execute_sync()`
contained an overly strict assertion used during cross-core calls:
```c
hard_assert(!recursive_mutex_enter_count(&self->lock_mutex));
```
This check fails whenever the `lock_mutex` is held — regardless of *who*
owns it — even in valid situations where the async core is processing background
work.
The assertion does **not check ownership**, only that the `enter_count` is zero,
which leads to false-positive failures on valid cross-core calls.
This patch replaces the enter-count check with a core-aware assertion:
```c
hard_assert(self->lock_mutex.owner != calling_core);
```
This ensures the current core does not recursively hold the mutex, preventing
deadlocks while allowing valid usage where the *other* core owns the lock.
The patch ensures that both `get_core_num()` and `hard_assert()` remain inlined
as in the original implementation, preserving the performance characteristics
under `-Os` and `RelWithDebInfo` builds.
Fixes #2527
Signed-off-by: Goran Mišković <[email protected]>
* fix indents
* Update async_context_threadsafe_background.c
Use pre-existing mutex owner method; add a comment
* oops
* typo
* Update async_context_threadsafe_background.c
---------
Signed-off-by: Goran Mišković <[email protected]>
Co-authored-by: Graham Sanderson <[email protected]>1 parent a24bc13 commit b1ca434
File tree
1 file changed
+9
-2
lines changed- src/rp2_common/pico_async_context
1 file changed
+9
-2
lines changedLines changed: 9 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
138 | 138 | | |
139 | 139 | | |
140 | 140 | | |
141 | | - | |
142 | | - | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
143 | 150 | | |
144 | 151 | | |
145 | 152 | | |
| |||
0 commit comments