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 c86a1c9a48b2e94e58ed4bc2efc51a0c8c7a45a7
Author: ganjing <[email protected]>
AuthorDate: Mon Aug 25 16:40:14 2025 +0800

    libc/unistd: Define the PSE52 thread options.
    
    PSE52 requires the thread priority inheritance, thread priority
    protection and thread-safe functions options.  <unistd.h> did not
    define _POSIX_THREAD_PRIO_INHERIT, _POSIX_THREAD_PRIO_PROTECT and
    _POSIX_THREAD_SAFE_FUNCTIONS, so applications could not detect them at
    build time, and sysconf(_SC_THREAD_SAFE_FUNCTIONS) returned -1.
    
    Define the three macros.  The priority protocols are only advertised
    when CONFIG_PRIORITY_INHERITANCE or CONFIG_PRIORITY_PROTECT is enabled,
    and sysconf() returns the macros, so that the build time and the run
    time answers agree.
    
    Assisted-by: Kiro:auto
    Signed-off-by: ganjing <[email protected]>
---
 include/unistd.h               | 20 ++++++++++++++++++++
 libs/libc/unistd/lib_sysconf.c | 16 +++++-----------
 2 files changed, 25 insertions(+), 11 deletions(-)

diff --git a/include/unistd.h b/include/unistd.h
index 32cd51b6b82..f50ca0d7bde 100644
--- a/include/unistd.h
+++ b/include/unistd.h
@@ -145,6 +145,26 @@
 #  define _POSIX_SPIN_LOCKS -1
 #endif
 
+/* For the PSE52 certification, define the following macros.
+ * _POSIX_THREAD_ATTR_STACKADDR and _POSIX_THREAD_ATTR_STACKSIZE are
+ * defined above.  The priority protocols are only supported when they are
+ * built in.
+ */
+
+#if defined(CONFIG_PRIORITY_INHERITANCE) && !defined(CONFIG_DISABLE_PTHREAD)
+#  define _POSIX_THREAD_PRIO_INHERIT 200112L
+#else
+#  define _POSIX_THREAD_PRIO_INHERIT -1
+#endif
+
+#if defined(CONFIG_PRIORITY_PROTECT) && !defined(CONFIG_DISABLE_PTHREAD)
+#  define _POSIX_THREAD_PRIO_PROTECT 200112L
+#else
+#  define _POSIX_THREAD_PRIO_PROTECT -1
+#endif
+
+#define _POSIX_THREAD_SAFE_FUNCTIONS 200112L
+
 #ifdef CONFIG_FS_AIO
 #  define _POSIX_ASYNCHRONOUS_IO _POSIX_VERSION
 #else
diff --git a/libs/libc/unistd/lib_sysconf.c b/libs/libc/unistd/lib_sysconf.c
index f48c71d1a8e..e7c653962da 100644
--- a/libs/libc/unistd/lib_sysconf.c
+++ b/libs/libc/unistd/lib_sysconf.c
@@ -511,18 +511,13 @@ long sysconf(int name)
 #endif
 
       case _SC_THREAD_PRIO_INHERIT:
-#if defined(CONFIG_PRIORITY_INHERITANCE) && !defined(CONFIG_DISABLE_PTHREAD)
-        return _POSIX_VERSION;
-#else
-        return -1;
-#endif
+        return _POSIX_THREAD_PRIO_INHERIT;
 
       case _SC_THREAD_PRIO_PROTECT:
-#if defined(CONFIG_PRIORITY_PROTECT) && !defined(CONFIG_DISABLE_PTHREAD)
-        return _POSIX_VERSION;
-#else
-        return -1;
-#endif
+        return _POSIX_THREAD_PRIO_PROTECT;
+
+      case _SC_THREAD_SAFE_FUNCTIONS:
+        return _POSIX_THREAD_SAFE_FUNCTIONS;
 
       case _SC_THREAD_ROBUST_PRIO_INHERIT:
 #if defined(CONFIG_PRIORITY_INHERITANCE) && !defined(CONFIG_DISABLE_PTHREAD) 
&& \
@@ -593,7 +588,6 @@ long sysconf(int name)
       case _SC_SHELL:
       case _SC_SPAWN:
       case _SC_SS_REPL_MAX:
-      case _SC_THREAD_SAFE_FUNCTIONS:
       case _SC_THREAD_THREADS_MAX:
       case _SC_TRACE:
       case _SC_TRACE_EVENT_FILTER:

Reply via email to