diff --git a/include/nuttx/spinlock.h b/include/nuttx/spinlock.h index 1d915a6314..ebb5d91328 100644 --- a/include/nuttx/spinlock.h +++ b/include/nuttx/spinlock.h @@ -626,6 +626,81 @@ irqstate_t spin_lock_irqsave(FAR volatile spinlock_t *lock) # define spin_lock_irqsave(l) ((void)(l), up_irq_save()) #endif +/**************************************************************************** + * Name: spin_trylock_irqsave_wo_note + * + * Description: + * Try once to lock the spinlock. Do not wait if the spinlock is already + * locked. + * + * This implementation is the same as the above spin_trylock() except that + * it does not perform instrumentation logic. + * + * Input Parameters: + * lock - A reference to the spinlock object to lock. + * flags - flag of interrupts status + * + * Returned Value: + * SP_LOCKED - Failure, the spinlock was already locked + * SP_UNLOCKED - Success, the spinlock was successfully locked + * + * Assumptions: + * Not running at the interrupt level. + * + ****************************************************************************/ + +#ifdef CONFIG_SPINLOCK +# define spin_trylock_irqsave_wo_note(l, f) \ +({ \ + f = up_irq_save(); \ + spin_trylock_wo_note(l) ? \ + true : ({ up_irq_restore(f); false; }); \ +}) +#else +# define spin_trylock_irqsave_wo_note(l, f) \ +({ \ + (void)(l); \ + f = up_irq_save(); \ + true; \ +}) +#endif /* CONFIG_SPINLOCK */ + +/**************************************************************************** + * Name: spin_trylock_irqsave + * + * Description: + * Try once to lock the spinlock. Do not wait if the spinlock is already + * locked. + * + * Input Parameters: + * lock - A reference to the spinlock object to lock. + * flags - flag of interrupts status + * + * Returned Value: + * SP_LOCKED - Failure, the spinlock was already locked + * SP_UNLOCKED - Success, the spinlock was successfully locked + * + * Assumptions: + * Not running at the interrupt level. + * + ****************************************************************************/ + +#ifdef CONFIG_SPINLOCK +# define spin_trylock_irqsave(l, f) \ +({ \ + f = up_irq_save(); \ + spin_trylock(l) ? \ + true : ({ up_irq_restore(f); false; }); \ +}) +#else +# define spin_trylock_irqsave(l, f) \ +({ \ + (void)(l); \ + f = up_irq_save(); \ + true; \ +}) +#endif /* CONFIG_SPINLOCK */ + /**************************************************************************** * Name: spin_unlock_irqrestore_wo_note *