-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ThisThread get_name() #8961
ThisThread get_name() #8961
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not totally sure about this, but I guess it's useful, and there's no other way to get the info other than going to the CMSIS-RTOS APIs.
rtos/ThisThread.h
Outdated
@note You may call this function from ISR context. | ||
*/ | ||
osThreadId_t get_id(); | ||
|
||
/** Get the thread name of the current running thread. | ||
@return thread name pointer or NULL in case of error or in ISR context. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could also be NULL if the thread has no name. (Possible in CMSIS-RTOS, even though the Thread
object likes to put in "application_unnamed_thread"
)
rtos/ThisThread.h
Outdated
@@ -174,7 +174,7 @@ void sleep_until(uint64_t millisec); | |||
void yield(); | |||
|
|||
/** Get the thread id of the current running thread. | |||
@return thread ID for reference by other functions or NULL in case of error or in ISR context. | |||
@return thread ID for reference by other functions or NULL in case of error. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You may be right here - I think it actually returns current foreground thread if called from ISR.
Wasn't inconsistent though - documenting it as returning NULL from ISR is perfectly logical.
Saying it returns NULL from ISR but then saying you can't call it from ISR would be inconsistent.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Although the new documented behaviour is maybe what you get from RTX osThreadGetId
, I don't think it's actually what we would want from ThisThread::get_id
, given the name.
Fixing implementation to match documented behaviour would be better I think. Or specifying it can't be called from ISR.
It was supposed to be a drop-in replacement for Thread::gettid()
, which never specified ISR behaviour, but said it worked. Hmm.
I misunderstood the "Cannot call" then, thinking it is possible to call but wouldn't function. Instead the functions that say they cannot be called from ISR crash? It seems to me that both osThreadGetId and osThreadGetName can be called from ISR context. Only osThreadGetName returns NULL even if the ID is valid in ISR context. It does make sense to block both get_id and get_name from being called in ISR context because there is no ThisThread if you are in ISR context. All other functions in the namespace are already blocked from ISR context so why should get_id be allowed? |
Often, yes, sometimes only enforced in a debug build. Or behaviour may be undefined.
CMSIS-RTOS 2 docs explicitly say
I wrote that, and I think I allowed it because
If it doesn't actually return |
Note that error cases in RTX call (Maybe debug build only?) |
I was looking at the cmsis_os2.h file instead of at the real docs. You're right about the osThreadGetName and I will change my comments. Noticed the EvrRtx call but didn't know that could lead to an mbed_error call, thought it was only meant to record some events. So the question remains, what to do with the get_id. |
I'd leave the get_id call to another PR. Needs separate discussion. I'd initially suggest saying it can't be called from ISR, and not enforce, so just docs change. |
@marcemmers A small astyle nit and we can get CI started. |
I still want to leave the |
a765e5d
to
2f792a9
Compare
CI started |
Test run: FAILEDSummary: 6 of 7 test jobs failed Failed test jobs:
|
CI restarted |
Test run: SUCCESSSummary: 11 of 11 test jobs passed |
Description
Added function to get the name of the current thread to ThisThread.
Comes in handy when debugging and doesn't have any impact if not used.
Pull request type