-
Notifications
You must be signed in to change notification settings - Fork 12
Add tokens for being in a thread #19
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
This allows locking a mutex without the overhead of a check whether code is running in thread mode. Contributes-To: #18
bcf49dd
to
dc66312
Compare
The documentation sittuation doesn't make me happy; the current head ("thread, mutex: Use a mutex-specific referenc type rather than ValueInThread") is an attempt to enhance this. It makes things only marginally better: The documentation for the "good" This could be taken a tad further by moving the Context into the Mutex, but then all of a sudden |
d8d0236
to
861c59f
Compare
I've pushed an extension to the previous approach that uses I'm rather happy with how that looks in documentation and feels in use, but I'd try it on other don't-call-in-ISR types before committing to it. |
There are currently no drivers written that test this, and anyway it'd be highly platform specific. Let's do it right when there is need for it.
On the list of "where to try this":
|
05e5944
to
122813a
Compare
122813a
to
a9afe55
Compare
Add DHT Wrapper Closes RIOT-OS#19 See merge request atacama/rust-riot-wrappers!25
Tokens for being-in-a-thread have only been a comment previously, and came to prominence through #18 and a reddit thread.
As a first demo, the tokens can be used with a Mutex when locking. This does not close #18, as the mutex function stays as it is -- but it might be deprecated, or (compatibly ... how?) changed to return a Result that the user would then need to unwrap (but does that make it better? Might it just be deprecated?).
As they work just the same, it also adds tokens for "being in an interrupt context", although there's probably not much that can be done with them (because interrupts could still be nested).
Advanced usage
More APIs should probably switch from being implemented on an X to being implemented on ValueInThread. I2C transfers come to mind.
APIs that explicitly send data between threads might want to offer ways to also transport ValueInThread. I'm not sure yet whether that's more easily achieved by allowing either trait requirement (is that possible even?), or whether they'd just transport
.into_inner()
and then use the recipient's knowledge of being in a thread to reconstitute the wrapper.Alternatives
Rather than having a single wrapper for any T that is not sent to interrupt contexts, it would be possible to have a Mutex type with generic variants (eg. const IS_IN_THREAD: bool).
The largest upside of that alternative is documentation visibility: ValueInThread<&Mutex> is documented with ValueInThread, not with Mutex.