Skip to content

Commit 582c983

Browse files
cfriedtkartben
authored andcommitted
kernel: revise doc for k_thread_stack_alloc and k_thread_create
Update the kernel API doxygen for k_thread_stack_alloc() and k_thread_create() to convey that kernel thread stacks may be dynamically allocated as an alternative to static allocation. Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
1 parent 50e3609 commit 582c983

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

include/zephyr/kernel.h

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -332,16 +332,22 @@ void k_thread_foreach_unlocked_filter_by_cpu(unsigned int cpu,
332332
/**
333333
* @brief Dynamically allocate a thread stack.
334334
*
335+
* Dynamically allocate a thread stack either from a pool of thread stacks of size
336+
* @kconfig{CONFIG_DYNAMIC_THREAD_POOL_SIZE}, or from the system heap. Order is determined by the
337+
* kconfig{CONFIG_DYNAMIC_THREAD_PREFER_ALLOC} and @kconfig{CONFIG_DYNAMIC_THREAD_PREFER_POOL}
338+
* options. Thread stacks from the pool are of maximum size
339+
* @kconfig{CONFIG_DYNAMIC_THREAD_STACK_SIZE}.
340+
*
335341
* Relevant stack creation flags include:
336-
* - @ref K_USER allocate a userspace thread (requires `CONFIG_USERSPACE=y`)
342+
* - @ref K_USER allocate a userspace thread (requires @kconfig{CONFIG_USERSPACE})
337343
*
338344
* @param size Stack size in bytes.
339345
* @param flags Stack creation flags, or 0.
340346
*
341347
* @retval the allocated thread stack on success.
342348
* @retval NULL on failure.
343349
*
344-
* @see CONFIG_DYNAMIC_THREAD
350+
* @see @kconfig{CONFIG_DYNAMIC_THREAD}
345351
*/
346352
__syscall k_thread_stack_t *k_thread_stack_alloc(size_t size, int flags);
347353

@@ -355,7 +361,7 @@ __syscall k_thread_stack_t *k_thread_stack_alloc(size_t size, int flags);
355361
* @retval -EINVAL if @p stack is invalid.
356362
* @retval -ENOSYS if dynamic thread stack allocation is disabled
357363
*
358-
* @see CONFIG_DYNAMIC_THREAD
364+
* @see @kconfig{CONFIG_DYNAMIC_THREAD}
359365
*/
360366
__syscall int k_thread_stack_free(k_thread_stack_t *stack);
361367

@@ -373,7 +379,7 @@ __syscall int k_thread_stack_free(k_thread_stack_t *stack);
373379
* K_FP_REGS, and K_SSE_REGS. Multiple options may be specified by separating
374380
* them using "|" (the logical OR operator).
375381
*
376-
* Stack objects passed to this function must be originally defined with
382+
* Stack objects passed to this function may be statically allocated with
377383
* either of these macros in order to be portable:
378384
*
379385
* - K_THREAD_STACK_DEFINE() - For stacks that may support either user or
@@ -382,6 +388,10 @@ __syscall int k_thread_stack_free(k_thread_stack_t *stack);
382388
* threads only. These stacks use less memory if CONFIG_USERSPACE is
383389
* enabled.
384390
*
391+
* Alternatively, the stack may be dynamically allocated using
392+
* @ref k_thread_stack_alloc. If this is the case, then the stack should
393+
* be freed using @ref k_thread_stack_free after joining the thread.
394+
*
385395
* The stack_size parameter has constraints. It must either be:
386396
*
387397
* - The original size value passed to K_THREAD_STACK_DEFINE() or

0 commit comments

Comments
 (0)