posix: deprecate PTHREAD_IPC _MUTEX _COND and _KEY

Zephyr's POSIX API is moving toward using the standard
nomenclature from IEEE 1003.1-2017 for as much as possible. In
particular, we want to have consistent naming between Zephyr's
POSIX API Kconfig options and the naming for POSIX Options and
Option Groups.

The Kconfig option CONFIG_PTHREAD_IPC has been (ab)used for a
very long time for a variety of different purposes. However,
the standard Option / feature test macro for POSIX Threads is,
intuitively _POSIX_THREADS. There is a corresponding sysconf()
key named _SC_POSIX_THREADS.

Annoyingly, the POSIX Option Group that corresponds to the
Option is POSIX_THREADS_BASE, which is a minor inconsistency
in the standard.

The _POSIX_THREADS Option already includes mutexes, condition
variables, and thread-specific storage (keys). So with this
change, we also deprecate the redundant Kconfig variables that
do not have a corresponding match in the standard.

- CONFIG_PTHREAD_IPC
- CONFIG_PTHREAD
- CONFIG_PTHREAD_COND
- CONFIG_PTHREAD_MUTEX
- CONFIG_PTHREAD_KEY

Additionally, create Kconfig variables for those configurables
which we are lacking:

- CONFIG_POSIX_THREADS_EXT
- CONFIG_POSIX_THREAD_ATTR_STACKSIZE
- CONFIG_POSIX_THREAD_ATTR_STACKADDR
- CONFIG_POSIX_THREAD_PRIORITY_SCHEDULING
- CONFIG_POSIX_THREAD_PRIO_INHERIT
- CONFIG_POSIX_THREAD_PRIO_PROTECT
- CONFIG_POSIX_THREAD_SAFE_FUNCTIONS

Some Kconfig variables were renamed to more properly match the spec:

- CONFIG_MAX_PTHREAD_COUNT -> CONFIG_POSIX_THREAD_THREADS_MAX
- CONFIG_MAX_PTHREAD_KEY_COUNT -> CONFIG_POSIX_THREAD_KEYS_MAX

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
This commit is contained in:
Chris Friedt 2024-05-22 23:48:17 -04:00 committed by David Leach
commit fcebe60090
36 changed files with 349 additions and 211 deletions

View file

@ -53,8 +53,7 @@ The *Minimal Realtime System Profile* (PSE51) includes all of the
:ref:`POSIX_DEVICE_IO <posix_option_group_device_io>`,, :kconfig:option:`CONFIG_POSIX_DEVICE_IO` :ref:`POSIX_DEVICE_IO <posix_option_group_device_io>`,, :kconfig:option:`CONFIG_POSIX_DEVICE_IO`
:ref:`POSIX_SIGNALS <posix_option_group_signals>`,, :ref:`POSIX_SIGNALS <posix_option_group_signals>`,,
:ref:`POSIX_SINGLE_PROCESS <posix_option_group_single_process>`, yes, :kconfig:option:`CONFIG_POSIX_SINGLE_PROCESS` :ref:`POSIX_SINGLE_PROCESS <posix_option_group_single_process>`, yes, :kconfig:option:`CONFIG_POSIX_SINGLE_PROCESS`
:ref:`POSIX_THREADS_BASE <posix_option_group_threads_base>`, yes, :ref:`XSI_THREADS_EXT <posix_option_group_xsi_threads_ext>`, yes, :kconfig:option:`CONFIG_XSI_THREADS_EXT`
:ref:`XSI_THREADS_EXT <posix_option_group_xsi_threads_ext>`, yes,
.. csv-table:: PSE51 Option Requirements .. csv-table:: PSE51 Option Requirements
:header: Symbol, Support, Remarks :header: Symbol, Support, Remarks
@ -66,12 +65,12 @@ The *Minimal Realtime System Profile* (PSE51) includes all of the
:ref:`_POSIX_MONOTONIC_CLOCK <posix_option_monotonic_clock>`, 200809L, :kconfig:option:`CONFIG_POSIX_MONOTONIC_CLOCK` :ref:`_POSIX_MONOTONIC_CLOCK <posix_option_monotonic_clock>`, 200809L, :kconfig:option:`CONFIG_POSIX_MONOTONIC_CLOCK`
:ref:`_POSIX_SHARED_MEMORY_OBJECTS <posix_shared_memory_objects>`, -1, :ref:`_POSIX_SHARED_MEMORY_OBJECTS <posix_shared_memory_objects>`, -1,
:ref:`_POSIX_SYNCHRONIZED_IO <posix_option_synchronized_io>`, -1, :kconfig:option:`CONFIG_POSIX_SYNCHRONIZED_IO` :ref:`_POSIX_SYNCHRONIZED_IO <posix_option_synchronized_io>`, -1, :kconfig:option:`CONFIG_POSIX_SYNCHRONIZED_IO`
:ref:`_POSIX_THREAD_ATTR_STACKADDR<posix_option_thread_attr_stackaddr>`, 200809L, :kconfig:option:`CONFIG_PTHREAD` :ref:`_POSIX_THREAD_ATTR_STACKADDR<posix_option_thread_attr_stackaddr>`, 200809L, :kconfig:option:`CONFIG_POSIX_THREAD_ATTR_STACKADDR`
:ref:`_POSIX_THREAD_ATTR_STACKSIZE<posix_option_thread_attr_stacksize>`, 200809L, :kconfig:option:`CONFIG_PTHREAD` :ref:`_POSIX_THREAD_ATTR_STACKSIZE<posix_option_thread_attr_stacksize>`, 200809L, :kconfig:option:`CONFIG_POSIX_THREAD_ATTR_STACKSIZE`
:ref:`_POSIX_THREAD_CPUTIME <posix_option_thread_cputime>`, 200809L, :kconfig:option:`CONFIG_POSIX_CPUTIME` :ref:`_POSIX_THREAD_CPUTIME <posix_option_thread_cputime>`, 200809L, :kconfig:option:`CONFIG_POSIX_CPUTIME`
_POSIX_THREAD_PRIO_INHERIT, 200809L, :kconfig:option:`CONFIG_PTHREAD_MUTEX` :ref:`_POSIX_THREAD_PRIO_INHERIT <posix_option_thread_prio_inherit>`, 200809L, :kconfig:option:`CONFIG_POSIX_THREAD_PRIO_INHERIT`
_POSIX_THREAD_PRIO_PROTECT, -1, :ref:`_POSIX_THREAD_PRIO_PROTECT <posix_option_thread_prio_protect>`, -1, :kconfig:option:`CONFIG_POSIX_THREAD_PRIO_PROTECT`
:ref:`_POSIX_THREAD_PRIORITY_SCHEDULING<posix_option_thread_priority_scheduling>`, 200809L, :kconfig:option:`CONFIG_POSIX_PRIORITY_SCHEDULING` :ref:`_POSIX_THREAD_PRIORITY_SCHEDULING <posix_option_thread_priority_scheduling>`, 200809L, :kconfig:option:`CONFIG_POSIX_THREAD_PRIORITY_SCHEDULING`
_POSIX_THREAD_SPORADIC_SERVER, -1, _POSIX_THREAD_SPORADIC_SERVER, -1,
.. _posix_aep_pse52: .. _posix_aep_pse52:

View file

@ -70,8 +70,8 @@ POSIX System Interfaces
:ref:`_POSIX_REALTIME_SIGNALS<posix_option_group_realtime_signals>`, -1, :ref:`_POSIX_REALTIME_SIGNALS<posix_option_group_realtime_signals>`, -1,
:ref:`_POSIX_SEMAPHORES<posix_option_group_semaphores>`, 200809L, :kconfig:option:`CONFIG_POSIX_SEMAPHORES` :ref:`_POSIX_SEMAPHORES<posix_option_group_semaphores>`, 200809L, :kconfig:option:`CONFIG_POSIX_SEMAPHORES`
:ref:`_POSIX_SPIN_LOCKS<posix_option_group_spin_locks>`, 200809L, :kconfig:option:`CONFIG_POSIX_SPIN_LOCKS` :ref:`_POSIX_SPIN_LOCKS<posix_option_group_spin_locks>`, 200809L, :kconfig:option:`CONFIG_POSIX_SPIN_LOCKS`
:ref:`_POSIX_THREAD_SAFE_FUNCTIONS<posix_thread_safe_functions>`, -1, :ref:`_POSIX_THREAD_SAFE_FUNCTIONS<posix_thread_safe_functions>`, -1, :kconfig:option:`CONFIG_POSIX_THREAD_SAFE_FUNCTIONS`
:ref:`_POSIX_THREADS<posix_option_group_threads_base>`, -1, :kconfig:option:`CONFIG_PTHREAD_IPC` :ref:`_POSIX_THREADS<posix_option_group_threads_base>`, -1, :kconfig:option:`CONFIG_POSIX_THREADS`
:ref:`_POSIX_TIMEOUTS<posix_option_timeouts>`, 200809L, :kconfig:option:`CONFIG_POSIX_TIMEOUTS` :ref:`_POSIX_TIMEOUTS<posix_option_timeouts>`, 200809L, :kconfig:option:`CONFIG_POSIX_TIMEOUTS`
:ref:`_POSIX_TIMERS<posix_option_group_timers>`, 200809L, :kconfig:option:`CONFIG_POSIX_TIMERS` :ref:`_POSIX_TIMERS<posix_option_group_timers>`, 200809L, :kconfig:option:`CONFIG_POSIX_TIMERS`
_POSIX2_C_BIND, 200809L, _POSIX2_C_BIND, 200809L,
@ -95,12 +95,12 @@ POSIX System Interfaces
_POSIX_SPAWN, -1, :ref:`†<posix_undefined_behaviour>` _POSIX_SPAWN, -1, :ref:`†<posix_undefined_behaviour>`
_POSIX_SPORADIC_SERVER, -1, :ref:`†<posix_undefined_behaviour>` _POSIX_SPORADIC_SERVER, -1, :ref:`†<posix_undefined_behaviour>`
:ref:`_POSIX_SYNCHRONIZED_IO <posix_option_synchronized_io>`, -1, :kconfig:option:`CONFIG_POSIX_SYNCHRONIZED_IO` :ref:`_POSIX_SYNCHRONIZED_IO <posix_option_synchronized_io>`, -1, :kconfig:option:`CONFIG_POSIX_SYNCHRONIZED_IO`
:ref:`_POSIX_THREAD_ATTR_STACKADDR<posix_option_thread_attr_stackaddr>`, 200809L, :kconfig:option:`CONFIG_PTHREAD` :ref:`_POSIX_THREAD_ATTR_STACKADDR<posix_option_thread_attr_stackaddr>`, 200809L, :kconfig:option:`CONFIG_POSIX_THREAD_ATTR_STACKADDR`
:ref:`_POSIX_THREAD_ATTR_STACKSIZE<posix_option_thread_attr_stacksize>`, 200809L, :kconfig:option:`CONFIG_PTHREAD` :ref:`_POSIX_THREAD_ATTR_STACKSIZE<posix_option_thread_attr_stacksize>`, 200809L, :kconfig:option:`CONFIG_POSIX_THREAD_ATTR_STACKSIZE`
:ref:`_POSIX_THREAD_CPUTIME <posix_option_thread_cputime>`, 200809L, :kconfig:option:`CONFIG_POSIX_CPUTIME` :ref:`_POSIX_THREAD_CPUTIME <posix_option_thread_cputime>`, 200809L, :kconfig:option:`CONFIG_POSIX_CPUTIME`
_POSIX_THREAD_PRIO_INHERIT, 200809L, :kconfig:option:`CONFIG_PTHREAD_MUTEX` :ref:`_POSIX_THREAD_PRIO_INHERIT <posix_option_thread_prio_inherit>`, 200809L, :kconfig:option:`CONFIG_POSIX_THREAD_PRIO_INHERIT`
_POSIX_THREAD_PRIO_PROTECT, -1, :ref:`_POSIX_THREAD_PRIO_PROTECT <posix_option_thread_prio_protect>`, -1, :kconfig:option:`CONFIG_POSIX_THREAD_PRIO_PROTECT`
:ref:`_POSIX_THREAD_PRIORITY_SCHEDULING<posix_option_thread_priority_scheduling>`, 200809L, :kconfig:option:`CONFIG_PTHREAD` :ref:`_POSIX_THREAD_PRIORITY_SCHEDULING <posix_option_thread_priority_scheduling>`, 200809L, :kconfig:option:`CONFIG_POSIX_THREAD_PRIORITY_SCHEDULING`
_POSIX_THREAD_PROCESS_SHARED, -1, _POSIX_THREAD_PROCESS_SHARED, -1,
_POSIX_THREAD_SPORADIC_SERVER, -1, _POSIX_THREAD_SPORADIC_SERVER, -1,
_POSIX_TRACE, -1, _POSIX_TRACE, -1,
@ -149,8 +149,8 @@ XSI System Interfaces
:widths: 50, 10, 50 :widths: 50, 10, 50
:ref:`_POSIX_FSYNC<posix_option_fsync>`, 200809L, :kconfig:option:`CONFIG_POSIX_FSYNC` :ref:`_POSIX_FSYNC<posix_option_fsync>`, 200809L, :kconfig:option:`CONFIG_POSIX_FSYNC`
:ref:`_POSIX_THREAD_ATTR_STACKADDR<posix_option_thread_attr_stackaddr>`, 200809L, :kconfig:option:`CONFIG_PTHREAD` :ref:`_POSIX_THREAD_ATTR_STACKADDR<posix_option_thread_attr_stackaddr>`, 200809L, :kconfig:option:`CONFIG_POSIX_THREAD_ATTR_STACKADDR`
:ref:`_POSIX_THREAD_ATTR_STACKSIZE<posix_option_thread_attr_stacksize>`, 200809L, :kconfig:option:`CONFIG_PTHREAD` :ref:`_POSIX_THREAD_ATTR_STACKSIZE<posix_option_thread_attr_stacksize>`, 200809L, :kconfig:option:`CONFIG_POSIX_THREAD_ATTR_STACKSIZE`
_POSIX_THREAD_PROCESS_SHARED, -1, _POSIX_THREAD_PROCESS_SHARED, -1,
.. _CX: https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap01.html .. _CX: https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap01.html

View file

@ -10,9 +10,6 @@ implementation of the POSIX API.
* :kconfig:option:`CONFIG_EVENTFD_MAX` * :kconfig:option:`CONFIG_EVENTFD_MAX`
* :kconfig:option:`CONFIG_FDTABLE` * :kconfig:option:`CONFIG_FDTABLE`
* :kconfig:option:`CONFIG_GETOPT_LONG` * :kconfig:option:`CONFIG_GETOPT_LONG`
* :kconfig:option:`CONFIG_MAX_PTHREAD_COUNT`
* :kconfig:option:`CONFIG_MAX_PTHREAD_KEY_COUNT`
* :kconfig:option:`CONFIG_MAX_PTHREAD_MUTEX_COUNT`
* :kconfig:option:`CONFIG_MAX_PTHREAD_SPINLOCK_COUNT` * :kconfig:option:`CONFIG_MAX_PTHREAD_SPINLOCK_COUNT`
* :kconfig:option:`CONFIG_MQUEUE_NAMELEN_MAX` * :kconfig:option:`CONFIG_MQUEUE_NAMELEN_MAX`
* :kconfig:option:`CONFIG_POSIX_MQ_OPEN_MAX` * :kconfig:option:`CONFIG_POSIX_MQ_OPEN_MAX`
@ -23,17 +20,17 @@ implementation of the POSIX API.
* :kconfig:option:`CONFIG_POSIX_API` * :kconfig:option:`CONFIG_POSIX_API`
* :kconfig:option:`CONFIG_ZVFS_OPEN_MAX` * :kconfig:option:`CONFIG_ZVFS_OPEN_MAX`
* :kconfig:option:`CONFIG_POSIX_OPEN_MAX` * :kconfig:option:`CONFIG_POSIX_OPEN_MAX`
* :kconfig:option:`CONFIG_POSIX_PTHREAD_ATTR_GUARDSIZE_BITS`
* :kconfig:option:`CONFIG_POSIX_PTHREAD_ATTR_GUARDSIZE_DEFAULT`
* :kconfig:option:`CONFIG_POSIX_PTHREAD_ATTR_STACKSIZE_BITS`
* :kconfig:option:`CONFIG_POSIX_RTSIG_MAX` * :kconfig:option:`CONFIG_POSIX_RTSIG_MAX`
* :kconfig:option:`CONFIG_POSIX_SIGNAL` * :kconfig:option:`CONFIG_POSIX_SIGNAL`
* :kconfig:option:`CONFIG_POSIX_SIGNAL_STRING_DESC` * :kconfig:option:`CONFIG_POSIX_SIGNAL_STRING_DESC`
* :kconfig:option:`CONFIG_POSIX_THREAD_KEYS_MAX`
* :kconfig:option:`CONFIG_POSIX_THREAD_THREADS_MAX`
* :kconfig:option:`CONFIG_POSIX_UNAME_NODENAME_LEN` * :kconfig:option:`CONFIG_POSIX_UNAME_NODENAME_LEN`
* :kconfig:option:`CONFIG_POSIX_UNAME_VERSION_LEN` * :kconfig:option:`CONFIG_POSIX_UNAME_VERSION_LEN`
* :kconfig:option:`CONFIG_PTHREAD`
* :kconfig:option:`CONFIG_PTHREAD_COND`
* :kconfig:option:`CONFIG_PTHREAD_CREATE_BARRIER` * :kconfig:option:`CONFIG_PTHREAD_CREATE_BARRIER`
* :kconfig:option:`CONFIG_PTHREAD_IPC`
* :kconfig:option:`CONFIG_PTHREAD_KEY`
* :kconfig:option:`CONFIG_PTHREAD_MUTEX`
* :kconfig:option:`CONFIG_PTHREAD_RECYCLER_DELAY_MS` * :kconfig:option:`CONFIG_PTHREAD_RECYCLER_DELAY_MS`
* :kconfig:option:`CONFIG_POSIX_SEM_NAMELEN_MAX` * :kconfig:option:`CONFIG_POSIX_SEM_NAMELEN_MAX`
* :kconfig:option:`CONFIG_POSIX_SEM_NSEMS_MAX` * :kconfig:option:`CONFIG_POSIX_SEM_NSEMS_MAX`

View file

@ -778,6 +778,34 @@ _POSIX_THREAD_PRIORITY_SCHEDULING
pthread_setschedparam(),yes pthread_setschedparam(),yes
pthread_setschedprio(),yes pthread_setschedprio(),yes
.. _posix_option_thread_prio_inherit:
_POSIX_THREAD_PRIO_INHERIT
++++++++++++++++++++++++++
.. csv-table:: _POSIX_THREAD_PRIO_INHERIT
:header: API, Supported
:widths: 50,10
pthread_mutexattr_getprotocol(),yes
pthread_mutexattr_setprotocol(),yes
.. _posix_option_thread_prio_protect:
_POSIX_THREAD_PRIO_PROTECT
++++++++++++++++++++++++++
.. csv-table:: _POSIX_THREAD_PRIO_PROTECT
:header: API, Supported
:widths: 50,10
pthread_mutex_getprioceiling(),
pthread_mutex_setprioceiling(),
pthread_mutexattr_getprioceiling(),
pthread_mutexattr_getprotocol(),yes
pthread_mutexattr_setprioceiling(),
pthread_mutexattr_setprotocol(),yes
.. _posix_thread_safe_functions: .. _posix_thread_safe_functions:
_POSIX_THREAD_SAFE_FUNCTIONS _POSIX_THREAD_SAFE_FUNCTIONS

View file

@ -129,8 +129,7 @@ feature selection at various levels of granularity.
Alternatively, users may enable one of the Kconfig options below as a shortcut to enable multiple Alternatively, users may enable one of the Kconfig options below as a shortcut to enable multiple
:ref:`Option Groups<posix_option_groups>`. :ref:`Option Groups<posix_option_groups>`.
* :kconfig:option:`CONFIG_POSIX_API` * :kconfig:option:`CONFIG_POSIX_API` - Enables all implemented POSIX API Options and Option Groups
* :kconfig:option:`CONFIG_PTHREAD_IPC`
.. note:: .. note::
Since the POSIX environment in Zephyr is fully configurable via :ref:`Kconfig<kconfig>`, Since the POSIX environment in Zephyr is fully configurable via :ref:`Kconfig<kconfig>`,

View file

@ -94,11 +94,11 @@
/* #define _POSIX_SPORADIC_SERVER (-1L) */ /* #define _POSIX_SPORADIC_SERVER (-1L) */
/* #define _POSIX_SYNCHRONIZED_IO (-1L) */ /* #define _POSIX_SYNCHRONIZED_IO (-1L) */
#ifdef CONFIG_PTHREAD_IPC #ifdef CONFIG_POSIX_THREAD_ATTR_STACKADDR
#define _POSIX_THREAD_ATTR_STACKADDR _POSIX_VERSION #define _POSIX_THREAD_ATTR_STACKADDR _POSIX_VERSION
#endif #endif
#ifdef CONFIG_PTHREAD_IPC #ifdef CONFIG_POSIX_THREAD_ATTR_STACKSIZE
#define _POSIX_THREAD_ATTR_STACKSIZE _POSIX_VERSION #define _POSIX_THREAD_ATTR_STACKSIZE _POSIX_VERSION
#endif #endif
@ -106,23 +106,29 @@
#define _POSIX_THREAD_CPUTIME _POSIX_VERSION #define _POSIX_THREAD_CPUTIME _POSIX_VERSION
#endif #endif
#ifdef CONFIG_PTHREAD_IPC #ifdef CONFIG_POSIX_THREAD_PRIO_INHERIT
#define _POSIX_THREAD_PRIO_INHERIT _POSIX_VERSION #define _POSIX_THREAD_PRIO_INHERIT _POSIX_VERSION
#endif #endif
/* #define _POSIX_THREAD_PRIO_PROTECT (-1L) */ #ifdef CONFIG_POSIX_THREAD_PRIO_PROTECT
/* #define _POSIX_THREAD_PRIORITY_SCHEDULING (-1L) */ #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_PROCESS_SHARED (-1L) */
/* #define _POSIX_THREAD_ROBUST_PRIO_INHERIT (-1L) */ /* #define _POSIX_THREAD_ROBUST_PRIO_INHERIT (-1L) */
/* #define _POSIX_THREAD_ROBUST_PRIO_PROTECT (-1L) */ /* #define _POSIX_THREAD_ROBUST_PRIO_PROTECT (-1L) */
#ifdef CONFIG_PTHREAD_IPC #ifdef CONFIG_POSIX_THREAD_SAFE_FUNCTIONS
#define _POSIX_THREAD_SAFE_FUNCTIONS _POSIX_VERSION #define _POSIX_THREAD_SAFE_FUNCTIONS _POSIX_VERSION
#endif #endif
/* #define _POSIX_THREAD_SPORADIC_SERVER (-1L) */ /* #define _POSIX_THREAD_SPORADIC_SERVER (-1L) */
#ifdef CONFIG_PTHREAD_IPC #ifdef CONFIG_POSIX_THREADS
#ifndef _POSIX_THREADS #ifndef _POSIX_THREADS
#define _POSIX_THREADS _POSIX_VERSION #define _POSIX_THREADS _POSIX_VERSION
#endif #endif
@ -229,9 +235,9 @@
#define _POSIX_SYMLOOP_MAX (8) #define _POSIX_SYMLOOP_MAX (8)
#define _POSIX_THREAD_DESTRUCTOR_ITERATIONS (4) #define _POSIX_THREAD_DESTRUCTOR_ITERATIONS (4)
#define _POSIX_THREAD_KEYS_MAX \ #define _POSIX_THREAD_KEYS_MAX \
COND_CODE_1(CONFIG_PTHREAD_IPC, (CONFIG_MAX_PTHREAD_KEY_COUNT), (0)) COND_CODE_1(CONFIG_POSIX_THREADS, (CONFIG_POSIX_THREAD_KEYS_MAX), (0))
#define _POSIX_THREAD_THREADS_MAX \ #define _POSIX_THREAD_THREADS_MAX \
COND_CODE_1(CONFIG_PTHREAD_IPC, (CONFIG_MAX_PTHREAD_COUNT), (0)) COND_CODE_1(CONFIG_POSIX_THREADS, (CONFIG_POSIX_THREAD_THREADS_MAX), (0))
#define _POSIX_TIMER_MAX \ #define _POSIX_TIMER_MAX \
COND_CODE_1(CONFIG_POSIX_TIMERS, (CONFIG_POSIX_TIMER_MAX), (0)) COND_CODE_1(CONFIG_POSIX_TIMERS, (CONFIG_POSIX_TIMER_MAX), (0))
#define _POSIX_TRACE_EVENT_NAME_MAX (30) #define _POSIX_TRACE_EVENT_NAME_MAX (30)

View file

@ -417,7 +417,7 @@ int pthread_attr_getscope(const pthread_attr_t *attr, int *contentionscope);
int pthread_attr_setscope(pthread_attr_t *attr, int 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 *attr, int *inheritsched);
int pthread_attr_setinheritsched(pthread_attr_t *attr, int inheritsched); int pthread_attr_setinheritsched(pthread_attr_t *attr, int inheritsched);
#ifdef CONFIG_PTHREAD_IPC #ifdef CONFIG_POSIX_THREADS
int pthread_once(pthread_once_t *once, void (*initFunc)(void)); int pthread_once(pthread_once_t *once, void (*initFunc)(void));
#endif #endif
FUNC_NORETURN void pthread_exit(void *retval); FUNC_NORETURN void pthread_exit(void *retval);
@ -502,7 +502,7 @@ int pthread_setname_np(pthread_t thread, const char *name);
*/ */
int pthread_getname_np(pthread_t thread, char *name, size_t len); int pthread_getname_np(pthread_t thread, char *name, size_t len);
#ifdef CONFIG_PTHREAD_IPC #ifdef CONFIG_POSIX_THREADS
/** /**
* @brief Destroy a pthread_spinlock_t. * @brief Destroy a pthread_spinlock_t.

View file

@ -183,22 +183,24 @@ enum {
#define __z_posix_sysconf_SC_SS_REPL_MAX _POSIX_SS_REPL_MAX #define __z_posix_sysconf_SC_SS_REPL_MAX _POSIX_SS_REPL_MAX
#define __z_posix_sysconf_SC_SYNCHRONIZED_IO (-1L) #define __z_posix_sysconf_SC_SYNCHRONIZED_IO (-1L)
#define __z_posix_sysconf_SC_THREAD_ATTR_STACKADDR \ #define __z_posix_sysconf_SC_THREAD_ATTR_STACKADDR \
COND_CODE_1(CONFIG_PTHREAD_IPC, (_POSIX_THREAD_ATTR_STACKADDR), (-1)) COND_CODE_1(CONFIG_POSIX_THREAD_ATTR_STACKADDR, (_POSIX_THREAD_ATTR_STACKADDR), (-1))
#define __z_posix_sysconf_SC_THREAD_ATTR_STACKSIZE \ #define __z_posix_sysconf_SC_THREAD_ATTR_STACKSIZE \
COND_CODE_1(CONFIG_PTHREAD_IPC, (_POSIX_THREAD_ATTR_STACKSIZE), (-1L)) COND_CODE_1(CONFIG_POSIX_THREAD_ATTR_STACKSIZE, (_POSIX_THREAD_ATTR_STACKSIZE), (-1L))
#define __z_posix_sysconf_SC_THREAD_CPUTIME (-1L) #define __z_posix_sysconf_SC_THREAD_CPUTIME (-1L)
#define __z_posix_sysconf_SC_THREAD_PRIO_INHERIT \ #define __z_posix_sysconf_SC_THREAD_PRIO_INHERIT \
COND_CODE_1(CONFIG_PTHREAD_IPC, (_POSIX_THREAD_PRIO_INHERIT), (-1L)) COND_CODE_1(CONFIG_POSIX_THREAD_PRIO_INHERIT, (_POSIX_THREAD_PRIO_INHERIT), (-1L))
#define __z_posix_sysconf_SC_THREAD_PRIO_PROTECT (-1L) #define __z_posix_sysconf_SC_THREAD_PRIO_PROTECT (-1L)
#define __z_posix_sysconf_SC_THREAD_PRIORITY_SCHEDULING (-1L) #define __z_posix_sysconf_SC_THREAD_PRIORITY_SCHEDULING \
COND_CODE_1(CONFIG_POSIX_THREAD_PRIORITY_SCHEDULING, (_POSIX_THREAD_PRIORITY_SCHEDULING), \
(-1L))
#define __z_posix_sysconf_SC_THREAD_PROCESS_SHARED (-1L) #define __z_posix_sysconf_SC_THREAD_PROCESS_SHARED (-1L)
#define __z_posix_sysconf_SC_THREAD_ROBUST_PRIO_INHERIT (-1L) #define __z_posix_sysconf_SC_THREAD_ROBUST_PRIO_INHERIT (-1L)
#define __z_posix_sysconf_SC_THREAD_ROBUST_PRIO_PROTECT (-1L) #define __z_posix_sysconf_SC_THREAD_ROBUST_PRIO_PROTECT (-1L)
#define __z_posix_sysconf_SC_THREAD_SAFE_FUNCTIONS \ #define __z_posix_sysconf_SC_THREAD_SAFE_FUNCTIONS \
COND_CODE_1(CONFIG_PTHREAD_IPC, (_POSIX_THREAD_SAFE_FUNCTIONS), (-1L)) COND_CODE_1(CONFIG_POSIX_THREAD_SAFE_FUNCTIONS, (_POSIX_THREAD_SAFE_FUNCTIONS), (-1L))
#define __z_posix_sysconf_SC_THREAD_SPORADIC_SERVER (-1L) #define __z_posix_sysconf_SC_THREAD_SPORADIC_SERVER (-1L)
#define __z_posix_sysconf_SC_THREADS \ #define __z_posix_sysconf_SC_THREADS \
COND_CODE_1(CONFIG_PTHREAD_IPC, (_POSIX_THREADS), (-1L)) COND_CODE_1(CONFIG_POSIX_THREADS, (_POSIX_THREADS), (-1L))
#define __z_posix_sysconf_SC_TIMEOUTS \ #define __z_posix_sysconf_SC_TIMEOUTS \
COND_CODE_1(CONFIG_POSIX_TIMEOUTS, (_POSIX_TIMEOUTS), (-1L)) COND_CODE_1(CONFIG_POSIX_TIMEOUTS, (_POSIX_TIMEOUTS), (-1L))
#define __z_posix_sysconf_SC_TIMERS \ #define __z_posix_sysconf_SC_TIMERS \

View file

@ -24,7 +24,7 @@ if(CONFIG_POSIX_SIGNAL)
) )
endif() endif()
if(CONFIG_POSIX_API OR CONFIG_PTHREAD_IPC OR CONFIG_POSIX_TIMERS OR if(CONFIG_POSIX_API OR CONFIG_POSIX_THREADS OR CONFIG_POSIX_TIMERS OR
CONFIG_POSIX_MESSAGE_PASSING OR CONFIG_POSIX_FILE_SYSTEM OR CONFIG_EVENTFD OR CONFIG_POSIX_MESSAGE_PASSING OR CONFIG_POSIX_FILE_SYSTEM OR CONFIG_EVENTFD OR
CONFIG_POSIX_C_LIB_EXT OR CONFIG_POSIX_SINGLE_PROCESS) CONFIG_POSIX_C_LIB_EXT OR CONFIG_POSIX_SINGLE_PROCESS)
# This is a temporary workaround so that Newlib declares the appropriate # This is a temporary workaround so that Newlib declares the appropriate
@ -70,15 +70,17 @@ zephyr_library_sources_ifdef(CONFIG_POSIX_SYSLOG syslog.c)
zephyr_library_sources_ifdef(CONFIG_POSIX_TIMERS zephyr_library_sources_ifdef(CONFIG_POSIX_TIMERS
clock.c clock.c
timer.c timer.c
timespec_to_timeout.c
) )
zephyr_library_sources_ifdef(CONFIG_PTHREAD_IPC _common.c)
zephyr_library_sources_ifdef(CONFIG_PTHREAD_COND cond.c)
zephyr_library_sources_ifdef(CONFIG_PTHREAD_KEY key.c)
zephyr_library_sources_ifdef(CONFIG_PTHREAD_MUTEX mutex.c)
zephyr_library_sources_ifdef(CONFIG_PTHREAD pthread.c)
zephyr_library_sources_ifdef(CONFIG_POSIX_PRIORITY_SCHEDULING sched.c) zephyr_library_sources_ifdef(CONFIG_POSIX_PRIORITY_SCHEDULING sched.c)
zephyr_library_sources_ifdef(CONFIG_POSIX_READER_WRITER_LOCKS rwlock.c) zephyr_library_sources_ifdef(CONFIG_POSIX_READER_WRITER_LOCKS rwlock.c)
zephyr_library_sources_ifdef(CONFIG_POSIX_SEMAPHORES semaphore.c) zephyr_library_sources_ifdef(CONFIG_POSIX_SEMAPHORES semaphore.c)
zephyr_library_sources_ifdef(CONFIG_POSIX_THREADS
cond.c
key.c
mutex.c
pthread.c
)
zephyr_library_sources_ifdef(CONFIG_XOPEN_STREAMS stropts.c) zephyr_library_sources_ifdef(CONFIG_XOPEN_STREAMS stropts.c)
zephyr_library_sources_ifdef(CONFIG_XSI_SYSTEM_LOGGING syslog.c) zephyr_library_sources_ifdef(CONFIG_XSI_SYSTEM_LOGGING syslog.c)

View file

@ -14,26 +14,14 @@ config POSIX_API
Enable mostly-standards-compliant implementations of Enable mostly-standards-compliant implementations of
various POSIX (IEEE 1003.1) APIs. various POSIX (IEEE 1003.1) APIs.
config PTHREAD_IPC
bool "POSIX pthread IPC API"
default y if POSIX_API
depends on POSIX_TIMERS
help
This enables a mostly-standards-compliant implementation of
the pthread mutex, condition variable and barrier IPC
mechanisms.
rsource "Kconfig.aio" rsource "Kconfig.aio"
rsource "Kconfig.barrier" rsource "Kconfig.barrier"
rsource "Kconfig.cond"
rsource "Kconfig.c_lib_ext" rsource "Kconfig.c_lib_ext"
rsource "Kconfig.device_io" rsource "Kconfig.device_io"
rsource "Kconfig.fd_mgmt" rsource "Kconfig.fd_mgmt"
rsource "Kconfig.fs" rsource "Kconfig.fs"
rsource "Kconfig.key"
rsource "Kconfig.mem" rsource "Kconfig.mem"
rsource "Kconfig.mqueue" rsource "Kconfig.mqueue"
rsource "Kconfig.mutex"
rsource "Kconfig.net" rsource "Kconfig.net"
rsource "Kconfig.proc1" rsource "Kconfig.proc1"
rsource "Kconfig.procN" rsource "Kconfig.procN"

View file

@ -1,9 +0,0 @@
# Copyright (c) 2017 Intel Corporation
# Copyright (c) 2023 Meta
#
# SPDX-License-Identifier: Apache-2.0
TYPE = PTHREAD_COND
type = pthread_cond_t
type-function = pthread_cond_wait
rsource "Kconfig.template.pooled_ipc_type"

View file

@ -33,6 +33,24 @@ config GETOPT
Please use CONFIG_POSIX_C_LIB_EXT instead. Please use CONFIG_POSIX_C_LIB_EXT instead.
config MAX_PTHREAD_COUNT
int "Maximum number of pthread_t [DEPRECATED]"
default POSIX_THREAD_THREADS_MAX if POSIX_THREADS
default 0
help
This option is deprecated.
Please use CONFIG_POSIX_THREAD_THREADS_MAX instead.
config MAX_PTHREAD_KEY_COUNT
int "Maximum number of pthread_key_t [DEPRECATED]"
default POSIX_THREAD_KEYS_MAX if POSIX_THREADS
default 0
help
This option is deprecated.
Please use CONFIG_POSIX_THREAD_KEYS_MAX instead.
config MAX_TIMER_COUNT config MAX_TIMER_COUNT
int "Maximum number of timer_t [DEPRECATED]" int "Maximum number of timer_t [DEPRECATED]"
default POSIX_TIMER_MAX if POSIX_TIMERS default POSIX_TIMER_MAX if POSIX_TIMERS
@ -165,6 +183,15 @@ config POSIX_UNAME
Please use CONFIG_POSIX_SINGLE_PROCESS instead. Please use CONFIG_POSIX_SINGLE_PROCESS instead.
config PTHREAD
bool "pthread_t support [DEPRECATED]"
select DEPRECATED
select POSIX_THREADS
help
This option is deprecated.
Please use CONFIG_POSIX_THREADS instead.
config PTHREAD_BARRIER config PTHREAD_BARRIER
bool "pthread_barrier_t support [DEPRECATED]" bool "pthread_barrier_t support [DEPRECATED]"
select DEPRECATED select DEPRECATED
@ -174,6 +201,43 @@ config PTHREAD_BARRIER
Please use CONFIG_POSIX_BARRIERS instead. Please use CONFIG_POSIX_BARRIERS instead.
config PTHREAD_COND
bool "pthread_cond_t support [DEPRECATED]"
select DEPRECATED
select POSIX_THREADS
help
This option is deprecated.
Please use CONFIG_POSIX_THREADS instead.
config PTHREAD_IPC
bool "POSIX pthread IPC API [DEPRECATED]"
select DEPRECATED
select POSIX_THREADS
help
This option is deprecated.
Please use CONFIG_POSIX_THREADS instead.
config PTHREAD_KEY
bool "pthread_key_t support [DEPRECATED]"
select DEPRECATED
select POSIX_THREADS
help
This option is deprecated.
Please use CONFIG_POSIX_THREADS instead.
config PTHREAD_MUTEX
bool "pthread_mutex_t support [DEPRECATED]"
select DEPRECATED
select POSIX_THREADS
help
This option is deprecated.
Please use CONFIG_POSIX_THREADS instead.
config PTHREAD_RWLOCK config PTHREAD_RWLOCK
bool "pthread_spinlock_t support [DEPRECATED]" bool "pthread_spinlock_t support [DEPRECATED]"
select DEPRECATED select DEPRECATED

View file

@ -1,9 +0,0 @@
# Copyright (c) 2018 Intel Corporation
# Copyright (c) 2023 Meta
#
# SPDX-License-Identifier: Apache-2.0
TYPE = PTHREAD_KEY
type = pthread_key_t
type-function = pthread_setspecific
rsource "Kconfig.template.pooled_ipc_type"

View file

@ -1,9 +0,0 @@
# Copyright (c) 2017 Intel Corporation
# Copyright (c) 2023 Meta
#
# SPDX-License-Identifier: Apache-2.0
TYPE = PTHREAD_MUTEX
type = pthread_mutex_t
type-function = pthread_mutex_lock
rsource "Kconfig.template.pooled_ipc_type"

View file

@ -1,14 +1,50 @@
# Copyright (c) 2017 Intel Corporation # Copyright (c) 2017 Intel Corporation
# Copyright (c) 2023 Meta # Copyright (c) 2023 Meta
# Copyright (c) 2024 Tenstorrent AI ULC
# #
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
TYPE = PTHREAD menuconfig POSIX_THREADS
type = pthread_t bool "POSIX thread support"
type-function = pthread_create default y if POSIX_API
rsource "Kconfig.template.pooled_ipc_type" help
Select 'y' here to enable POSIX threads, mutexes, condition variables, and thread-specific
storage.
if PTHREAD For more information please see
https://pubs.opengroup.org/onlinepubs/9699919799/xrat/V4_subprofiles.html
if POSIX_THREADS
config POSIX_THREAD_THREADS_MAX
int "Maximum number of POSIX threads"
default 5
help
Maximum simultaneously active threads in a POSIX application.
For more information, see
https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/limits.h.html
config MAX_PTHREAD_MUTEX_COUNT
int "Maximum number of POSIX mutexes"
default 5
help
Maximum simultaneously active mutexes in a POSIX application.
config MAX_PTHREAD_COND_COUNT
int "Maximum number of POSIX condition variables"
default 5
help
Maximum simultaneously active condition variables in a POSIX application.
config POSIX_THREAD_KEYS_MAX
int "Maximum number of POSIX thread-specific-storage keys"
default 5
help
Maximum simultaneously active thread-specific-storage keys in a POSIX application.
For more information, see
https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/limits.h.html
config PTHREAD_RECYCLER_DELAY_MS config PTHREAD_RECYCLER_DELAY_MS
int "Delay for reclaiming dynamic pthread stacks (ms)" int "Delay for reclaiming dynamic pthread stacks (ms)"
@ -27,6 +63,54 @@ config PTHREAD_RECYCLER_DELAY_MS
Note: this option should be considered temporary and will likely be Note: this option should be considered temporary and will likely be
removed once a more synchronous solution is available. removed once a more synchronous solution is available.
config POSIX_THREAD_ATTR_STACKADDR
bool "Support getting and setting POSIX thread stack addresses"
default y
help
Enable this option to use pthread_attr_getstackaddr() and
pthread_attr_setstackaddr().
This option was removed in IEEE 1003.1-2017 in favour of
pthread_attr_getstack() and pthread_attr_setstack().
For more information, please see
https://pubs.opengroup.org/onlinepubs/009696799/functions/pthread_attr_getstackaddr.html
https://pubs.opengroup.org/onlinepubs/9699919799/xrat/V4_xsh_chap03.html
https://pubs.opengroup.org/onlinepubs/9699919799/functions/V2_chap02.html#tag_15_09_08
config POSIX_THREAD_ATTR_STACKSIZE
bool "Support getting and setting POSIX thread stack sizes"
default y
help
Enable this option to use pthread_attr_getstacksize() or
pthread_attr_setstacksize().
For more information, please see
https://pubs.opengroup.org/onlinepubs/009696699/functions/pthread_attr_getstacksize.html
config POSIX_THREADS_EXT
bool "Extended POSIX thread support"
default y
help
Enable this option to use pthread_attr_getguardsize(), pthread_attr_setguardsize(),
pthread_mutexattr_gettype(), or pthread_mutexattr_settype().
For more information, please see
https://pubs.opengroup.org/onlinepubs/9699919799/xrat/V4_subprofiles.html
config POSIX_THREAD_PRIORITY_SCHEDULING
bool "Run POSIX threads with different priorities and schedulers"
default y
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
config POSIX_PTHREAD_ATTR_STACKSIZE_BITS config POSIX_PTHREAD_ATTR_STACKSIZE_BITS
int "Significant bits for pthread_attr_t stacksize" int "Significant bits for pthread_attr_t stacksize"
range 8 31 range 8 31
@ -59,4 +143,50 @@ config POSIX_PTHREAD_ATTR_GUARDSIZE_DEFAULT
facilitate a more dynamic approach to guard areas (via software or facilitate a more dynamic approach to guard areas (via software or
hardware) but for now it simply increases the size of thread stacks. hardware) but for now it simply increases the size of thread stacks.
endif config POSIX_THREAD_PRIO_INHERIT
bool "POSIX mutex priority inheritance"
default y
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
config POSIX_THREAD_PRIO_PROTECT
bool "POSIX mutex priority protection"
default y
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
config POSIX_THREAD_SAFE_FUNCTIONS
bool "POSIX thread-safe functions"
default y
help
Select 'y' here to enable POSIX thread-safe functions including asctime_r(), ctime_r(),
flockfile(), ftrylockfile(), funlockfile(), getc_unlocked(), getchar_unlocked(),
getgrgid_r(), getgrnam_r(), getpwnam_r(), getpwuid_r(), gmtime_r(), localtime_r(),
putc_unlocked(), putchar_unlocked(), rand_r(), readdir_r(), strerror_r(), and strtok_r().
For more information, please see
https://pubs.opengroup.org/onlinepubs/9699919799/xrat/V4_xsh_chap02.html#tag_22_02_09_07
module = PTHREAD
module-str = POSIX thread
source "subsys/logging/Kconfig.template.log_config"
module = PTHREAD_MUTEX
module-str = POSIX mutex
source "subsys/logging/Kconfig.template.log_config"
module = PTHREAD_COND
module-str = POSIX condition variable
source "subsys/logging/Kconfig.template.log_config"
module = PTHREAD_KEY
module-str = POSIX thread-specific data
source "subsys/logging/Kconfig.template.log_config"
endif # POSIX_THREADS

View file

@ -4,8 +4,8 @@
config POSIX_PRIORITY_SCHEDULING config POSIX_PRIORITY_SCHEDULING
bool "Priority scheduling" bool "Priority scheduling"
default y if PTHREAD default y if POSIX_THREADS
default y if POSIX_API default y if POSIX_API
depends on PTHREAD depends on POSIX_THREADS
help help
This enables POSIX scheduling APIs (_POSIX_PRIORITY_SCHEDULING). This enables POSIX scheduling APIs (_POSIX_PRIORITY_SCHEDULING).

View file

@ -1,29 +0,0 @@
# Copyright (c) 2023 Meta
#
# SPDX-License-Identifier: Apache-2.0
rsource "Kconfig.template.with_url"
# Not user configurable (i.e. private for now)
menuconfig $(TYPE)
bool "$(type) support"
depends on PTHREAD_IPC
default y
help
Support for $(TYPE)
For more info, see
$(posix-url-base)/$(type-function).html
if $(TYPE)
# eventually, this size should be defaulted to 0
config MAX_$(TYPE)_COUNT
int "Maximum number of $(type)"
default 5
depends on $(TYPE)
help
Maximum simultaneously active $(type) in a POSIX application.
rsource "Kconfig.template.with_logging"
endif # $(TYPE)

View file

@ -1,25 +0,0 @@
# Copyright (c) 2023 Meta
#
# SPDX-License-Identifier: Apache-2.0
rsource "Kconfig.template.with_url"
# This is mainly for TIMER currently.
menuconfig $(TYPE)
bool "$(type) support"
help
For more info, see
$(posix-url-base)/$(type-function).html
if $(TYPE)
# eventually, this size should be defaulted to 0 as a safe value
config MAX_$(TYPE)_COUNT
int "Maximum number of $(type)"
default 5
help
Maximum simultaneously active $(type) in a POSIX application.
rsource "Kconfig.template.with_logging"
endif # $(TYPE)

View file

@ -1,7 +0,0 @@
# Copyright (c) 2023 Meta
#
# SPDX-License-Identifier: Apache-2.0
module = $(TYPE)
module-str = $(TYPE) logging
source "subsys/logging/Kconfig.template.log_config"

View file

@ -1,5 +0,0 @@
# Copyright (c) 2023 Meta
#
# SPDX-License-Identifier: Apache-2.0
posix-url-base = https://pubs.opengroup.org/onlinepubs/9699919799

View file

@ -36,4 +36,14 @@ config XSI_SYSTEM_LOGGING
For more information, please see For more information, please see
https://pubs.opengroup.org/onlinepubs/9699919799/xrat/V4_subprofiles.html https://pubs.opengroup.org/onlinepubs/9699919799/xrat/V4_subprofiles.html
config XSI_THREADS_EXT
bool "X/Open threads extensions"
default y if POSIX_API
help
This option provides support for pthread_attr_getstack(), pthread_attr_setstack(),
pthread_getconcurrency(), and pthread_setconcurrency().
For more information, please see
https://pubs.opengroup.org/onlinepubs/9699919799/xrat/V4_subprofiles.html
endmenu endmenu

View file

@ -29,11 +29,11 @@ static struct k_spinlock pthread_key_lock;
* perspective of the application). With a linear space, this means that * perspective of the application). With a linear space, this means that
* the theoretical pthread_key_t range is [0,2147483647]. * the theoretical pthread_key_t range is [0,2147483647].
*/ */
BUILD_ASSERT(CONFIG_MAX_PTHREAD_KEY_COUNT < PTHREAD_OBJ_MASK_INIT, BUILD_ASSERT(CONFIG_POSIX_THREAD_KEYS_MAX < PTHREAD_OBJ_MASK_INIT,
"CONFIG_MAX_PTHREAD_KEY_COUNT is too high"); "CONFIG_MAX_PTHREAD_KEY_COUNT is too high");
static pthread_key_obj posix_key_pool[CONFIG_MAX_PTHREAD_KEY_COUNT]; static pthread_key_obj posix_key_pool[CONFIG_POSIX_THREAD_KEYS_MAX];
SYS_BITARRAY_DEFINE_STATIC(posix_key_bitarray, CONFIG_MAX_PTHREAD_KEY_COUNT); SYS_BITARRAY_DEFINE_STATIC(posix_key_bitarray, CONFIG_POSIX_THREAD_KEYS_MAX);
static inline size_t posix_key_to_offset(pthread_key_obj *k) static inline size_t posix_key_to_offset(pthread_key_obj *k)
{ {

View file

@ -86,7 +86,7 @@ static sys_dlist_t posix_thread_q[] = {
SYS_DLIST_STATIC_INIT(&posix_thread_q[POSIX_THREAD_RUN_Q]), SYS_DLIST_STATIC_INIT(&posix_thread_q[POSIX_THREAD_RUN_Q]),
SYS_DLIST_STATIC_INIT(&posix_thread_q[POSIX_THREAD_DONE_Q]), SYS_DLIST_STATIC_INIT(&posix_thread_q[POSIX_THREAD_DONE_Q]),
}; };
static struct posix_thread posix_thread_pool[CONFIG_MAX_PTHREAD_COUNT]; static struct posix_thread posix_thread_pool[CONFIG_POSIX_THREAD_THREADS_MAX];
static struct k_spinlock pthread_pool_lock; static struct k_spinlock pthread_pool_lock;
static int pthread_concurrency; static int pthread_concurrency;
@ -123,8 +123,8 @@ static inline enum posix_thread_qid posix_thread_q_get(struct posix_thread *t)
* perspective of the application). With a linear space, this means that * perspective of the application). With a linear space, this means that
* the theoretical pthread_t range is [0,2147483647]. * the theoretical pthread_t range is [0,2147483647].
*/ */
BUILD_ASSERT(CONFIG_MAX_PTHREAD_COUNT < PTHREAD_OBJ_MASK_INIT, BUILD_ASSERT(CONFIG_POSIX_THREAD_THREADS_MAX < PTHREAD_OBJ_MASK_INIT,
"CONFIG_MAX_PTHREAD_COUNT is too high"); "CONFIG_POSIX_THREAD_THREADS_MAX is too high");
static inline size_t posix_thread_to_offset(struct posix_thread *t) static inline size_t posix_thread_to_offset(struct posix_thread *t)
{ {
@ -148,7 +148,7 @@ struct posix_thread *to_posix_thread(pthread_t pthread)
return NULL; return NULL;
} }
if (bit >= CONFIG_MAX_PTHREAD_COUNT) { if (bit >= ARRAY_SIZE(posix_thread_pool)) {
LOG_DBG("Invalid pthread (%x)", pthread); LOG_DBG("Invalid pthread (%x)", pthread);
return NULL; return NULL;
} }
@ -252,8 +252,8 @@ void __z_pthread_cleanup_pop(int execute)
static bool is_posix_policy_prio_valid(int priority, int policy) static bool is_posix_policy_prio_valid(int priority, int policy)
{ {
if (priority >= sched_get_priority_min(policy) && if (priority >= posix_sched_priority_min(policy) &&
priority <= sched_get_priority_max(policy)) { priority <= posix_sched_priority_max(policy)) {
return true; return true;
} }
@ -879,7 +879,7 @@ int pthread_setschedprio(pthread_t thread, int prio)
int ret; int ret;
int new_prio = K_LOWEST_APPLICATION_THREAD_PRIO; int new_prio = K_LOWEST_APPLICATION_THREAD_PRIO;
struct posix_thread *t = NULL; struct posix_thread *t = NULL;
int policy; int policy = -1;
struct sched_param param; struct sched_param param;
ret = pthread_getschedparam(thread, &policy, &param); ret = pthread_getschedparam(thread, &policy, &param);
@ -1375,7 +1375,7 @@ int pthread_setname_np(pthread_t thread, const char *name)
k_tid_t kthread; k_tid_t kthread;
thread = get_posix_thread_idx(thread); thread = get_posix_thread_idx(thread);
if (thread >= CONFIG_MAX_PTHREAD_COUNT) { if (thread >= ARRAY_SIZE(posix_thread_pool)) {
return ESRCH; return ESRCH;
} }
@ -1399,7 +1399,7 @@ int pthread_getname_np(pthread_t thread, char *name, size_t len)
k_tid_t kthread; k_tid_t kthread;
thread = get_posix_thread_idx(thread); thread = get_posix_thread_idx(thread);
if (thread >= CONFIG_MAX_PTHREAD_COUNT) { if (thread >= ARRAY_SIZE(posix_thread_pool)) {
return ESRCH; return ESRCH;
} }
@ -1474,10 +1474,8 @@ int pthread_sigmask(int how, const sigset_t *ZRESTRICT set, sigset_t *ZRESTRICT
static int posix_thread_pool_init(void) static int posix_thread_pool_init(void)
{ {
size_t i; ARRAY_FOR_EACH_PTR(posix_thread_pool, th) {
posix_thread_q_set(th, POSIX_THREAD_READY_Q);
for (i = 0; i < CONFIG_MAX_PTHREAD_COUNT; ++i) {
posix_thread_q_set(&posix_thread_pool[i], POSIX_THREAD_READY_Q);
} }
return 0; return 0;

View file

@ -7,6 +7,7 @@
#ifndef ZEPHYR_LIB_POSIX_POSIX_PTHREAD_SCHED_H_ #ifndef ZEPHYR_LIB_POSIX_POSIX_PTHREAD_SCHED_H_
#define ZEPHYR_LIB_POSIX_POSIX_PTHREAD_SCHED_H_ #define ZEPHYR_LIB_POSIX_POSIX_PTHREAD_SCHED_H_
#include <errno.h>
#include <stdbool.h> #include <stdbool.h>
#include <zephyr/posix/sched.h> #include <zephyr/posix/sched.h>
@ -16,4 +17,27 @@ static inline bool valid_posix_policy(int policy)
return policy == SCHED_FIFO || policy == SCHED_RR || policy == SCHED_OTHER; return policy == SCHED_FIFO || policy == SCHED_RR || policy == SCHED_OTHER;
} }
static inline int posix_sched_priority_min(int policy)
{
if (!valid_posix_policy(policy)) {
errno = EINVAL;
return -1;
}
return 0;
}
static inline int posix_sched_priority_max(int policy)
{
if (IS_ENABLED(CONFIG_COOP_ENABLED) && policy == SCHED_FIFO) {
return CONFIG_NUM_COOP_PRIORITIES - 1;
} else if (IS_ENABLED(CONFIG_PREEMPT_ENABLED) &&
(policy == SCHED_RR || policy == SCHED_OTHER)) {
return CONFIG_NUM_PREEMPT_PRIORITIES - 1;
}
errno = EINVAL;
return -1;
}
#endif #endif

View file

@ -12,7 +12,7 @@
#include <zephyr/posix/pthread.h> #include <zephyr/posix/pthread.h>
#include <zephyr/sys/bitarray.h> #include <zephyr/sys/bitarray.h>
#define CONCURRENT_READER_LIMIT (CONFIG_MAX_PTHREAD_COUNT + 1) #define CONCURRENT_READER_LIMIT (CONFIG_POSIX_THREAD_THREADS_MAX + 1)
struct posix_rwlock { struct posix_rwlock {
struct k_sem rd_sem; struct k_sem rd_sem;

View file

@ -16,12 +16,7 @@
*/ */
int sched_get_priority_min(int policy) int sched_get_priority_min(int policy)
{ {
if (!valid_posix_policy(policy)) { return posix_sched_priority_min(policy);
errno = EINVAL;
return -1;
}
return 0;
} }
/** /**
@ -31,15 +26,7 @@ int sched_get_priority_min(int policy)
*/ */
int sched_get_priority_max(int policy) int sched_get_priority_max(int policy)
{ {
if (IS_ENABLED(CONFIG_COOP_ENABLED) && policy == SCHED_FIFO) { return posix_sched_priority_max(policy);
return CONFIG_NUM_COOP_PRIORITIES - 1;
} else if (IS_ENABLED(CONFIG_PREEMPT_ENABLED) &&
(policy == SCHED_RR || policy == SCHED_OTHER)) {
return CONFIG_NUM_PREEMPT_PRIORITIES - 1;
}
errno = EINVAL;
return -1;
} }
/** /**

View file

@ -8,7 +8,6 @@
#include <ksched.h> #include <ksched.h>
#include <zephyr/posix/time.h> #include <zephyr/posix/time.h>
#ifdef CONFIG_POSIX_TIMERS
int64_t timespec_to_timeoutms(const struct timespec *abstime) int64_t timespec_to_timeoutms(const struct timespec *abstime)
{ {
int64_t milli_secs, secs, nsecs; int64_t milli_secs, secs, nsecs;
@ -30,4 +29,3 @@ int64_t timespec_to_timeoutms(const struct timespec *abstime)
return milli_secs; return milli_secs;
} }
#endif /* CONFIG_POSIX_TIMERS */

View file

@ -7,14 +7,14 @@ config HAS_CC3220SDK
# SimpleLink drivers require types (stdint.h) from c library which is not # SimpleLink drivers require types (stdint.h) from c library which is not
# provided by minimal lbc # provided by minimal lbc
# Selecting ERRNO lets host driver use Zephyr's __errno # Selecting ERRNO lets host driver use Zephyr's __errno
# Selecting PTHREAD_IPC and POSIX_API are needed to build the host driver # Selecting POSIX_THREADS and POSIX_API are needed to build the host driver
config SIMPLELINK_HOST_DRIVER config SIMPLELINK_HOST_DRIVER
bool "Build the SimpleLink WiFi Host Driver" bool "Build the SimpleLink WiFi Host Driver"
depends on HAS_CC3220SDK depends on HAS_CC3220SDK
depends on MULTITHREADING depends on MULTITHREADING
select REQUIRES_FULL_LIBC select REQUIRES_FULL_LIBC
select ERRNO select ERRNO
select PTHREAD_IPC select POSIX_THREADS
select POSIX_TIMERS select POSIX_TIMERS
help help
Build the SimpleLink host driver Build the SimpleLink host driver

View file

@ -6,7 +6,7 @@ CONFIG_THREAD_STACK_INFO=y
CONFIG_DYNAMIC_THREAD=y CONFIG_DYNAMIC_THREAD=y
CONFIG_DYNAMIC_THREAD_POOL_SIZE=6 CONFIG_DYNAMIC_THREAD_POOL_SIZE=6
CONFIG_MAX_PTHREAD_COUNT=6 CONFIG_POSIX_THREAD_THREADS_MAX=6
CONFIG_MAX_PTHREAD_MUTEX_COUNT=6 CONFIG_MAX_PTHREAD_MUTEX_COUNT=6
#Enable thread awareness for debugging tools supporting it #Enable thread awareness for debugging tools supporting it

View file

@ -21,12 +21,12 @@
#define MAX_NAME_LEN 1 #define MAX_NAME_LEN 1
#endif #endif
#define NUM_PHIL CONFIG_MAX_PTHREAD_COUNT #define NUM_PHIL CONFIG_POSIX_THREAD_THREADS_MAX
#define obj_init_type "POSIX" #define obj_init_type "POSIX"
#define fork_type_str "mutexes" #define fork_type_str "mutexes"
BUILD_ASSERT(CONFIG_MAX_PTHREAD_COUNT == CONFIG_MAX_PTHREAD_MUTEX_COUNT); BUILD_ASSERT(CONFIG_POSIX_THREAD_THREADS_MAX == CONFIG_MAX_PTHREAD_MUTEX_COUNT);
BUILD_ASSERT(CONFIG_DYNAMIC_THREAD_POOL_SIZE == CONFIG_MAX_PTHREAD_COUNT); BUILD_ASSERT(CONFIG_DYNAMIC_THREAD_POOL_SIZE == CONFIG_POSIX_THREAD_THREADS_MAX);
typedef pthread_mutex_t *fork_t; typedef pthread_mutex_t *fork_t;

View file

@ -1,6 +1,5 @@
CONFIG_PTHREAD_IPC=y
CONFIG_POSIX_API=y CONFIG_POSIX_API=y
CONFIG_MAX_PTHREAD_COUNT=6 CONFIG_POSIX_THREAD_THREADS_MAX=6
CONFIG_ZTEST=y CONFIG_ZTEST=y
CONFIG_POSIX_SEM_VALUE_MAX=32767 CONFIG_POSIX_SEM_VALUE_MAX=32767
CONFIG_POSIX_MESSAGE_PASSING=y CONFIG_POSIX_MESSAGE_PASSING=y

View file

@ -117,7 +117,7 @@ ZTEST(key, test_key_resource_leak)
{ {
pthread_key_t key; pthread_key_t key;
for (size_t i = 0; i < CONFIG_MAX_PTHREAD_KEY_COUNT; ++i) { for (size_t i = 0; i < CONFIG_POSIX_THREAD_KEYS_MAX; ++i) {
zassert_ok(pthread_key_create(&key, NULL), "failed to create key %zu", i); zassert_ok(pthread_key_create(&key, NULL), "failed to create key %zu", i);
zassert_ok(pthread_key_delete(key), "failed to delete key %zu", i); zassert_ok(pthread_key_delete(key), "failed to delete key %zu", i);
} }
@ -126,8 +126,8 @@ ZTEST(key, test_key_resource_leak)
ZTEST(key, test_correct_key_is_deleted) ZTEST(key, test_correct_key_is_deleted)
{ {
pthread_key_t key; pthread_key_t key;
size_t j = CONFIG_MAX_PTHREAD_KEY_COUNT - 1; size_t j = CONFIG_POSIX_THREAD_KEYS_MAX - 1;
pthread_key_t keys[CONFIG_MAX_PTHREAD_KEY_COUNT]; pthread_key_t keys[CONFIG_POSIX_THREAD_KEYS_MAX];
for (size_t i = 0; i < ARRAY_SIZE(keys); ++i) { for (size_t i = 0; i < ARRAY_SIZE(keys); ++i) {
zassert_ok(pthread_key_create(&keys[i], NULL), "failed to create key %zu", i); zassert_ok(pthread_key_create(&keys[i], NULL), "failed to create key %zu", i);

View file

@ -382,7 +382,7 @@ ZTEST(pthread, test_pthread_descriptor_leak)
pthread_t pthread1; pthread_t pthread1;
/* If we are leaking descriptors, then this loop will never complete */ /* If we are leaking descriptors, then this loop will never complete */
for (size_t i = 0; i < CONFIG_MAX_PTHREAD_COUNT * 2; ++i) { for (size_t i = 0; i < CONFIG_POSIX_THREAD_THREADS_MAX * 2; ++i) {
zassert_ok(pthread_create(&pthread1, NULL, create_thread1, NULL), zassert_ok(pthread_create(&pthread1, NULL, create_thread1, NULL),
"unable to create thread %zu", i); "unable to create thread %zu", i);
zassert_ok(pthread_join(pthread1, NULL), "unable to join thread %zu", i); zassert_ok(pthread_join(pthread1, NULL), "unable to join thread %zu", i);

View file

@ -22,7 +22,7 @@ ZTEST(posix_apis, test_posix_sysconf)
/* SC that value depends on target's configuration */ /* SC that value depends on target's configuration */
ret = sysconf(_SC_SEMAPHORES); ret = sysconf(_SC_SEMAPHORES);
if (IS_ENABLED(CONFIG_PTHREAD_IPC)) { if (IS_ENABLED(CONFIG_POSIX_THREADS)) {
zassert_equal(ret, zassert_equal(ret,
_POSIX_VERSION, _POSIX_VERSION,
"sysconf returned unexpected value %d", "sysconf returned unexpected value %d",

View file

@ -14,7 +14,7 @@ CONFIG_NETWORKING=y
CONFIG_NET_SOCKETPAIR=y CONFIG_NET_SOCKETPAIR=y
# for when CONFIG_POSIX_API is not selected # for when CONFIG_POSIX_API is not selected
CONFIG_PTHREAD_IPC=y CONFIG_POSIX_THREADS=y
CONFIG_POSIX_FILE_SYSTEM=y CONFIG_POSIX_FILE_SYSTEM=y
CONFIG_POSIX_TIMERS=y CONFIG_POSIX_TIMERS=y
CONFIG_POSIX_MESSAGE_PASSING=y CONFIG_POSIX_MESSAGE_PASSING=y

View file

@ -21,7 +21,7 @@
#endif #endif
/* 32 threads is mainly a limitation of find_lsb_set() */ /* 32 threads is mainly a limitation of find_lsb_set() */
#define NUM_THREADS MIN(32, MIN(CONFIG_TEST_NUM_CPUS, CONFIG_MAX_PTHREAD_COUNT)) #define NUM_THREADS MIN(32, MIN(CONFIG_TEST_NUM_CPUS, CONFIG_POSIX_THREAD_THREADS_MAX))
typedef int (*create_fn)(int i); typedef int (*create_fn)(int i);
typedef int (*join_fn)(int i); typedef int (*join_fn)(int i);