anchao commented on code in PR #16486: URL: https://github.com/apache/nuttx/pull/16486#discussion_r2128541076
########## include/nuttx/spinlock.h: ########## @@ -585,11 +585,11 @@ irqstate_t spin_lock_irqsave_nopreempt(FAR volatile spinlock_t *lock) * Similar feature with enter_critical_section, but isolate by instance. * * If SPINLOCK is enabled: - * Will take spinlock each cpu fisrt call. + * Will take spinlock each cpu first call. Review Comment: merge to original patch ########## include/nuttx/spinlock.h: ########## @@ -499,6 +543,85 @@ irqstate_t spin_lock_irqsave(FAR volatile spinlock_t *lock) # define spin_lock_irqsave(l) ((void)(l), up_irq_save()) #endif +/**************************************************************************** + * Name: spin_lock_irqsave_nopreempt + * + * Description: + * If SMP is enabled: + * Disable local interrupts, sched_lock and take the lock spinlock and + * return the interrupt state. + * + * NOTE: This API is very simple to protect data (e.g. H/W register + * or internal data structure) in SMP mode. But do not use this API + * with kernel APIs which suspend a caller thread. (e.g. nxsem_wait) + * + * If SMP is not enabled: + * This function is equivalent to up_irq_save() + sched_lock(). + * + * Input Parameters: + * lock - Caller specific spinlock. not NULL. + * + * Returned Value: + * An opaque, architecture-specific value that represents the state of + * the interrupts prior to the call to spin_lock_irqsave(lock); + * + ****************************************************************************/ + +static inline_function +irqstate_t spin_lock_irqsave_nopreempt(FAR volatile spinlock_t *lock) +{ + irqstate_t flags; + flags = spin_lock_irqsave(lock); + sched_lock(); + return flags; +} + +/**************************************************************************** + * Name: rspin_lock_irqsave_noprempt + * + * Description: + * Nest supported spinlock, can support UINT8_MAX max depth. + * As we should not disable irq for long time, sched also locked. + * Similar feature with enter_critical_section, but isolate by instance. + * + * If SPINLOCK is enabled: + * Will take spinlock each cpu first call. + * + * If SPINLOCK is not enabled: + * Equivalent to up_irq_save() + sched_lock(). + * Will only sched_lock once when first called. + * + * Input Parameters: + * lock - Caller specific rspinlock_s. not NULL. + * + * Returned Value: + * An opaque, architecture-specific value that represents the state of + * the interrupts prior to the call to spin_lock_irqsave(lock); + * + ****************************************************************************/ + +static inline_function +irqstate_t rspin_lock_irqsave_noprempt(FAR struct rspinlock_s *lock) Review Comment: ```suggestion irqstate_t rspin_lock_irqsave_nopreempt(FAR struct rspinlock_s *lock) ``` ########## include/nuttx/spinlock.h: ########## @@ -633,6 +756,77 @@ void spin_unlock_irqrestore(FAR volatile spinlock_t *lock, irqstate_t flags) # define spin_unlock_irqrestore(l, f) ((void)(l), up_irq_restore(f)) #endif +/**************************************************************************** + * Name: spin_unlock_irqrestore_nopreempt + * + * Description: + * If SMP is enabled: + * Release the lock and restore the interrupt state, sched_unlock + * as it was prior to the previous call to + * spin_unlock_irqrestore_nopreempt(lock). + * + * If SMP is not enabled: + * This function is equivalent to up_irq_restore() + sched_unlock(). + * + * Input Parameters: + * lock - Caller specific spinlock. not NULL + * + * flags - The architecture-specific value that represents the state of + * the interrupts prior to the call to + * spin_unlock_irqrestore_nopreempt(lock); + * + * Returned Value: + * None + * + ****************************************************************************/ + +static inline_function +void spin_unlock_irqrestore_nopreempt(FAR volatile spinlock_t *lock, + irqstate_t flags) +{ + spin_unlock_irqrestore(lock, flags); + sched_unlock(); +} + +/**************************************************************************** + * Name: rspin_unlock_irqrestore_noprempt + * + * Description: + * Nest supported spinunlock, can support UINT8_MAX max depth. + * Should work with rspin_lock_irqsave_noprempt(). + * Similar feature with leave_critical_section, but isolate by instance. + * + * If SPINLOCK is enabled: + * Will release spinlock each cpu last call. + * + * If SPINLOCK is not enabled: + * Equivalent to sched_unlock() + up_irq_restore(). + * Will only sched_unlock once when last called. + * + * Input Parameters: + * lock - Caller specific rspinlock_s. + * + * flags - The architecture-specific value that represents the state of + * the interrupts prior to the call to + * spin_unlock_irqrestore_nopreempt(lock); + * + * Returned Value: + * None + * + ****************************************************************************/ + +static inline_function +void rspin_unlock_irqrestore_noprempt(FAR struct rspinlock_s *lock, Review Comment: ```suggestion void rspin_unlock_irqrestore_nopreempt(FAR struct rspinlock_s *lock, ``` -- 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: commits-unsubscr...@nuttx.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org