-
Notifications
You must be signed in to change notification settings - Fork 5
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
Use const instead of macros #5
Use const instead of macros #5
Conversation
d685227
to
da59528
Compare
I've updated the PR with this trick which makes it possible to have a I also added an RAII mechanism instead of the |
5fffad7
to
0eac74a
Compare
This is pretty much a complete rewrite. It gives a much nicer API to understand from the documentation. It also means that it doesn't rely on \#[doc(hidden)] methods (except for `Interchange::const_new` so that it can be removed once the required compiler features are stabilized) Because everything doesn't need to be `'static` anymore, it can also be tested efficiently with Loom, ensuring that there are no possible race conditions. It is a significantly breaking change
This method doesn't make sense now with RAII
0eac74a
to
d17d2cf
Compare
I've made a branch that also removes the |
Remove the Clone bound
It would be helpful to also implement |
Isn't it already the case? |
Ah, sorry, I probably looked at the wrong branch. |
Not worried about the overhead of the atomic bools to implement the RAII, just to state the obvious though, it's not guaranteed destructors (drop) are run. Seems fine for the intended use cases. Overall, I think these are good changes, particularly adding the testing with Loom. Do we have any chance of upstreaming constness as needed to Loom, or is this a property of the implementations there? Also.. did Loom catch any bugs already? |
src/lib.rs
Outdated
/// (rq, rp) = interchange.claim().unwrap() ; | ||
/// } | ||
/// ``` | ||
pub struct Interchange<Q, A, const N: usize> { |
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.
I presume Q = query/question, and A = answer? Maybe use longer names in the struct definition (and switch to the short ones in the implementation)? In any case, please add a comment on what the names mean, so it's easier to understand.
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're right, I'm not very satisfied with Q,A since everything else mentions Request/Response. I'll replace it with Rq
and Rp
This is the implementation of It registers itself to loom's runtime so I doubt it will ever be made |
I also added an static INTERCHANGE_INNER: Interchange<Request, Response, 1> = Interchange::new();
// The size of the interchange is absent from the type
static INTERCHANGE: InterchangeRef<'static, Request, Response> = INTERCHANGE_INNER.as_interchange_ref();
let (mut rq, mut rp) = INTERCHANGE.claim().unwrap(); |
PR trussed-dev#5 ended up adding an RAII mechanism that mad the split API safe
PR #5 ended up adding an RAII mechanism that mad the split API safe
This is pretty much a complete rewrite. It gives a much nicer API to
understand from the documentation. It also means that it doesn't rely on
#[doc(hidden)] methods (except for
Interchange::const_new
so that itcan be removed once the required compiler features are stabilized)
Because everything doesn't need to be
'static
anymore, it can also betested efficiently with Loom, ensuring that there are no possible race
conditions.
It is a significantly breaking change
There may be some possible improvement. For example the
claims
mechanism could be implemented in theChannel
struct and use RAII to be made safe and remove the need forreset-claims
. This could make the API 100% safe which would be nice, but it would not be zero cost, given that it's unlikely aRequester
or aResponder
would ever be dropped in most use cases.