spinlock: add support of spin_trylock_irqsave()
trylock spinlock in critical section: bool spin_trylock_irqsave(FAR volatile spinlock_t *lock, irqstate_t flags); bool spin_trylock_irqsave_wo_note(FAR volatile spinlock_t *lock, irqstate_t flags); Signed-off-by: chao an <anchao@lixiang.com>
This commit is contained in:
parent
a3b94383ed
commit
9cc25523b1
1 changed files with 75 additions and 0 deletions
|
@ -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
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue