From 81608bdab5b44f3b3432153c3a28e678bcd6234b Mon Sep 17 00:00:00 2001 From: Ludwig Ortmann Date: Mon, 20 Jan 2014 10:42:59 +0100 Subject: [PATCH] thread_measure_stack_usage documentation fix documentation - the return value is the opposite of what it said add and improve comments renamed space to space_free (the name is documentation as well) --- core/include/thread.h | 2 +- core/thread.c | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/core/include/thread.h b/core/include/thread.h index 39c973703a..df771e996b 100644 --- a/core/include/thread.h +++ b/core/include/thread.h @@ -96,7 +96,7 @@ int thread_getlastpid(void); * Only works if the thread was created with the flag CREATE_STACKTEST. * * @param stack The stack you want to measure. try active_thread->stack_start. - * @return The current usage (overwritten addresses) of the thread's stack + * @return The amount of unused space of the thread's stack */ int thread_measure_stack_usage(char *stack); diff --git a/core/thread.c b/core/thread.c index 339d250306..36e004c009 100644 --- a/core/thread.c +++ b/core/thread.c @@ -113,13 +113,14 @@ int thread_measure_stack_usage(char *stack) { unsigned int *stackp = (unsigned int *)stack; - /* assumption that the comparison fails before or after end of stack */ + /* assume that the comparison fails before or after end of stack */ + /* assume that the stack grows "downwards" */ while (*stackp == (unsigned int)stackp) { stackp++; } - int space = (unsigned int)stackp - (unsigned int)stack; - return space; + int space_free = (unsigned int)stackp - (unsigned int)stack; + return space_free; } int thread_create(char *stack, int stacksize, char priority, int flags, void (*function)(void), const char *name)