diff --git a/core/include/thread.h b/core/include/thread.h index e591549782..cc414c9fb7 100644 --- a/core/include/thread.h +++ b/core/include/thread.h @@ -43,10 +43,11 @@ * In addition to the priority, flags can be used when creating a thread to * alter the thread's behavior after creation. The following flags are available: * - * Flags | Description - * ----------------------------- | -------------------------------------------------- - * @ref THREAD_CREATE_SLEEPING | the thread will sleep until woken up manually - * @ref THREAD_CREATE_WOUT_YIELD | the thread might not run immediately after creation + * Flags | Description + * ------------------------------ | -------------------------------------------------- + * @ref THREAD_CREATE_SLEEPING | the thread will sleep until woken up manually + * @ref THREAD_CREATE_WOUT_YIELD | the thread might not run immediately after creation + * @ref THREAD_CREATE_NO_STACKTEST| never measure the stack's memory usage * * Thread creation * =============== @@ -229,6 +230,13 @@ struct _thread { */ #define THREAD_CREATE_WOUT_YIELD (4) +/** + * @brief Never write markers into the thread's stack to measure stack usage + * + * This flag is ignored when DEVELHELP or SCHED_TEST_STACK is not enabled + */ +#define THREAD_CREATE_NO_STACKTEST (8) + /** * @brief Legacy flag kept for compatibility. * diff --git a/core/thread.c b/core/thread.c index 189d98e730..979a95b901 100644 --- a/core/thread.c +++ b/core/thread.c @@ -265,14 +265,21 @@ kernel_pid_t thread_create(char *stack, int stacksize, uint8_t priority, #if defined(DEVELHELP) || defined(SCHED_TEST_STACK) \ || defined(MODULE_TEST_UTILS_PRINT_STACK_USAGE) - /* assign each int of the stack the value of it's address. Alignment - * has been handled above, so silence -Wcast-align */ - uintptr_t *stackmax = (uintptr_t *)(uintptr_t)(stack + stacksize); - uintptr_t *stackp = (uintptr_t *)(uintptr_t)stack; + if (flags & THREAD_CREATE_NO_STACKTEST) { + /* create stack guard. Alignment has been handled above, so silence + * -Wcast-align */ + *(uintptr_t *)(uintptr_t)stack = (uintptr_t)stack; + } + else { + /* assign each int of the stack the value of it's address. Alignment + * has been handled above, so silence -Wcast-align */ + uintptr_t *stackmax = (uintptr_t *)(uintptr_t)(stack + stacksize); + uintptr_t *stackp = (uintptr_t *)(uintptr_t)stack; - while (stackp < stackmax) { - *stackp = (uintptr_t)stackp; - stackp++; + while (stackp < stackmax) { + *stackp = (uintptr_t)stackp; + stackp++; + } } #endif