Skip to content
Merged
Show file tree
Hide file tree
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
10 changes: 10 additions & 0 deletions include/nuttx/atomic.h
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,16 @@ ARCH_SYNC_DECLARE(sync, uint16_t, 2)
ARCH_ATOMIC_DECLARE(atomic, int64_t, 8)
ARCH_SYNC_DECLARE(sync, uint64_t, 8)
# endif
#elif defined(CONFIG_LIBC_ATOMIC_NOINLINE)
ARCH_ATOMIC_DECLARE(atomic, uint8_t, 1)
ARCH_ATOMIC_DECLARE(atomic, uint16_t, 2)
ARCH_ATOMIC_DECLARE(atomic, int32_t, 4)
ARCH_ATOMIC_DECLARE(atomic, int64_t, 8)

ARCH_SYNC_DECLARE(sync, uint8_t, 1)
ARCH_SYNC_DECLARE(sync, uint16_t, 2)
ARCH_SYNC_DECLARE(sync, uint32_t, 4)
ARCH_SYNC_DECLARE(sync, uint64_t, 8)
#endif

#if defined(__cplusplus)
Expand Down
13 changes: 12 additions & 1 deletion include/nuttx/lib/arch_atomic.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,15 @@
****************************************************************************/

#ifndef ARCH_ATOMIC_SPECIFIER
# define ARCH_ATOMIC_SPECIFIER static always_inline_function
# ifdef CONFIG_LIBC_ATOMIC_NOINLINE

/* KASAN calls the atomic functions, so they must not be instrumented */

# define ARCH_ATOMIC_SPECIFIER \
noinline_function nosanitize_address noinstrument_function
# else
# define ARCH_ATOMIC_SPECIFIER static always_inline_function
# endif
#endif

#if !defined(CONFIG_BUILD_FLAT) && !defined(__KERNEL__)
Expand Down Expand Up @@ -276,6 +284,8 @@ extern struct hwspinlock_dev_s g_atomic_hwspinlock;
* Inline Functions
****************************************************************************/

# if !defined(CONFIG_LIBC_ATOMIC_NOINLINE) || \
defined(ARCH_ATOMIC_NOINLINE_DEFINE)
ARCH_ATOMIC_DEFINE(atomic, uint8_t, 1)
ARCH_ATOMIC_DEFINE(atomic, uint16_t, 2)
ARCH_ATOMIC_DEFINE(atomic, int32_t, 4)
Expand All @@ -285,6 +295,7 @@ ARCH_SYNC_DEFINE(sync, uint8_t, 1)
ARCH_SYNC_DEFINE(sync, uint16_t, 2)
ARCH_SYNC_DEFINE(sync, uint32_t, 4)
ARCH_SYNC_DEFINE(sync, uint64_t, 8)
# endif
#endif

#endif /* __INCLUDE_NUTTX_LIB_ARCH_ATOMIC_H */
13 changes: 13 additions & 0 deletions libs/libc/machine/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,19 @@ config LIBC_ATOMIC_IRQ
---help---
atomic function by irq disable/enable

config LIBC_ATOMIC_NOINLINE
bool "Do not inline the atomic functions"
default n
depends on LIBC_ATOMIC_IRQ || LIBC_ATOMIC_HWSPINLOCK
---help---
Build the atomic functions of the IRQ and hardware spinlock
backends once in libc and call them, instead of inlining them at
each use. This reduces the code size when the atomic functions
are used at many places, at the cost of a call for each atomic
operation. Code that runs from RAM while the flash cannot be
read must also place arch_atomic.o in RAM, and loadable modules
that use the atomic functions need them in the symbol table.

config LIBC_ATOMIC_TOOLCHAIN
bool
default y if !LIBC_ATOMIC_ARCH && !LIBC_ATOMIC_HWSPINLOCK && !LIBC_ATOMIC_IRQ
Expand Down
1 change: 1 addition & 0 deletions libs/libc/machine/arch_atomic.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

#include <nuttx/config.h>

#define ARCH_ATOMIC_NOINLINE_DEFINE
#include <nuttx/atomic.h>

#undef ARCH_ATOMIC_SPECIFIER
Expand Down
Loading