wangzhi16 opened a new pull request, #18178:
URL: https://github.com/apache/nuttx/pull/18178

   ## Summary
   
   This PR aggregates four recent commits that refactor and harden the spinlock
   type and related headers to improve compile-time correctness, reduce
   architecture-specific inline assembly exposure to third-party includes, and
   prepare a cleaner separation between architecture-native spinlocks and the
   scheduler-level spinlock type used by the NuttX core.
   
   The included commits are:
   
   - `27bb5e0908f` — sched/sched: optimization for type "spinlock_t".
     - Separate the native arch spinlock representation (raw/testset type)
       `_spinlock_t` from the scheduler-level `spinlock_t` to make it easier to
       add debugging/metadata at the scheduler layer and avoid accidental
       interpretation of native spinlock words as scheduler spinlocks.
   
   - `007256d8278` — compiler.h: add CONFIG_HAVE_ZERO_SIZE_ARRAY support.
     - Add detection for zero-sized-array support (C/C++ standards) to allow
       using zero-length array initializers in structures for empty spinlock
       representations when `CONFIG_SPINLOCK` is disabled.
   
   - `7a3f7d9f0dc` — nuttx/spinlock.h: Disable up_testset if CONFIG_SPINLOCK=n.
     - Guard `up_testset()` so it is not provided when `spinlock_t` is an empty
       placeholder (spinlocks disabled), avoiding incorrect type/size usage.
   
   - `a93db05b498` — spinlock: Fix compilation errors if `spinlock.h` included.
     - Rework many arch headers to include `arch/types.h` and expose raw
       `UP_SP_LOCKED`/`UP_SP_UNLOCKED` and `_spinlock_t` for architectures that
       implement `up_testset` (avoids inclusion of inline assembly by external
       consumers like `glibc` compiled for non-targets such as `wasm64`).
   
   Together these commits:
   
   - Introduce `_spinlock_t` as the raw/testset type used by architecture
     implementations of `up_testset()` and inline test-and-set logic.
   - Define `UP_SP_LOCKED`/`UP_SP_UNLOCKED` constants and provide macro
     compatibility mapping (`SP_LOCKED`/`SP_UNLOCKED`) where appropriate.
   - Provide a `spinlock_t` scheduler-level type that can be an empty zero-sized
     struct when `CONFIG_SPINLOCK` is disabled, avoiding incorrect size/ABI
     assumptions by `up_testset()`.
   - Add `CONFIG_HAVE_ZERO_SIZE_ARRAY` detection to `include/nuttx/compiler.h` 
to
     facilitate zero-sized array struct initializers used when spinlocks are
     disabled.
   - Reduce accidental exposure of architecture inline assembly and type
     definitions to third-party includes by moving low-level definitions into
     `arch/*/types.h` and guarding `arch/*/spinlock.h` content.
   
   ## Impact
   
   Summary of impacts:
   
   - Build/system: These changes improve build correctness by ensuring that the
     architecture `up_testset()` and the scheduler `spinlock_t` types are
     consistently defined. However, they change type names and macro mappings
     (addition of `_spinlock_t`, `UP_SP_LOCKED`, `UP_SP_UNLOCKED`) and thus may
     require small adjustments in out-of-tree code that previously assumed the
     old `spinlock_t` layout.
   
   - ABI/source compatibility: For in-tree code, header changes are backwards
     compatible because `include/nuttx/spinlock_type.h` provides mapping macros
     and a `spinlock_t` typedef suitable for the configuration. External
     projects that included architecture `spinlock.h` directly or assumed the
     old `SP_LOCKED`/`SP_UNLOCKED` constants may need to be updated.
   
   - Tooling/third-party: The change reduces the chance of compilation failures
     when non-target tooling (for example `glibc` built for `wasm64`) pulls in
     NuttX architecture headers by avoiding inline assembly exposure in those
     common includes.
   
   - Documentation: No functional doc changes required, but any code examples or
     documentation that refer to low-level `SP_LOCKED`/`SP_UNLOCKED` constants 
or
     the previous `spinlock_t` layout should be reviewed.
   
   ## Testing
   
   ostest in armv7a:smp, PASS
   


-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to