Make hook execution parallel for StoreIdAccessor impl for Aspect
This commit is contained in:
parent
d8760c9737
commit
7102a57808
2 changed files with 31 additions and 7 deletions
|
@ -32,18 +32,41 @@ impl Aspect {
|
||||||
|
|
||||||
impl StoreIdAccessor for Aspect {
|
impl StoreIdAccessor for Aspect {
|
||||||
fn access(&self, id: &StoreId) -> HookResult<()> {
|
fn access(&self, id: &StoreId) -> HookResult<()> {
|
||||||
|
use crossbeam;
|
||||||
|
use std::thread;
|
||||||
|
use std::thread::JoinHandle;
|
||||||
|
|
||||||
|
use hook::error::HookError as HE;
|
||||||
|
use hook::error::HookErrorKind as HEK;
|
||||||
|
|
||||||
let accessors : Vec<HDA> = self.hooks.iter().map(|h| h.accessor()).collect();
|
let accessors : Vec<HDA> = self.hooks.iter().map(|h| h.accessor()).collect();
|
||||||
if !accessors.iter().all(|a| match a { &HDA::StoreIdAccess(_) => true, _ => false }) {
|
if !accessors.iter().all(|a| match a { &HDA::StoreIdAccess(_) => true, _ => false }) {
|
||||||
unimplemented!()
|
unimplemented!()
|
||||||
}
|
}
|
||||||
|
|
||||||
for accessor in accessors {
|
let threads : Vec<HookResult<()>> = accessors
|
||||||
match accessor {
|
.iter()
|
||||||
HDA::StoreIdAccess(accessor) => try!(accessor.access(id)),
|
.map(|accessor| {
|
||||||
_ => unreachable!(),
|
crossbeam::scope(|scope| {
|
||||||
}
|
scope.spawn(|| {
|
||||||
}
|
match accessor {
|
||||||
Ok(())
|
&HDA::StoreIdAccess(accessor) => accessor.access(id),
|
||||||
|
_ => unreachable!(),
|
||||||
|
}
|
||||||
|
.map_err(|e| ()) // TODO: We're losing the error cause here
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
.map(|i| i.join().map_err(|_| HE::new(HEK::HookExecutionError, None)))
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
threads
|
||||||
|
.into_iter()
|
||||||
|
.fold(Ok(()), |acc, elem| {
|
||||||
|
acc.and_then(|a| {
|
||||||
|
elem.map(|_| a).map_err(|_| HE::new(HEK::HookExecutionError, None))
|
||||||
|
})
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,7 @@ use std::convert::Into;
|
||||||
*/
|
*/
|
||||||
#[derive(Clone, Copy, Debug)]
|
#[derive(Clone, Copy, Debug)]
|
||||||
pub enum HookErrorKind {
|
pub enum HookErrorKind {
|
||||||
|
HookExecutionError,
|
||||||
Pre(PreHookErrorKind),
|
Pre(PreHookErrorKind),
|
||||||
Post(PostHookErrorKind)
|
Post(PostHookErrorKind)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue