-
Notifications
You must be signed in to change notification settings - Fork 220
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 atomic crossbeam structure to add interior mutability to common::Errors #255
Conversation
cc @Xaeroxe @omni-viral @ebkalderon This should also improve performance for Amethyst in the future, and is the same strategy we should use for events in case we want to implement them as described in amethyst/amethyst#229 |
@torkleyy I believe that crossbeam's
Of course the fact it is optional is a good thing. |
@omni-viral I don't think so, but the bigger problem I have with fn run(..) {
let x = errors.execute(|| {
let val = do_something_that_can_fail()?;
val + 5
});
ints.insert(entity, x);
} Just look at these systems used in an actual game built with Specs: https://github.com/agmcleod/ld39/tree/master/src/systems None of them needs |
The difference here is also that the crossbeam structure only does something if errors get pushed, but the collecting of |
The good reason I often forget about 😄 |
@omni-viral So can I take this as an approval? |
src/common.rs
Outdated
} | ||
|
||
/// Collect all errors into a `Vec`. | ||
pub fn collect(&mut self) -> Vec<BoxedErr> { |
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.
Maybe it is better to return draining iterator instead?
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.
Crossbeam doesn't offer that, but I could still implement it in this module.
src/common.rs
Outdated
/// Collect all errors into a `Vec`. | ||
pub fn collect(&mut self) -> Vec<BoxedErr> { | ||
let mut errors = Vec::new(); | ||
while let Some(e) = self.errors.try_pop() { |
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.
Isn't there a method to pop all queue at once?
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.
No.
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'll take a look if it may be added 😄
…Errors Add methods * collect * drain * pop_err * has_error
@omni-viral Done. |
Merging this now, as this is blocking me atm. bors r+ |
Build succeeded |
Great! |
This allows fetching
Errors
without limiting concurrency.