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 {
|
impl NonMutableHookDataAccessor for Aspect {
|
||||||
fn access(&self, fle: &FileLockEntry) -> HookResult<()> {
|
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();
|
let accessors : Vec<HDA> = self.hooks.iter().map(|h| h.accessor()).collect();
|
||||||
if !accessors.iter().all(|a| match a { &HDA::NonMutableAccess(_) => true, _ => false }) {
|
if !accessors.iter().all(|a| match a { &HDA::NonMutableAccess(_) => true, _ => false }) {
|
||||||
unimplemented!()
|
unimplemented!()
|
||||||
}
|
}
|
||||||
|
|
||||||
for accessor in accessors {
|
let threads : Vec<HookResult<()>> = accessors
|
||||||
match accessor {
|
.iter()
|
||||||
HDA::NonMutableAccess(accessor) => try!(accessor.access(fle)),
|
.map(|accessor| {
|
||||||
_ => unreachable!(),
|
crossbeam::scope(|scope| {
|
||||||
}
|
scope.spawn(|| {
|
||||||
}
|
match accessor {
|
||||||
Ok(())
|
&HDA::NonMutableAccess(accessor) => accessor.access(fle),
|
||||||
|
_ => 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))
|
||||||
|
})
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue