Restaged repo, allocator and runtime implemented, ioring-backed async fs/net/channel/timer primitives
This commit is contained in:
78
lib/runtime/src/lib.rs
Normal file
78
lib/runtime/src/lib.rs
Normal file
@@ -0,0 +1,78 @@
|
||||
//! RUIN runtime foundations.
|
||||
//!
|
||||
//! This crate provides a Linux x86_64 runtime substrate: the mesh allocator, the reactor, and a
|
||||
//! single-threaded runtime loop with worker-thread task forwarding.
|
||||
|
||||
#![feature(thread_local)]
|
||||
|
||||
#[cfg(not(all(target_os = "linux", target_arch = "x86_64")))]
|
||||
compile_error!("ruin-runtime currently supports only Linux x86_64.");
|
||||
|
||||
extern crate alloc;
|
||||
|
||||
pub mod channel;
|
||||
pub mod fs;
|
||||
pub mod net;
|
||||
pub mod op;
|
||||
pub mod platform;
|
||||
pub mod sys;
|
||||
pub mod time;
|
||||
|
||||
pub use ruin_runtime_proc_macros::{async_main, main};
|
||||
|
||||
#[cfg(all(target_os = "linux", target_arch = "x86_64"))]
|
||||
pub use platform::linux_x86_64::mesh_alloc::{
|
||||
ActiveMeshGuard, Arena, AtomicBitmap, BitIter, CLASS_TO_SIZE, CompactionAdvice,
|
||||
CompactionEstimate, CompactionRecommendation, CompactionSkipReason,
|
||||
DEFAULT_GLOBAL_MINIHEAP_CAPACITY, FutexMutex, GlobalMeshAllocator, MeshAllocator, MeshStats,
|
||||
MiniHeap, MiniHeapFlags, MiniHeapId, Mwc, Mwc64, NUM_SIZE_CLASSES, PageConfig, PlatformHooks,
|
||||
PlatformInstallError, RelaxedBitmap, RuntimeCompactionPolicy, RuntimeCompactionResult,
|
||||
ShuffleEntry, ShuffleVector, Span, ThreadLocalHeap, byte_size_for_class,
|
||||
ensure_fault_mediation_installed, install_platform_hooks, ok_to_proceed, page_count,
|
||||
page_shift, page_size, retry_on_efault, retry_on_efault_ptrs, round_up_to_page,
|
||||
runtime_slots_per_span, size_class_for,
|
||||
};
|
||||
#[cfg(all(target_os = "linux", target_arch = "x86_64"))]
|
||||
pub use platform::linux_x86_64::mesh_alloc::{FreelistId, bitmaps_meshable};
|
||||
#[cfg(all(target_os = "linux", target_arch = "x86_64"))]
|
||||
pub use platform::linux_x86_64::reactor::{
|
||||
Reactor, ReadyEvents, ThreadNotifier, create, create_reactor, monotonic_now,
|
||||
};
|
||||
#[cfg(all(target_os = "linux", target_arch = "x86_64"))]
|
||||
pub use platform::linux_x86_64::runtime::{
|
||||
IntervalHandle, JoinHandle, ThreadHandle, TimeoutHandle, WorkerHandle, clear_interval,
|
||||
clear_timeout, current_thread_handle, queue_future, queue_microtask, queue_task, run,
|
||||
set_interval, set_timeout, spawn_worker, yield_now,
|
||||
};
|
||||
|
||||
pub const fn default_global_allocator() -> GlobalMeshAllocator {
|
||||
GlobalMeshAllocator::with_default_config()
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::{MeshAllocator, page_size};
|
||||
|
||||
#[test]
|
||||
fn mesh_allocator_smoke_test() {
|
||||
let mut allocator =
|
||||
MeshAllocator::new(page_size() * 1024, 256).expect("allocator should initialize");
|
||||
|
||||
let small = allocator
|
||||
.allocate(64)
|
||||
.expect("small allocation should succeed");
|
||||
unsafe {
|
||||
small.write_bytes(0xAB, 64);
|
||||
}
|
||||
allocator.deallocate(small);
|
||||
|
||||
let large_size = page_size() * 2;
|
||||
let large = allocator
|
||||
.allocate(large_size)
|
||||
.expect("large allocation should succeed");
|
||||
unsafe {
|
||||
large.write_bytes(0xCD, large_size);
|
||||
}
|
||||
allocator.deallocate(large);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user