Files
wasmtime/crates/bench-api/src/unsafe_send_sync.rs
Nick Fitzgerald 18fabd7700 bench-api: Allow multiple instantiations per compilation
We used to allow at most one instantiation per compilation, but there is no
fundamental reason why that should be the case. Allowing multiple instantiations
per compilation allows us to, for example, benchmark repeated instantiation
within Wasmtime's pooling allocator.

This additionally switches to using host functions for WASI and for
`bench_{start,end}` rather than defining them on the linker, this way we can use
a new store for every instantiation and don't need to keep other instances alive
when instantiating new instances.

Finally, we switch all timing to be done through callback functions, rather than
having the bench API caller implicitly start/end timers around bench API
calls. This allows us to more precisely measure phases and exclude things like
file I/O performed when creating a WASI context.
2021-05-24 16:53:22 -07:00

20 lines
517 B
Rust

#[derive(Clone, Copy)]
pub struct UnsafeSendSync<T>(T);
impl<T> UnsafeSendSync<T> {
/// Create a new `UnsafeSendSync` wrapper around the given value.
///
/// The result is a type that is `Send` and `Sync` regardless of whether `T:
/// Send + Sync`, so this constructor is unsafe.
pub unsafe fn new(val: T) -> Self {
UnsafeSendSync(val)
}
pub fn get(&self) -> &T {
&self.0
}
}
unsafe impl<T> Send for UnsafeSendSync<T> {}
unsafe impl<T> Sync for UnsafeSendSync<T> {}