1# Copyright (c) 2017 Intel Corporation
2# Copyright (c) 2023 Meta
3# Copyright (c) 2024 Tenstorrent AI ULC
4#
5# SPDX-License-Identifier: Apache-2.0
6
7menuconfig POSIX_THREADS
8	bool "POSIX thread support"
9	help
10	  Select 'y' here to enable POSIX threads, mutexes, condition variables, and thread-specific
11	  storage.
12
13	  For more information please see
14	  https://pubs.opengroup.org/onlinepubs/9699919799/xrat/V4_subprofiles.html
15
16if POSIX_THREADS
17
18config POSIX_THREAD_THREADS_MAX
19	int "Maximum number of POSIX threads"
20	default 5
21	help
22	  Maximum simultaneously active threads in a POSIX application.
23
24	  For more information, see
25	  https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/limits.h.html
26
27config MAX_PTHREAD_MUTEX_COUNT
28	int "Maximum number of POSIX mutexes"
29	default 5
30	help
31	  Maximum simultaneously active mutexes in a POSIX application.
32
33config MAX_PTHREAD_COND_COUNT
34	int "Maximum number of POSIX condition variables"
35	default 5
36	help
37	  Maximum simultaneously active condition variables in a POSIX application.
38
39config POSIX_THREAD_KEYS_MAX
40	int "Maximum number of POSIX thread-specific-storage keys"
41	default 5
42	help
43	  Maximum simultaneously active thread-specific-storage keys in a POSIX application.
44
45	  For more information, see
46	  https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/limits.h.html
47
48config PTHREAD_RECYCLER_DELAY_MS
49	int "Delay for reclaiming dynamic pthread stacks (ms)"
50	default 100
51	help
52	  Prior to a POSIX thread terminating via k_thread_abort(), scheduled
53	  work is added to the system workqueue (SWQ) so that any resources
54	  allocated by the thread (e.g. thread stack from a pool or the heap)
55	  can be released back to the system. Because resources are also freed
56	  on calls to pthread_create() there is no need to worry about resource
57	  starvation.
58
59	  This option sets the number of milliseconds by which to defer
60	  scheduled work.
61
62	  Note: this option should be considered temporary and will likely be
63	  removed once a more synchronous solution is available.
64
65config POSIX_THREAD_ATTR_STACKADDR
66	bool "Support getting and setting POSIX thread stack addresses"
67	help
68	  Enable this option to use pthread_attr_getstackaddr() and
69	  pthread_attr_setstackaddr().
70
71	  This option was removed in IEEE 1003.1-2017 in favour of
72	  pthread_attr_getstack() and pthread_attr_setstack().
73
74	  For more information, please see
75	  https://pubs.opengroup.org/onlinepubs/009696799/functions/pthread_attr_getstackaddr.html
76	  https://pubs.opengroup.org/onlinepubs/9699919799/xrat/V4_xsh_chap03.html
77	  https://pubs.opengroup.org/onlinepubs/9699919799/functions/V2_chap02.html#tag_15_09_08
78
79config POSIX_THREAD_ATTR_STACKSIZE
80	bool "Support getting and setting POSIX thread stack sizes"
81	help
82	  Enable this option to use pthread_attr_getstacksize() or
83	  pthread_attr_setstacksize().
84
85	  For more information, please see
86	  https://pubs.opengroup.org/onlinepubs/009696699/functions/pthread_attr_getstacksize.html
87
88config POSIX_THREADS_EXT
89	bool "Extended POSIX thread support"
90	help
91	  Enable this option to use pthread_attr_getguardsize(), pthread_attr_setguardsize(),
92	  pthread_mutexattr_gettype(), or pthread_mutexattr_settype().
93
94	  For more information, please see
95	  https://pubs.opengroup.org/onlinepubs/9699919799/xrat/V4_subprofiles.html
96
97config POSIX_THREAD_PRIORITY_SCHEDULING
98	bool "Run POSIX threads with different priorities and schedulers"
99	help
100	  Enabling this option allows the application to configure different priorities and
101	  scheduling algorithms for different threads via functions such as pthread_setschedparam()
102	  and pthread_setschedprio(). This is required for Realtime Threads and Advanced Realtime
103	  Threads.
104
105	  For more information, please see
106	  https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap02.html#tag_02_01_06
107	  https://man7.org/linux/man-pages/man7/posixoptions.7.html
108
109config POSIX_PTHREAD_ATTR_STACKSIZE_BITS
110	int "Significant bits for pthread_attr_t stacksize"
111	range 8 31
112	default 23
113	help
114	  This value plays a part in determining the maximum supported
115	  pthread_attr_t stacksize. Valid stacksizes are in the range
116	  [1, N], where N = 1 << M, and M is this configuration value.
117
118config POSIX_PTHREAD_ATTR_GUARDSIZE_BITS
119	int "Significant bits for pthread_attr_t guardsize"
120	range 1 31
121	default 9
122	help
123	  This value plays a part in determining the maximum supported
124	  pthread_attr_t guardsize. Valid guardsizes are in the range
125	  [0, N-1], where N = 1 << M, and M is this configuration value.
126
127	  Actual guardsize values may be rounded-up.
128
129config POSIX_PTHREAD_ATTR_GUARDSIZE_DEFAULT
130	int "Default size of stack guard area"
131	default 0
132	help
133	  This is the default amount of space to reserve at the overflow end of a
134	  pthread stack. Since Zephyr already supports both software-based stack
135	  protection (canaries) and hardware-based stack protection (MMU or MPU),
136	  this is set to 0 by default. However, a conforming application would be
137	  required to set this to PAGESIZE. Eventually, this option might
138	  facilitate a more dynamic approach to guard areas (via software or
139	  hardware) but for now it simply increases the size of thread stacks.
140
141config POSIX_THREAD_PRIO_INHERIT
142	bool "POSIX mutex priority inheritance"
143	help
144	  Select 'y' here to enable POSIX mutex priority inheritance.
145
146	  For more information, please see
147	  https://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_mutexattr_getprotocol.html
148
149config POSIX_THREAD_PRIO_PROTECT
150	bool "POSIX mutex priority protection"
151	help
152	  Select 'y' here to enable POSIX mutex priority protection.
153
154	  For more information, please see
155	  https://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_mutexattr_getprotocol.html
156
157config POSIX_THREAD_SAFE_FUNCTIONS
158	bool "POSIX thread-safe functions"
159	help
160	  Select 'y' here to enable POSIX thread-safe functions including asctime_r(), ctime_r(),
161	  flockfile(), ftrylockfile(), funlockfile(), getc_unlocked(), getchar_unlocked(),
162	  getgrgid_r(), getgrnam_r(), getpwnam_r(), getpwuid_r(), gmtime_r(), localtime_r(),
163	  putc_unlocked(), putchar_unlocked(), rand_r(), readdir_r(), strerror_r(), and strtok_r().
164
165	  For more information, please see
166	  https://pubs.opengroup.org/onlinepubs/9699919799/xrat/V4_xsh_chap02.html#tag_22_02_09_07
167
168module = PTHREAD
169module-str = POSIX thread
170source "subsys/logging/Kconfig.template.log_config"
171
172module = PTHREAD_MUTEX
173module-str = POSIX mutex
174source "subsys/logging/Kconfig.template.log_config"
175
176module = PTHREAD_COND
177module-str = POSIX condition variable
178source "subsys/logging/Kconfig.template.log_config"
179
180module = PTHREAD_KEY
181module-str = POSIX thread-specific data
182source "subsys/logging/Kconfig.template.log_config"
183
184endif # POSIX_THREADS
185