Skip to content
Open
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
2 changes: 1 addition & 1 deletion doc/services/portability/posix/conformance/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ POSIX System Interfaces
_POSIX_TYPED_MEMORY_OBJECTS, -1,
_XOPEN_CRYPT, -1,
:ref:`_XOPEN_REALTIME <posix_option_group_xsi_realtime>`, 700, :kconfig:option:`CONFIG_XSI_REALTIME`
_XOPEN_REALTIME_THREADS, -1,
:ref:`_XOPEN_REALTIME <posix_option_group_xsi_realtime_threads>`, 700, :kconfig:option:`CONFIG_XSI_REALTIME_THREADS`
:ref:`_XOPEN_STREAMS<posix_option_xopen_streams>`, 200809L, :kconfig:option:`CONFIG_XOPEN_STREAMS`
_XOPEN_UNIX, -1,

Expand Down
22 changes: 22 additions & 0 deletions doc/services/portability/posix/option_groups/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -706,6 +706,24 @@ Enable this option group with :kconfig:option:`CONFIG_XSI_REALTIME`.
When this option group is enabled, the ``_XOPEN_REALTIME`` feature test macro will be defined to a
value other than -1.

.. _posix_option_group_xsi_realtime_threads:

XSI_REALTIME_THREADS
++++++++++++++++++++

The ``XSI_REALTIME_THREADS`` option group indicates that the
:ref:`_POSIX_THREAD_PRIO_INHERIT<posix_option_thread_prio_inherit>`,
:ref:`_POSIX_THREAD_PRIO_PROTECT<posix_option_thread_prio_protect>`,
:ref:`_POSIX_THREAD_PRIORITY_SCHEDULING<posix_option_thread_priority_scheduling>`,
:ref:`_POSIX_THREAD_ROBUST_PRIO_INHERIT<posix_option_thread_robust_prio_inherit>`, and
:ref:`_POSIX_THREAD_ROBUST_PRIO_PROTECT<posix_option_thread_robust_prio_protect>` options are
enabled.

Enable this option group with :kconfig:option:`CONFIG_XSI_REALTIME_THREADS`.

When this option group is enabled, the ``_XOPEN_REALTIME_THREADS`` feature test macro will be defined to a
value other than -1.

.. _posix_option_group_xsi_single_process:

XSI_SINGLE_PROCESS
Expand Down Expand Up @@ -1051,6 +1069,10 @@ Enable this option with :kconfig:option:`CONFIG_POSIX_THREAD_PRIORITY_SCHEDULING
pthread_setschedparam(),yes
pthread_setschedprio(),yes

.. _posix_option_thread_robust_prio_inherit:

.. _posix_option_thread_robust_prio_protect:

.. _posix_option_thread_safe_functions:

_POSIX_THREAD_SAFE_FUNCTIONS
Expand Down
16 changes: 1 addition & 15 deletions include/zephyr/posix/posix_features.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,21 +132,7 @@
#define _POSIX_THREAD_CPUTIME _POSIX_VERSION
#endif

#ifdef CONFIG_POSIX_THREAD_PRIO_INHERIT
#define _POSIX_THREAD_PRIO_INHERIT _POSIX_VERSION
#endif

#ifdef CONFIG_POSIX_THREAD_PRIO_PROTECT
#define _POSIX_THREAD_PRIO_PROTECT _POSIX_VERSION
#endif

#ifdef CONFIG_POSIX_THREAD_PRIORITY_SCHEDULING
#define _POSIX_THREAD_PRIORITY_SCHEDULING _POSIX_VERSION
#endif

/* #define _POSIX_THREAD_PROCESS_SHARED (-1L) */
/* #define _POSIX_THREAD_ROBUST_PRIO_INHERIT (-1L) */
/* #define _POSIX_THREAD_ROBUST_PRIO_PROTECT (-1L) */

/* #define _POSIX_THREAD_SPORADIC_SERVER (-1L) */

Expand Down Expand Up @@ -214,7 +200,7 @@
defined(CONFIG_POSIX_SHARED_MEMORY_OBJECTS) && defined(CONFIG_POSIX_SYNCHRONIZED_IO))
#define _XOPEN_REALTIME _XOPEN_VERSION
#endif
/* #define _XOPEN_REALTIME_THREADS (-1L) */

/* #define _XOPEN_SHM (-1L) */

#ifdef CONFIG_XOPEN_STREAMS
Expand Down
124 changes: 51 additions & 73 deletions include/zephyr/posix/pthread.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,21 @@
#define PTHREAD_PROCESS_SHARED 1

/* Pthread cancellation */
#define PTHREAD_CANCELED ((void *)-1)
#define PTHREAD_CANCEL_ENABLE 0
#define PTHREAD_CANCEL_DISABLE 1
#define PTHREAD_CANCELED ((void *)-1)
#define PTHREAD_CANCEL_ENABLE 0
#define PTHREAD_CANCEL_DISABLE 1
#define PTHREAD_CANCEL_DEFERRED 0
#define PTHREAD_CANCEL_ASYNCHRONOUS 1

/* Pthread scope */
#undef PTHREAD_SCOPE_PROCESS
#define PTHREAD_SCOPE_PROCESS 1
#define PTHREAD_SCOPE_PROCESS 1
#undef PTHREAD_SCOPE_SYSTEM
#define PTHREAD_SCOPE_SYSTEM 0
#define PTHREAD_SCOPE_SYSTEM 0

/* Pthread inherit scheduler */
#undef PTHREAD_INHERIT_SCHED
#define PTHREAD_INHERIT_SCHED 0
#define PTHREAD_INHERIT_SCHED 0
#undef PTHREAD_EXPLICIT_SCHED
#define PTHREAD_EXPLICIT_SCHED 1

Expand Down Expand Up @@ -130,7 +130,7 @@
*
*/
int pthread_condattr_getclock(const pthread_condattr_t *ZRESTRICT att,
clockid_t *ZRESTRICT clock_id);
clockid_t *ZRESTRICT clock_id);

/**
* @brief POSIX threading compatibility API
Expand Down Expand Up @@ -165,10 +165,10 @@
* error is returned.
*
*/
#define PTHREAD_MUTEX_NORMAL 0
#define PTHREAD_MUTEX_RECURSIVE 1
#define PTHREAD_MUTEX_ERRORCHECK 2
#define PTHREAD_MUTEX_DEFAULT PTHREAD_MUTEX_NORMAL
#define PTHREAD_MUTEX_NORMAL 0
#define PTHREAD_MUTEX_RECURSIVE 1
#define PTHREAD_MUTEX_ERRORCHECK 2
#define PTHREAD_MUTEX_DEFAULT PTHREAD_MUTEX_NORMAL

/*
* Mutex attributes - protocol
Expand All @@ -182,9 +182,9 @@
* any of these mutexes).
* FIXME: Only PRIO_NONE is supported. Implement other protocols.
*/
#define PTHREAD_PRIO_NONE 0
#define PTHREAD_PRIO_INHERIT 1
#define PTHREAD_PRIO_PROTECT 2
#define PTHREAD_PRIO_NONE 0
#define PTHREAD_PRIO_INHERIT 1
#define PTHREAD_PRIO_PROTECT 2

/**
* @brief POSIX threading compatibility API
Expand Down Expand Up @@ -213,8 +213,7 @@
* See IEEE 1003.1
*/

int pthread_mutex_timedlock(pthread_mutex_t *m,
const struct timespec *abstime);
int pthread_mutex_timedlock(pthread_mutex_t *m, const struct timespec *abstime);

/**
* @brief POSIX threading compatibility API
Expand All @@ -228,15 +227,7 @@
*
* See IEEE 1003.1
*/
int pthread_mutex_init(pthread_mutex_t *m,
const pthread_mutexattr_t *att);

/**
* @brief POSIX threading compatibility API
*
* See IEEE 1003.1
*/
int pthread_mutexattr_setprotocol(pthread_mutexattr_t *attr, int protocol);
int pthread_mutex_init(pthread_mutex_t *m, const pthread_mutexattr_t *att);

/**
* @brief POSIX threading compatibility API
Expand All @@ -245,14 +236,6 @@
*/
int pthread_mutexattr_settype(pthread_mutexattr_t *attr, int type);

/**
* @brief POSIX threading compatibility API
*
* See IEEE 1003.1
*/
int pthread_mutexattr_getprotocol(const pthread_mutexattr_t *attr,
int *protocol);

/**
* @brief POSIX threading compatibility API
*
Expand Down Expand Up @@ -283,8 +266,8 @@
/*
* Barrier attributes - type
*/
#define PTHREAD_PROCESS_PRIVATE 0
#define PTHREAD_PROCESS_PUBLIC 1
#define PTHREAD_PROCESS_PRIVATE 0
#define PTHREAD_PROCESS_PUBLIC 1

/**
* @brief POSIX threading compatibility API
Expand Down Expand Up @@ -356,16 +339,6 @@
int pthread_mutexattr_setrobust(pthread_mutexattr_t *, int);
*/

#ifdef CONFIG_POSIX_THREAD_PRIO_PROTECT
int pthread_mutex_getprioceiling(const pthread_mutex_t *ZRESTRICT mutex,
int *ZRESTRICT prioceiling);
int pthread_mutex_setprioceiling(pthread_mutex_t *ZRESTRICT mutex, int prioceiling,
int *ZRESTRICT old_ceiling);
int pthread_mutexattr_getprioceiling(const pthread_mutexattr_t *ZRESTRICT attr,
int *ZRESTRICT prioceiling);
int pthread_mutexattr_setprioceiling(pthread_mutexattr_t *attr, int prioceiling);
#endif /* CONFIG_POSIX_THREAD_PRIO_PROTECT */

/* Base Pthread related APIs */

/**
Expand Down Expand Up @@ -413,18 +386,30 @@
int pthread_attr_getdetachstate(const pthread_attr_t *attr, int *detachstate);
int pthread_attr_init(pthread_attr_t *attr);
int pthread_attr_destroy(pthread_attr_t *attr);
int pthread_attr_getschedparam(const pthread_attr_t *attr,
struct sched_param *schedparam);
int pthread_getschedparam(pthread_t pthread, int *policy,
struct sched_param *param);
int pthread_attr_getstack(const pthread_attr_t *attr,
void **stackaddr, size_t *stacksize);
int pthread_attr_setstack(pthread_attr_t *attr, void *stackaddr,
size_t stacksize);
int pthread_attr_getscope(const pthread_attr_t *attr, int *contentionscope);
int pthread_attr_getschedparam(const pthread_attr_t *attr, struct sched_param *schedparam);
int pthread_attr_getstack(const pthread_attr_t *attr, void **stackaddr, size_t *stacksize);
int pthread_attr_setstack(pthread_attr_t *attr, void *stackaddr, size_t stacksize);

#if defined(CONFIG_XSI_REALTIME_THREADS)
int pthread_attr_getscope(const pthread_attr_t *ZRESTRICT attr, int *ZRESTRICT contentionscope);
int pthread_attr_setscope(pthread_attr_t *attr, int contentionscope);
int pthread_attr_getinheritsched(const pthread_attr_t *attr, int *inheritsched);
int pthread_attr_getinheritsched(const pthread_attr_t *ZRESTRICT attr, int *ZRESTRICT inheritsched);
int pthread_attr_setinheritsched(pthread_attr_t *attr, int inheritsched);
int pthread_attr_getschedpolicy(const pthread_attr_t *ZRESTRICT attr, int *ZRESTRICT policy);
int pthread_attr_setschedpolicy(pthread_attr_t *attr, int policy);
int pthread_getschedparam(pthread_t thread, int *ZRESTRICT policy,
struct sched_param *ZRESTRICT param);
int pthread_setschedparam(pthread_t pthread, int policy, const struct sched_param *param);
int pthread_setschedprio(pthread_t thread, int prio);
int pthread_mutexattr_getprotocol(const pthread_mutexattr_t *attr, int *protocol);
int pthread_mutexattr_setprotocol(pthread_mutexattr_t *attr, int protocol);
int pthread_mutex_getprioceiling(const pthread_mutex_t *mutex, int *prioceiling);
int pthread_mutex_setprioceiling(pthread_mutex_t *mutex, int prioceiling, int *old_ceiling);
int pthread_mutexattr_getprioceiling(const pthread_mutexattr_t *ZRESTRICT attr,
int *ZRESTRICT prioceiling);
int pthread_mutexattr_setprioceiling(pthread_mutexattr_t *attr, int prioceiling);
#endif

#ifdef CONFIG_POSIX_THREADS
int pthread_once(pthread_once_t *once, void (*initFunc)(void));
#endif
Expand All @@ -434,30 +419,22 @@
int pthread_join(pthread_t thread, void **status);
int pthread_cancel(pthread_t pthread);
int pthread_detach(pthread_t thread);
int pthread_create(pthread_t *newthread, const pthread_attr_t *attr,
void *(*threadroutine)(void *), void *arg);
int pthread_create(pthread_t *newthread, const pthread_attr_t *attr, void *(*threadroutine)(void *),
void *arg);
int pthread_setcancelstate(int state, int *oldstate);
int pthread_setcanceltype(int type, int *oldtype);
void pthread_testcancel(void);
int pthread_attr_setschedparam(pthread_attr_t *attr,
const struct sched_param *schedparam);
int pthread_setschedparam(pthread_t pthread, int policy,
const struct sched_param *param);
int pthread_setschedprio(pthread_t thread, int prio);
int pthread_attr_setschedparam(pthread_attr_t *attr, const struct sched_param *schedparam);
int pthread_rwlock_destroy(pthread_rwlock_t *rwlock);
int pthread_rwlock_init(pthread_rwlock_t *rwlock,
const pthread_rwlockattr_t *attr);
int pthread_rwlock_init(pthread_rwlock_t *rwlock, const pthread_rwlockattr_t *attr);
int pthread_rwlock_rdlock(pthread_rwlock_t *rwlock);
int pthread_rwlock_timedrdlock(pthread_rwlock_t *rwlock,
const struct timespec *abstime);
int pthread_rwlock_timedwrlock(pthread_rwlock_t *rwlock,
const struct timespec *abstime);
int pthread_rwlock_timedrdlock(pthread_rwlock_t *rwlock, const struct timespec *abstime);
int pthread_rwlock_timedwrlock(pthread_rwlock_t *rwlock, const struct timespec *abstime);
int pthread_rwlock_tryrdlock(pthread_rwlock_t *rwlock);
int pthread_rwlock_trywrlock(pthread_rwlock_t *rwlock);
int pthread_rwlock_unlock(pthread_rwlock_t *rwlock);
int pthread_rwlock_wrlock(pthread_rwlock_t *rwlock);
int pthread_key_create(pthread_key_t *key,
void (*destructor)(void *));
int pthread_key_create(pthread_key_t *key, void (*destructor)(void *));
int pthread_key_delete(pthread_key_t key);
int pthread_setspecific(pthread_key_t key, const void *value);
void *pthread_getspecific(pthread_key_t key);
Expand All @@ -471,11 +448,12 @@
#define pthread_cleanup_push(_rtn, _arg) \
do /* enforce '{'-like behaviour */ { \
void *_z_pthread_cleanup[3]; \
__z_pthread_cleanup_push(_z_pthread_cleanup, _rtn, _arg)
__z_pthread_cleanup_push(_z_pthread_cleanup, _rtn, _arg)

#define pthread_cleanup_pop(_ex) \
__z_pthread_cleanup_pop(_ex); \
} /* enforce '}'-like behaviour */ while (0)
__z_pthread_cleanup_pop(_ex); \
} /* enforce '}'-like behaviour */ \
while (0)

Check warning on line 456 in include/zephyr/posix/pthread.h

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

BRACES

include/zephyr/posix/pthread.h:456 braces {} are required around if/while/for/else

/* Glibc / Oracle Extension Functions */

Expand Down
3 changes: 3 additions & 0 deletions lib/posix/Kconfig.toolchain
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,9 @@ config TC_PROVIDES_XSI_MULTI_PROCESS
config TC_PROVIDES_XSI_REALTIME
bool

config TC_PROVIDES_XSI_REALTIME_THREADS
bool

config TC_PROVIDES_XSI_SIGNALS
bool

Expand Down
15 changes: 15 additions & 0 deletions lib/posix/options/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,21 @@ if(NOT CONFIG_TC_PROVIDES_XSI_REALTIME)
zephyr_library_sources_ifdef(CONFIG_POSIX_SHARED_MEMORY_OBJECTS shm.c)
endif()

if(NOT CONFIG_TC_PROVIDES_XSI_REALTIME_THREADS)
zephyr_library_sources_ifdef(CONFIG_XSI_REALTIME_THREADS
xsi_realtime_threads.c
)
endif()

if(CONFIG_XSI_REALTIME_THREADS)
zephyr_compile_definitions(-D_XOPEN_REALTIME_THREADS=${XOPEN_VERSION})
zephyr_compile_definitions(-D_POSIX_THREAD_PRIORITY_SCHEDULING=${POSIX_VERSION})
zephyr_compile_definitions(-D_POSIX_THREAD_PRIO_INHERIT=${POSIX_VERSION})
zephyr_compile_definitions(-D_POSIX_THREAD_PRIO_PROTECT=${POSIX_VERSION})
zephyr_compile_definitions(-D_POSIX_THREAD_ROBUST_PRIO_INHERIT=${POSIX_VERSION})
zephyr_compile_definitions(-D_POSIX_THREAD_ROBUST_PRIO_PROTECT=${POSIX_VERSION})
endif()

zephyr_library_sources_ifdef(CONFIG_XOPEN_STREAMS stropts.c)

if (NOT CONFIG_TC_PROVIDES_XSI_SINGLE_PROCESS)
Expand Down
1 change: 1 addition & 0 deletions lib/posix/options/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ menu "X/Open system interfaces"

# zephyr-keep-sorted-start
rsource "Kconfig.xsi_realtime"
rsource "Kconfig.xsi_realtime_threads"
rsource "Kconfig.xsi_single_process"
rsource "Kconfig.xsi_streams"
rsource "Kconfig.xsi_system_logging"
Expand Down
22 changes: 3 additions & 19 deletions lib/posix/options/Kconfig.pthread
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,7 @@ config POSIX_THREADS_EXT

config POSIX_THREAD_PRIORITY_SCHEDULING
bool "Run POSIX threads with different priorities and schedulers"
help
Enabling this option allows the application to configure different priorities and
scheduling algorithms for different threads via functions such as pthread_setschedparam()
and pthread_setschedprio(). This is required for Realtime Threads and Advanced Realtime
Threads.

For more information, please see
https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap02.html#tag_02_01_06
https://man7.org/linux/man-pages/man7/posixoptions.7.html
select DEPRECATED

config POSIX_PTHREAD_ATTR_STACKSIZE_BITS
int "Significant bits for pthread_attr_t stacksize"
Expand Down Expand Up @@ -143,19 +135,11 @@ config POSIX_PTHREAD_ATTR_GUARDSIZE_DEFAULT

config POSIX_THREAD_PRIO_INHERIT
bool "POSIX mutex priority inheritance"
help
Select 'y' here to enable POSIX mutex priority inheritance.

For more information, please see
https://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_mutexattr_getprotocol.html
select DEPRECATED

config POSIX_THREAD_PRIO_PROTECT
bool "POSIX mutex priority protection"
help
Select 'y' here to enable POSIX mutex priority protection.

For more information, please see
https://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_mutexattr_getprotocol.html
select DEPRECATED

config POSIX_THREAD_SAFE_FUNCTIONS
bool "POSIX thread-safe functions"
Expand Down
Loading
Loading