-
Notifications
You must be signed in to change notification settings - Fork 1.3k
osal/none: add nested count to spin lock #3151
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds nested locking support to the bare-metal spinlock implementation in osal_none.h. The enhancement allows the same execution context to acquire a spinlock multiple times without deadlocking, which is crucial for single-core bare-metal systems where nested critical sections are common.
Key changes:
- Added
nested_countfield to track lock depth and prevent premature interrupt re-enabling - Modified lock/unlock logic to only disable/enable interrupts on the outermost lock/unlock
- Added underflow detection to catch mismatched lock/unlock pairs
Signed-off-by: HiFiPhile <[email protected]>
| TU_ATTR_ALWAYS_INLINE static inline void osal_spin_unlock(osal_spinlock_t *ctx, bool in_isr) { | ||
| if (!in_isr) { | ||
| // Check for underflow - unlock without lock | ||
| if (ctx->nested_count == 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let make it simpler, in case of 0, we just return since the spin is not locked to begin with
hathach
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thank you
Describe the PR
To allow it be used in nested functions, I think most OSs already have the counter.