Skip to content

Commit 0fbc10f

Browse files
committed
core/thread: introduce THREAD_CREATE_NO_STACKTEST
1 parent 312a550 commit 0fbc10f

2 files changed

Lines changed: 27 additions & 12 deletions

File tree

core/include/thread.h

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,11 @@
4343
* In addition to the priority, flags can be used when creating a thread to
4444
* alter the thread's behavior after creation. The following flags are available:
4545
*
46-
* Flags | Description
47-
* ----------------------------- | --------------------------------------------------
48-
* @ref THREAD_CREATE_SLEEPING | the thread will sleep until woken up manually
49-
* @ref THREAD_CREATE_WOUT_YIELD | the thread might not run immediately after creation
46+
* Flags | Description
47+
* ------------------------------ | --------------------------------------------------
48+
* @ref THREAD_CREATE_SLEEPING | the thread will sleep until woken up manually
49+
* @ref THREAD_CREATE_WOUT_YIELD | the thread might not run immediately after creation
50+
* @ref THREAD_CREATE_NO_STACKTEST| never measure the stack's memory usage
5051
*
5152
* Thread creation
5253
* ===============
@@ -229,6 +230,13 @@ struct _thread {
229230
*/
230231
#define THREAD_CREATE_WOUT_YIELD (4)
231232

233+
/**
234+
* @brief Never write markers into the thread's stack to measure stack usage
235+
*
236+
* This flag is ignored when DEVELHELP or SCHED_TEST_STACK is not enabled
237+
*/
238+
#define THREAD_CREATE_NO_STACKTEST (8)
239+
232240
/**
233241
* @brief Legacy flag kept for compatibility.
234242
*

core/thread.c

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -265,14 +265,21 @@ kernel_pid_t thread_create(char *stack, int stacksize, uint8_t priority,
265265

266266
#if defined(DEVELHELP) || defined(SCHED_TEST_STACK) \
267267
|| defined(MODULE_TEST_UTILS_PRINT_STACK_USAGE)
268-
/* assign each int of the stack the value of it's address. Alignment
269-
* has been handled above, so silence -Wcast-align */
270-
uintptr_t *stackmax = (uintptr_t *)(uintptr_t)(stack + stacksize);
271-
uintptr_t *stackp = (uintptr_t *)(uintptr_t)stack;
272-
273-
while (stackp < stackmax) {
274-
*stackp = (uintptr_t)stackp;
275-
stackp++;
268+
if (flags & THREAD_CREATE_NO_STACKTEST) {
269+
/* create stack guard. Alignment has been handled above, so silence
270+
* -Wcast-align */
271+
*(uintptr_t *)(uintptr_t)stack = (uintptr_t)stack;
272+
}
273+
else {
274+
/* assign each int of the stack the value of it's address. Alignment
275+
* has been handled above, so silence -Wcast-align */
276+
uintptr_t *stackmax = (uintptr_t *)(uintptr_t)(stack + stacksize);
277+
uintptr_t *stackp = (uintptr_t *)(uintptr_t)stack;
278+
279+
while (stackp < stackmax) {
280+
*stackp = (uintptr_t)stackp;
281+
stackp++;
282+
}
276283
}
277284
#endif
278285

0 commit comments

Comments
 (0)