1use std::sync::Arc;
6
7pub trait StallProvider: Sync + Send + 'static {
8 fn get_stall_info(&self) -> Result<zx::MemoryStall, anyhow::Error>;
10}
11
12pub struct StallProviderImpl {
13 stall_resource: Arc<dyn StallResource>,
15}
16
17pub trait StallResource: Sync + Send {
20 fn get_memory_stall(&self) -> Result<zx::MemoryStall, zx::Status>;
21}
22
23impl StallResource for zx::Resource {
24 fn get_memory_stall(&self) -> Result<zx::MemoryStall, zx::Status> {
25 self.memory_stall()
26 }
27}
28
29impl StallProviderImpl {
30 pub fn new(stall_resource: Arc<dyn StallResource>) -> Result<StallProviderImpl, anyhow::Error> {
32 Ok(StallProviderImpl { stall_resource: stall_resource })
33 }
34}
35
36impl StallProvider for StallProviderImpl {
37 fn get_stall_info(&self) -> Result<zx::MemoryStall, anyhow::Error> {
38 Ok(self.stall_resource.get_memory_stall()?)
39 }
40}