1use anyhow::anyhow;
4use cid::Cid;
5use fvm_shared::message::Message;
6use lazy_static::lazy_static;
7
8use super::{ApplyKind, ApplyRet, Executor};
9
10lazy_static! {
11 static ref EXEC_POOL: yastl::Pool = yastl::Pool::with_config(
12 std::thread::available_parallelism().map(|n|n.get()).unwrap_or(8),
13 yastl::ThreadConfig::new()
14 .prefix("fvm-executor")
15 .stack_size(64 << 20),
21 );
22}
23
24pub struct ThreadedExecutor<E>(pub E);
27
28impl<E> Executor for ThreadedExecutor<E>
29where
30 E: Executor + Send,
31{
32 type Kernel = E::Kernel;
33
34 fn execute_message(
36 &mut self,
37 msg: Message,
38 apply_kind: ApplyKind,
39 raw_length: usize,
40 ) -> anyhow::Result<ApplyRet> {
41 let mut ret = Err(anyhow!("failed to execute"));
42
43 EXEC_POOL.scoped(|scope| {
44 scope.execute(|| ret = self.0.execute_message(msg, apply_kind, raw_length));
45 });
46
47 ret
48 }
49
50 fn flush(&mut self) -> anyhow::Result<Cid> {
51 self.0.flush()
52 }
53}