expose eager thread-local initialization by the Engine
This commit is contained in:
@@ -49,8 +49,8 @@ pub use crate::memory::{Memory, RuntimeLinearMemory, RuntimeMemoryCreator};
|
|||||||
pub use crate::mmap::Mmap;
|
pub use crate::mmap::Mmap;
|
||||||
pub use crate::table::{Table, TableElement};
|
pub use crate::table::{Table, TableElement};
|
||||||
pub use crate::traphandlers::{
|
pub use crate::traphandlers::{
|
||||||
catch_traps, init_traps, raise_lib_trap, raise_user_trap, resume_panic, SignalHandler,
|
catch_traps, init_traps, raise_lib_trap, raise_user_trap, resume_panic, tls_eager_initialize,
|
||||||
TlsRestore, Trap,
|
SignalHandler, TlsRestore, Trap,
|
||||||
};
|
};
|
||||||
pub use crate::vmcontext::{
|
pub use crate::vmcontext::{
|
||||||
VMCallerCheckedAnyfunc, VMContext, VMFunctionBody, VMFunctionImport, VMGlobalDefinition,
|
VMCallerCheckedAnyfunc, VMContext, VMFunctionBody, VMFunctionImport, VMGlobalDefinition,
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ use std::sync::atomic::Ordering::SeqCst;
|
|||||||
use std::sync::Once;
|
use std::sync::Once;
|
||||||
use wasmtime_environ::ir;
|
use wasmtime_environ::ir;
|
||||||
|
|
||||||
pub use self::tls::TlsRestore;
|
pub use self::tls::{tls_eager_initialize, TlsRestore};
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#[allow(improper_ctypes)]
|
#[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
|
#[inline(never)] // see module docs for why this is here
|
||||||
pub fn get() -> Ptr {
|
pub fn get() -> Ptr {
|
||||||
PTR.with(|p| p.get().0)
|
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
|
/// Opaque state used to help control TLS state across stack switches for
|
||||||
/// async support.
|
/// async support.
|
||||||
pub struct TlsRestore(raw::Ptr);
|
pub struct TlsRestore(raw::Ptr);
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
use crate::signatures::SignatureRegistry;
|
use crate::signatures::SignatureRegistry;
|
||||||
use crate::Config;
|
use crate::{Config, Trap};
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
#[cfg(feature = "cache")]
|
#[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.
|
/// Returns the configuration settings that this engine is using.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn config(&self) -> &Config {
|
pub fn config(&self) -> &Config {
|
||||||
|
|||||||
Reference in New Issue
Block a user