forked from bytecodealliance/wasmtime
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove resource abstraction from clocks (bytecodealliance#129)
* wit: remove resource index from monotonic-clocks and wall-clocks, delete instance-*-clock interfaces At this time, we don't have use cases for providing multiple wall clocks or multiple monotonic clocks to the same component. So, according to the principle of following preview 1's design as close as possible, we are changing these interfaces to being provided by ambient functions, rather than methods on a resource. * adapter: unresourcify clocks * host: de-resourcify clocks
- Loading branch information
Showing
6 changed files
with
24 additions
and
169 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,75 +1,16 @@ | ||
use crate::Error; | ||
use cap_std::time::Duration; | ||
|
||
pub trait WasiWallClock: Send + Sync { | ||
fn resolution(&self) -> Duration; | ||
fn now(&self) -> Duration; | ||
fn dup(&self) -> Box<dyn WasiWallClock + Send + Sync>; | ||
} | ||
|
||
pub trait WasiMonotonicClock: Send + Sync { | ||
fn resolution(&self) -> u64; | ||
fn now(&self) -> u64; | ||
fn dup(&self) -> Box<dyn WasiMonotonicClock + Send + Sync>; | ||
} | ||
|
||
pub struct WasiClocks { | ||
pub instance_wall_clock: Box<dyn WasiWallClock + Send + Sync>, | ||
pub instance_monotonic_clock: Box<dyn WasiMonotonicClock + Send + Sync>, | ||
} | ||
|
||
pub trait TableWallClockExt { | ||
fn get_wall_clock(&self, fd: u32) -> Result<&(dyn WasiWallClock + Send + Sync), Error>; | ||
fn get_wall_clock_mut( | ||
&mut self, | ||
fd: u32, | ||
) -> Result<&mut Box<dyn WasiWallClock + Send + Sync>, Error>; | ||
fn delete_wall_clock(&mut self, fd: u32) -> Result<(), Error>; | ||
} | ||
impl TableWallClockExt for crate::table::Table { | ||
fn get_wall_clock(&self, fd: u32) -> Result<&(dyn WasiWallClock + Send + Sync), Error> { | ||
self.get::<Box<dyn WasiWallClock + Send + Sync>>(fd) | ||
.map(|f| f.as_ref()) | ||
} | ||
fn get_wall_clock_mut( | ||
&mut self, | ||
fd: u32, | ||
) -> Result<&mut Box<dyn WasiWallClock + Send + Sync>, Error> { | ||
self.get_mut::<Box<dyn WasiWallClock + Send + Sync>>(fd) | ||
} | ||
fn delete_wall_clock(&mut self, fd: u32) -> Result<(), Error> { | ||
self.delete::<Box<dyn WasiWallClock + Send + Sync>>(fd) | ||
.map(|_old| ()) | ||
} | ||
} | ||
|
||
pub trait TableMonotonicClockExt { | ||
fn get_monotonic_clock( | ||
&self, | ||
fd: u32, | ||
) -> Result<&(dyn WasiMonotonicClock + Send + Sync), Error>; | ||
fn get_monotonic_clock_mut( | ||
&mut self, | ||
fd: u32, | ||
) -> Result<&mut Box<dyn WasiMonotonicClock + Send + Sync>, Error>; | ||
fn delete_monotonic_clock(&mut self, fd: u32) -> Result<(), Error>; | ||
} | ||
impl TableMonotonicClockExt for crate::table::Table { | ||
fn get_monotonic_clock( | ||
&self, | ||
fd: u32, | ||
) -> Result<&(dyn WasiMonotonicClock + Send + Sync), Error> { | ||
self.get::<Box<dyn WasiMonotonicClock + Send + Sync>>(fd) | ||
.map(|f| f.as_ref()) | ||
} | ||
fn get_monotonic_clock_mut( | ||
&mut self, | ||
fd: u32, | ||
) -> Result<&mut Box<dyn WasiMonotonicClock + Send + Sync>, Error> { | ||
self.get_mut::<Box<dyn WasiMonotonicClock + Send + Sync>>(fd) | ||
} | ||
fn delete_monotonic_clock(&mut self, fd: u32) -> Result<(), Error> { | ||
self.delete::<Box<dyn WasiMonotonicClock + Send + Sync>>(fd) | ||
.map(|_old| ()) | ||
} | ||
pub wall: Box<dyn WasiWallClock + Send + Sync>, | ||
pub monotonic: Box<dyn WasiMonotonicClock + Send + Sync>, | ||
} |