Move StoreId to common wasmer_types

This commit is contained in:
Syrus Akbary
2023-02-09 19:22:33 +01:00
parent 83313eb098
commit 30f4589f23
6 changed files with 35 additions and 58 deletions

View File

@@ -234,30 +234,8 @@ mod objects {
use wasm_bindgen::JsValue;
use crate::js::{function_env::VMFunctionEnvironment, vm::VMGlobal};
use std::{
fmt,
marker::PhantomData,
num::{NonZeroU64, NonZeroUsize},
sync::atomic::{AtomicU64, Ordering},
};
/// Unique ID to identify a context.
///
/// Every handle to an object managed by a context also contains the ID of the
/// context. This is used to check that a handle is always used with the
/// correct context.
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
pub struct StoreId(NonZeroU64);
impl Default for StoreId {
// Allocates a unique ID for a new context.
fn default() -> Self {
// No overflow checking is needed here: overflowing this would take
// thousands of years.
static NEXT_ID: AtomicU64 = AtomicU64::new(1);
Self(NonZeroU64::new(NEXT_ID.fetch_add(1, Ordering::Relaxed)).unwrap())
}
}
use std::{fmt, marker::PhantomData, num::NonZeroUsize};
pub use wasmer_types::StoreId;
/// Trait to represent an object managed by a context. This is implemented on
/// the VM types managed by the context.

View File

@@ -3,9 +3,10 @@ use crate::sys::engine::{default_engine, Engine};
use derivative::Derivative;
use std::fmt;
use wasmer_compiler::Tunables;
use wasmer_types::OnCalledAction;
use wasmer_vm::{init_traps, StoreId, TrapHandlerFn};
use wasmer_types::{OnCalledAction, StoreId};
use wasmer_vm::{init_traps, TrapHandlerFn};
#[cfg(feature = "sys")]
use wasmer_vm::StoreObjects;
/// Call handler for a store.