Skip to content
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

spinlock: use inline replace macro #14932

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 42 additions & 24 deletions include/nuttx/spinlock.h
Original file line number Diff line number Diff line change
Expand Up @@ -633,19 +633,28 @@ irqstate_t spin_lock_irqsave(FAR volatile spinlock_t *lock)
****************************************************************************/

#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; }); \
})
static inline_function
bool spin_trylock_irqsave_wo_note(FAR volatile spinlock_t *lock,
FAR irqstate_t *flags)
{
*flags = up_irq_save();

if (!spin_trylock_wo_note(lock))
{
up_irq_restore(*flags);
return false;
}

return true;
}
#else
# define spin_trylock_irqsave_wo_note(l, f) \
({ \
(void)(l); \
f = up_irq_save(); \
true; \
})
static inline_function
bool spin_trylock_irqsave_wo_note(FAR volatile spinlock_t *lock,
FAR irqstate_t *flags)
{
*flags = up_irq_save();
return true;
}
#endif /* CONFIG_SPINLOCK */

/****************************************************************************
Expand All @@ -669,19 +678,28 @@ irqstate_t spin_lock_irqsave(FAR volatile spinlock_t *lock)
****************************************************************************/

#ifdef CONFIG_SPINLOCK
# define spin_trylock_irqsave(l, f) \
({ \
f = up_irq_save(); \
spin_trylock(l) ? \
true : ({ up_irq_restore(f); false; }); \
})
static inline_function
bool spin_trylock_irqsave(FAR volatile spinlock_t *lock,
FAR irqstate_t *flags)
{
*flags = up_irq_save();

if (!spin_trylock(lock))
{
up_irq_restore(*flags);
return false;
}

return true;
}
#else
# define spin_trylock_irqsave(l, f) \
({ \
(void)(l); \
f = up_irq_save(); \
true; \
})
static inline_function
bool spin_trylock_irqsave(FAR volatile spinlock_t *lock,
FAR irqstate_t *flags)
{
*flags = up_irq_save();
return true;
}
#endif /* CONFIG_SPINLOCK */

/****************************************************************************
Expand Down
Loading