hujun260 opened a new pull request, #18049: URL: https://github.com/apache/nuttx/pull/18049
## Summary This PR adds comprehensive recursive spinlock (rspinlock) interface functions to support nested spinlock acquisitions. The implementation includes separate lock/unlock operations and helper functions for breaking and restoring locks. This enables proper handling of scenarios where the same CPU needs to acquire a spinlock multiple times without causing deadlocks. ### Changes Made - Add rspin_lock() function for acquiring recursive spinlock without IRQ handling - Refactor rspin_lock_irqsave() to use new rspin_lock() internally - Add rspin_unlock() function with return value indicating lock release - Refactor rspin_unlock_irqrestore() to use new rspin_unlock() - Add rspin_breaklock() to temporarily release nested locks - Add rspin_restorelock() to restore previously broken locks - Update documentation comments for new function return values ### Impact • Functionality: Enables recursive spinlock patterns for same-CPU nested locking • Code Quality: Separates concerns between lock management and IRQ handling • Flexibility: Provides utility functions for lock breaking and restoration • Compatibility: Maintains backward compatibility with existing rspin_lock_irqsave/irqrestore ### Testing Test Environment: • Host: Linux x86_64 • Board: sim (simulated multi-core environment) • Configuration: NuttX with spinlock support enabled Test Procedure: 1. Tested rspin_lock() for single acquisition 2. Tested rspin_lock() for nested acquisition by same CPU 3. Verified lock count increments correctly on nested lock 4. Tested rspin_unlock() return value (true on final unlock, false otherwise) 5. Tested rspin_lock_irqsave() still functions with new implementation 6. Tested rspin_unlock_irqrestore() with new implementation 7. Tested rspin_breaklock() and rspin_restorelock() pair 8. Verified lock state preservation across break/restore operations 9. Stress tested with multiple nested lock levels Test Results: Recursive Spinlock Test: - First lock acquisition: count=1 ✅ - Second lock acquisition (same CPU): count=2 ✅ - Third lock acquisition (same CPU): count=3 ✅ - First unlock (count>1): returns false, count=2 ✅ - Second unlock (count>1): returns false, count=1 ✅ - Final unlock (count==0): returns true, lock released ✅ Break/Restore Test: - Original count: 3 - After breaklock(): count=1, oldcount saved - After restorelock(): count=3, restored correctly ✅ IRQ Integration: - rspin_lock_irqsave() still properly saves/restores IRQ state ✅ - Nested acquisition works with IRQ disabled ✅ Verification: • ✅ rspin_lock() correctly handles recursive acquisition • ✅ Lock count properly managed for nested calls • ✅ rspin_unlock() returns correct values • ✅ IRQ state properly saved and restored • ✅ Breaklock/restorelock functionality working • ✅ No deadlocks in recursive scenarios • ✅ Backward compatibility maintained • ✅ OSTest passed without regressions ### Related Issues Enables recursive spinlock support for NuttX synchronization primitives. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
