dope_runtime/process/
context.rs1use dope_core::executor::{self, create};
2use dope_core::{
3 driver::{
4 life::{creation, domain},
5 settings,
6 },
7 platform::{affinity, affinity::Binding},
8 random,
9};
10
11use crate::{
12 process::{self, gate, runtime::bus},
13};
14
15pub struct Context<'run> {
16 affinity: Binding,
17 seed: random::Seed,
18 shutdown: process::Shutdown<'run>,
19}
20
21impl<'run> Context<'run> {
22 pub(super) const fn new(bind: Binding, seed: random::Seed, tx: bus::Tx<'run>) -> Self {
23 Self {
24 affinity: bind,
25 seed,
26 shutdown: process::Shutdown::new(tx),
27 }
28 }
29
30 pub fn cpu(&self) -> affinity::Cpu {
31 self.affinity.cpu()
32 }
33
34 pub fn terminal(&self) -> process::Terminal<'run> {
35 self.shutdown.terminal()
36 }
37
38 pub(super) fn gated(self) -> (Self, gate::Closed<'run>) {
39 let gate = self.shutdown.gate();
40 (self, gate)
41 }
42}
43
44impl<'run> executor::Build for Context<'run> {
45 type Shutdown = process::Shutdown<'run>;
46
47 fn try_build(
48 self,
49 attempt: &mut creation::Attempt,
50 config: settings::Config,
51 ) -> Result<domain::Generation<Self::Shutdown>, create::Error<'_>> {
52 self.shutdown.attach(
53 attempt
54 .try_seed(config, self.seed)
55 .map(domain::Generation::new)
56 .map_err(create::Error::from),
57 )
58 }
59}