Make hook execution parallel for NonMutableHookDataAccessor impl for Aspect
This commit is contained in:
parent
7102a57808
commit
5ba260943b
1 changed files with 30 additions and 7 deletions
|
@ -89,18 +89,41 @@ impl MutableHookDataAccessor for Aspect {
|
|||
|
||||
impl NonMutableHookDataAccessor for Aspect {
|
||||
fn access(&self, fle: &FileLockEntry) -> 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();
|
||||
if !accessors.iter().all(|a| match a { &HDA::NonMutableAccess(_) => true, _ => false }) {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
for accessor in accessors {
|
||||
let threads : Vec<HookResult<()>> = accessors
|
||||
.iter()
|
||||
.map(|accessor| {
|
||||
crossbeam::scope(|scope| {
|
||||
scope.spawn(|| {
|
||||
match accessor {
|
||||
HDA::NonMutableAccess(accessor) => try!(accessor.access(fle)),
|
||||
&HDA::NonMutableAccess(accessor) => accessor.access(fle),
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
.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))
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue