-
Notifications
You must be signed in to change notification settings - Fork 3k
Add ThisThread namespace and deprecate static Thread methods #7872
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
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.
Looks very good. I'm a bit worried about naming conventions for namespace: on one hand we got mbed
, event
and rtos
and on the other we have Kernel
and ThisThread
.
rtos/ThisThread.h
Outdated
|
||
/** Returns the Thread Flags currently set for the currently running thread. | ||
@return current thread flags or 0 if not in a valid thread. | ||
@note You may call this function from 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.
That's a bit strange to call this function from ISR; even if it is legal.
More generally this pack of function are not meant to be called from 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.
Actually it isn't legal, according to docs.
The RTX implementation of osThreadFlagsGet
does return 0 without error if in ISR context, but the CMSIS-RTOS 2.1.2 documentation says it can't be called from interrupt context. Will modify.
rtos/ThisThread.h
Outdated
*/ | ||
namespace ThisThread { | ||
/** Clears the specified Thread Flags of the currently running thread. | ||
@param flags specifies the thread flags of the thread that should be cleared. |
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.
of the thread may be redundant.
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.
Made it "flags of the thread", matching CMSIS-RTOS 2 doc wording. Still feels a bit wonky for something acting only on current thread, but it matches the wording of Thread::flags_set
/ osThreadFlagsSet
, either intentionally or by copy-and-paste.
#include "mbed_assert.h" | ||
|
||
namespace rtos { | ||
|
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.
Would it be possible to enclose function implementations into a namespace. With the prefix it looks like a member function implementation.
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.
That was intentional because that's how I was mainly expecting them to be used - as if they were static member functions. So people are likely to be searching for ThisThread::sleep_for
, having seen it in code.
Does that make sense?
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.
Looks good 👍
Please review the astyle job (fix them). |
I think there's a reasonable distinction to be made.
C++11 has I would say for these pseudo-static-classes the namespace is very much to be read as part of the API name, and they are normally expected to be called explicitly as |
3d5baa7
to
37433b0
Compare
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.
Thanks Kevin, it all makes sense. I've opened an issue in the docs. It would be nice to document in our guidelines what the pseudo-static-classes pattern is and what conventions it uses.
/morph build |
Build : SUCCESSBuild number : 2928 Triggering tests/morph test |
Exporter Build : SUCCESSBuild number : 2548 |
Test : FAILUREBuild number : 2679 |
Broken testcase corrected. |
/morph build |
Build : SUCCESSBuild number : 2950 Triggering tests/morph test |
Exporter Build : SUCCESSBuild number : 2566 |
Test : FAILUREBuild number : 2698 |
Seems to be a spurious failure unconnected to PR - passed in previous run. |
Correct. We're currently running Testing CI on other PRs. Will restart this PR when able to. |
/morph test |
Test : SUCCESSBuild number : 2743 |
(I believe) This changed has created some warnings.
Is someone on the case? It has also created warnings in the LoRa radio drivers but I guess no one here is interested in those! I'll open an issue there. |
Thanks for the poke. Created PR #7980 to clean up warnings. |
Description
The static methods of
Thread
have repeatedly caused confusion - while it's very clear in C thatosThreadGetId()
must be returning the current thread ID, as it takes no parameters, it's not at all obvious thatthread->gettid()
is static and will return the current thread's ID, notthread
'sRemove the confusion by
namespace ThisThread
andnamespace Kernel
,Thread::get_id()
.The distinction between
ThisThread::get_id()
andthread->get_id()
is clear, and they cannot be confused.Syntax and naming follows C++11, which has
namespace std::this_thread
and corresponding methods.Most visible change to typical code is that
Thread::wait()
(which people often use because of problems withmbed::wait()
) is deprecated in favour ofThisThread::sleep_for()
.Effectively fixes #1831
Pull request type