use wasmer_types::MemoryError;
use crate::{
Memory,
error::AtomicsError,
location::{MemoryLocation, SharedMemoryOps},
};
#[derive(Clone)]
pub struct SharedMemory {
memory: Memory,
ops: std::sync::Arc<dyn SharedMemoryOps + Send + Sync>,
}
impl std::fmt::Debug for SharedMemory {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("SharedMemory").finish()
}
}
impl SharedMemory {
pub fn memory(&self) -> &Memory {
&self.memory
}
#[allow(unused)]
pub(crate) fn new(memory: Memory, ops: impl SharedMemoryOps + Send + Sync + 'static) -> Self {
Self {
memory,
ops: std::sync::Arc::new(ops),
}
}
pub fn notify(&self, location: MemoryLocation, count: u32) -> Result<u32, AtomicsError> {
self.ops.notify(location, count)
}
pub fn wait(
&self,
location: MemoryLocation,
timeout: Option<std::time::Duration>,
) -> Result<u32, AtomicsError> {
self.ops.wait(location, timeout)
}
pub fn disable_atomics(&self) -> Result<(), MemoryError> {
self.ops.disable_atomics()
}
pub fn wake_all_atomic_waiters(&self) -> Result<(), MemoryError> {
self.ops.wake_all_atomic_waiters()
}
}