open_entry_bindings/
runtime.rs

1use tokio::{runtime::Runtime as TokioRuntime, sync::mpsc::UnboundedReceiver};
2use std::{sync::{Arc, atomic::AtomicBool}, collections::HashSet};
3
4use tokio::sync::{Mutex, RwLock};
5
6use crate::{shared_memory::SharedMemory, extensions::Extensions, archive::Archive, shutdown_type::ShutdownType, thread_counter::ThreadCounter, executor::Executor, event::EventType, virtual_thread::VThread, extension_data::ExtensionData, ffi::FfiBindings};
7
8pub struct Runtime {
9    pub temp_vmstr: Arc<Mutex<HashSet<(u64, usize)>>>,
10    pub memory: RwLock<SharedMemory>,
11    pub tokio_rt: Arc<TokioRuntime>,
12    pub extensions: Extensions,
13    pub archive: Arc<Archive>,
14    pub shutdown: AtomicBool,
15    pub initial_inst: u64,
16    pub base: u64,
17
18    pub ffi: FfiBindings,
19    pub extension_data: ExtensionData,
20
21    _shutdown_rx: Mutex<UnboundedReceiver<ShutdownType>>,
22    _threads: ThreadCounter,
23    pub stack_size: usize,
24
25    pub executor: Executor
26}
27
28impl Runtime {
29    #[inline(always)] pub fn dispatch_extension_event(self: &Arc<Self>, event: EventType) {
30        unsafe { crate::Runtime__dispatch_extension_event.unwrap_unchecked()(self, event) }
31    }
32    
33    #[inline(always)] pub fn send_extension_event(self: &Arc<Self>, target: u32, event: EventType) {
34        unsafe { crate::Runtime__send_extension_event.unwrap_unchecked()(self, target, event) }
35    }
36    
37    #[inline(always)] pub fn dispose_thread(&self, thread: VThread) {
38        unsafe { crate::Runtime__dispose_thread.unwrap_unchecked()(self, thread) }
39    }
40    
41    #[inline(always)] pub fn shutdown(&self, shutdown_type: ShutdownType) {
42        unsafe { crate::Runtime__shutdown.unwrap_unchecked()(self, shutdown_type) }
43    }
44
45    #[inline(always)] pub async fn set_error_data(&self, data: String) {
46        unsafe { crate::Runtime__set_error_data.unwrap_unchecked()(self, data).await; }
47    }
48
49    #[inline(always)] pub async fn spawn(self: &Arc<Self>, addr: u64) {
50        unsafe { crate::Runtime__spawn.unwrap_unchecked()(self, addr).await; }
51    }
52}