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