This is an automated email from the ASF dual-hosted git repository.

xiaoxiang781216 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit 93cc157ceeed809f79b1245f452bf6b25293c51d
Author: Marco Casaroli <[email protected]>
AuthorDate: Tue Oct 20 20:55:19 2026 +0200

    include/unistd.h: Make the POSIX option macros follow the configuration.
    
    <unistd.h> defined _POSIX_SEMAPHORES, _POSIX_SHARED_MEMORY_OBJECTS,
    _POSIX_MAPPED_FILES, _POSIX_MESSAGE_PASSING, _POSIX_THREADS,
    _POSIX_THREAD_PROCESS_SHARED, _POSIX_CPUTIME and _POSIX_THREAD_CPUTIME
    in every configuration.  A program that tests them then used functions
    that the build does not have: sem_open() needs
    CONFIG_FS_NAMED_SEMAPHORES, shm_open() needs CONFIG_FS_SHMFS, mmap() of
    a regular file needs CONFIG_FS_RAMMAP, and the CPU-time clocks need the
    run-time accounting of CONFIG_SCHED_CRITMONITOR.
    
    It also did not define _POSIX_BARRIERS, _POSIX_READER_WRITER_LOCKS,
    _POSIX_SPIN_LOCKS and _POSIX_THREAD_ATTR_STACKADDR, although the
    functions exist.  <pthread.h> defined _POSIX_THREAD_ATTR_STACKSIZE with
    no value, so "#if _POSIX_THREAD_ATTR_STACKSIZE > 0" did not compile.
    
    Define each option as _POSIX_VERSION when the configuration has it, and
    as -1 when it does not.  A kernel build has process-shared mutexes only
    with memory that two processes can share (CONFIG_FS_SHMFS or
    CONFIG_MM_SHM).  Remove the empty fallbacks from <pthread.h>.
    
    Assisted-by: Claude Code:claude-opus-5-5
    Signed-off-by: Marco Casaroli <[email protected]>
---
 include/pthread.h | 10 -------
 include/unistd.h  | 86 ++++++++++++++++++++++++++++++++++++++++++++++++-------
 2 files changed, 76 insertions(+), 20 deletions(-)

diff --git a/include/pthread.h b/include/pthread.h
index 242664a58e7..846df728944 100644
--- a/include/pthread.h
+++ b/include/pthread.h
@@ -57,16 +57,6 @@
  * Pre-processor Definitions
  ****************************************************************************/
 
-/* Standard POSIX switches */
-
-#ifndef _POSIX_THREADS
-#  define _POSIX_THREADS
-#endif
-
-#ifndef _POSIX_THREAD_ATTR_STACKSIZE
-#  define _POSIX_THREAD_ATTR_STACKSIZE
-#endif
-
 /* Values for the process shared (pshared) attribute */
 
 #define PTHREAD_PROCESS_PRIVATE       0
diff --git a/include/unistd.h b/include/unistd.h
index 20682df03de..91b68141756 100644
--- a/include/unistd.h
+++ b/include/unistd.h
@@ -46,12 +46,18 @@
 #define W_OK        2  /* Test write permission */
 #define R_OK        4  /* Test read permission */
 
-/* POSIX feature set macros */
+/* POSIX feature set macros.  A value greater than zero means that the
+ * option is supported; -1 means that this configuration does not have it.
+ */
 
 #define POSIX_VERSION
 #undef  _POSIX_SAVED_IDS
 #undef  _POSIX_JOB_CONTROL
-#define _POSIX_MESSAGE_PASSING 1
+#ifdef CONFIG_DISABLE_MQUEUE
+#  define _POSIX_MESSAGE_PASSING -1
+#else
+#  define _POSIX_MESSAGE_PASSING 1
+#endif
 #define _POSIX_PRIORITY_SCHEDULING 1
 #ifndef CONFIG_DISABLE_POSIX_TIMERS
 #  define _POSIX_TIMERS 1
@@ -67,18 +73,78 @@
 
 #define _POSIX_VERSION 201712L
 #define _POSIX_PRIORITIZED_IO _POSIX_VERSION
-#define _POSIX_CPUTIME _POSIX_VERSION
-#define _POSIX_THREAD_CPUTIME _POSIX_VERSION
+
+/* CPU-time clocks need the run-time accounting of the critical section
+ * monitor.
+ */
+
+#if defined(CONFIG_SCHED_CRITMONITOR_MAXTIME_THREAD) && \
+    CONFIG_SCHED_CRITMONITOR_MAXTIME_THREAD >= 0
+#  define _POSIX_CPUTIME _POSIX_VERSION
+#  define _POSIX_THREAD_CPUTIME _POSIX_VERSION
+#else
+#  define _POSIX_CPUTIME -1
+#  define _POSIX_THREAD_CPUTIME -1
+#endif
+
 #define _POSIX_REALTIME_SIGNALS _POSIX_VERSION
-#define _POSIX_THREAD_PRIORITY_SCHEDULING _POSIX_VERSION
-#define _POSIX_SEMAPHORES _POSIX_VERSION
-#define _POSIX_SHARED_MEMORY_OBJECTS _POSIX_VERSION
-#define _POSIX_THREAD_PROCESS_SHARED _POSIX_VERSION
-#define _POSIX_MAPPED_FILES _POSIX_VERSION
-#define _POSIX_THREADS _POSIX_VERSION
 #define _POSIX_MONOTONIC_CLOCK _POSIX_VERSION
 #define _POSIX_CLOCK_SELECTION _POSIX_VERSION
 
+/* sem_open() needs the named semaphores */
+
+#ifdef CONFIG_FS_NAMED_SEMAPHORES
+#  define _POSIX_SEMAPHORES _POSIX_VERSION
+#else
+#  define _POSIX_SEMAPHORES -1
+#endif
+
+#ifdef CONFIG_FS_SHMFS
+#  define _POSIX_SHARED_MEMORY_OBJECTS _POSIX_VERSION
+#else
+#  define _POSIX_SHARED_MEMORY_OBJECTS -1
+#endif
+
+/* mmap() of a regular file needs the file mapping emulation */
+
+#ifdef CONFIG_FS_RAMMAP
+#  define _POSIX_MAPPED_FILES _POSIX_VERSION
+#else
+#  define _POSIX_MAPPED_FILES -1
+#endif
+
+#ifdef CONFIG_DISABLE_PTHREAD
+#  define _POSIX_THREADS -1
+#  define _POSIX_THREAD_PRIORITY_SCHEDULING -1
+#  define _POSIX_THREAD_ATTR_STACKADDR -1
+#  define _POSIX_THREAD_ATTR_STACKSIZE -1
+#  define _POSIX_THREAD_PROCESS_SHARED -1
+#  define _POSIX_BARRIERS -1
+#  define _POSIX_READER_WRITER_LOCKS -1
+#else
+#  define _POSIX_THREADS _POSIX_VERSION
+#  define _POSIX_THREAD_PRIORITY_SCHEDULING _POSIX_VERSION
+#  define _POSIX_THREAD_ATTR_STACKADDR _POSIX_VERSION
+#  define _POSIX_THREAD_ATTR_STACKSIZE _POSIX_VERSION
+#  define _POSIX_BARRIERS _POSIX_VERSION
+#  define _POSIX_READER_WRITER_LOCKS _POSIX_VERSION
+
+/* Process-shared objects need memory that two processes can share */
+
+#  if !defined(CONFIG_BUILD_KERNEL) || defined(CONFIG_FS_SHMFS) || \
+      defined(CONFIG_MM_SHM)
+#    define _POSIX_THREAD_PROCESS_SHARED _POSIX_VERSION
+#  else
+#    define _POSIX_THREAD_PROCESS_SHARED -1
+#  endif
+#endif
+
+#ifdef CONFIG_PTHREAD_SPINLOCKS
+#  define _POSIX_SPIN_LOCKS _POSIX_VERSION
+#else
+#  define _POSIX_SPIN_LOCKS -1
+#endif
+
 #ifdef CONFIG_FS_AIO
 #  define _POSIX_ASYNCHRONOUS_IO _POSIX_VERSION
 #else

Reply via email to