wasmer_wasix/
capabilities.rs1use std::time::Duration;
2
3use crate::http::HttpClientCapabilityV1;
4
5#[derive(Clone, Debug, PartialEq, Eq, Hash)]
7pub struct Capabilities {
8 pub insecure_allow_all: bool,
9 pub http_client: HttpClientCapabilityV1,
10 pub threading: CapabilityThreadingV1,
11}
12
13impl Capabilities {
14 pub fn new() -> Self {
15 Self {
16 insecure_allow_all: false,
17 http_client: Default::default(),
18 threading: Default::default(),
19 }
20 }
21
22 pub fn update(&mut self, other: Capabilities) {
25 let Capabilities {
26 insecure_allow_all,
27 http_client,
28 threading,
29 } = other;
30 self.insecure_allow_all |= insecure_allow_all;
31 self.http_client.update(http_client);
32 self.threading.update(threading);
33 }
34}
35
36impl Default for Capabilities {
37 fn default() -> Self {
38 Self::new()
39 }
40}
41
42#[derive(Debug, Clone, PartialEq, Eq, Hash)]
44pub struct CapabilityThreadingV1 {
45 pub max_threads: Option<usize>,
49
50 pub enable_asynchronous_threading: bool,
53
54 pub enable_deep_sleep: bool,
57
58 pub enable_exponential_cpu_backoff: Option<Duration>,
63
64 pub enable_blocking_sleep: bool,
67}
68
69impl Default for CapabilityThreadingV1 {
70 fn default() -> Self {
71 Self {
72 max_threads: None,
73 enable_asynchronous_threading: true,
74 enable_deep_sleep: false,
75 enable_exponential_cpu_backoff: None,
76 enable_blocking_sleep: false,
77 }
78 }
79}
80
81impl CapabilityThreadingV1 {
82 pub fn update(&mut self, other: CapabilityThreadingV1) {
83 let CapabilityThreadingV1 {
84 max_threads,
85 enable_asynchronous_threading,
86 enable_deep_sleep,
87 enable_exponential_cpu_backoff,
88 enable_blocking_sleep,
89 } = other;
90 self.enable_asynchronous_threading |= enable_asynchronous_threading;
91 self.enable_deep_sleep |= enable_deep_sleep;
92 if let Some(val) = enable_exponential_cpu_backoff {
93 self.enable_exponential_cpu_backoff = Some(val);
94 }
95 self.max_threads = max_threads.or(self.max_threads);
96 self.enable_blocking_sleep |= enable_blocking_sleep;
97 }
98}