Browse Source

expose eager thread-local initialization by the Engine

pull/2946/head
Pat Hickey 4 years ago
parent
commit
ff87f45604
  1. 4
      crates/runtime/src/lib.rs
  2. 19
      crates/runtime/src/traphandlers.rs
  3. 8
      crates/wasmtime/src/engine.rs

4
crates/runtime/src/lib.rs

@ -49,8 +49,8 @@ pub use crate::memory::{Memory, RuntimeLinearMemory, RuntimeMemoryCreator};
pub use crate::mmap::Mmap;
pub use crate::table::{Table, TableElement};
pub use crate::traphandlers::{
catch_traps, init_traps, raise_lib_trap, raise_user_trap, resume_panic, SignalHandler,
TlsRestore, Trap,
catch_traps, init_traps, raise_lib_trap, raise_user_trap, resume_panic, tls_eager_initialize,
SignalHandler, TlsRestore, Trap,
};
pub use crate::vmcontext::{
VMCallerCheckedAnyfunc, VMContext, VMFunctionBody, VMFunctionImport, VMGlobalDefinition,

19
crates/runtime/src/traphandlers.rs

@ -12,7 +12,7 @@ use std::sync::atomic::Ordering::SeqCst;
use std::sync::Once;
use wasmtime_environ::ir;
pub use self::tls::TlsRestore;
pub use self::tls::{tls_eager_initialize, TlsRestore};
extern "C" {
#[allow(improper_ctypes)]
@ -386,12 +386,29 @@ mod tls {
})
}
#[inline(never)]
/// Eagerly initialize thread-local runtime functionality. This will be performed
/// lazily by the runtime if users do not perform it eagerly.
pub fn initialize() -> Result<(), Trap> {
PTR.with(|p| {
let (state, mut initialized) = p.get();
if !initialized {
super::super::sys::lazy_per_thread_init()?;
initialized = true;
}
p.set((state, initialized));
Ok(())
})
}
#[inline(never)] // see module docs for why this is here
pub fn get() -> Ptr {
PTR.with(|p| p.get().0)
}
}
pub use raw::initialize as tls_eager_initialize;
/// Opaque state used to help control TLS state across stack switches for
/// async support.
pub struct TlsRestore(raw::Ptr);

8
crates/wasmtime/src/engine.rs

@ -1,5 +1,5 @@
use crate::signatures::SignatureRegistry;
use crate::Config;
use crate::{Config, Trap};
use anyhow::Result;
use std::sync::Arc;
#[cfg(feature = "cache")]
@ -63,6 +63,12 @@ impl Engine {
})
}
/// Eagerly initialize thread-local functionality shared by all [`Engine`]s. This
/// will be performed lazily by the runtime if users do not perform it eagerly.
pub fn tls_eager_initialize() -> Result<(), Trap> {
wasmtime_runtime::tls_eager_initialize().map_err(Trap::from_runtime)
}
/// Returns the configuration settings that this engine is using.
#[inline]
pub fn config(&self) -> &Config {

Loading…
Cancel
Save