From 2f792a9c88c44b0decd25a3d6f92c85abe003f2b Mon Sep 17 00:00:00 2001 From: Marc Emmers Date: Tue, 4 Dec 2018 11:31:20 +0100 Subject: [PATCH] Added get_name function to ThisThread namespace --- rtos/ThisThread.cpp | 9 +++++++++ rtos/ThisThread.h | 6 ++++++ 2 files changed, 15 insertions(+) diff --git a/rtos/ThisThread.cpp b/rtos/ThisThread.cpp index 1ddbfe57ae..0e3b89d431 100644 --- a/rtos/ThisThread.cpp +++ b/rtos/ThisThread.cpp @@ -138,4 +138,13 @@ osThreadId_t ThisThread::get_id() return osThreadGetId(); } +const char *get_name() +{ + osThreadId_t id = osThreadGetId(); + if (id == NULL) { + return NULL; + } + return osThreadGetName(id); +} + } diff --git a/rtos/ThisThread.h b/rtos/ThisThread.h index c0104fc1e0..33a2036e0b 100644 --- a/rtos/ThisThread.h +++ b/rtos/ThisThread.h @@ -179,6 +179,12 @@ void yield(); */ osThreadId_t get_id(); +/** Get the thread name of the current running thread. + @return thread name pointer or NULL if thread has no name or in case of error. + @note You cannot call this function from ISR context. +*/ +const char *get_name(); + }; /** @}*/ /** @}*/