Use HashMap instead of BTreeMap where possible
This shrinks the kernel from 905840 bytes to 862408 bytes.
This commit is contained in:
Generated
+50
-2
@@ -2,6 +2,18 @@
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "ahash"
|
||||
version = "0.8.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "91429305e9f0a25f6205c5b8e0d2db09e0708a7a6df0f42212bb56c32c8ac97a"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"once_cell",
|
||||
"version_check",
|
||||
"zerocopy",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "autocfg"
|
||||
version = "1.1.0"
|
||||
@@ -70,9 +82,12 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "hashbrown"
|
||||
version = "0.14.0"
|
||||
version = "0.14.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2c6201b9ff9fd90a5a3bac2e56a830d0caa509576f0e503818ee82c181b3437a"
|
||||
checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604"
|
||||
dependencies = [
|
||||
"ahash",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "indexmap"
|
||||
@@ -94,6 +109,7 @@ dependencies = [
|
||||
"cc",
|
||||
"fdt",
|
||||
"goblin",
|
||||
"hashbrown",
|
||||
"linked_list_allocator 0.9.1",
|
||||
"log",
|
||||
"paste",
|
||||
@@ -151,6 +167,12 @@ version = "2.6.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8f232d6ef707e1956a43342693d2a31e72989554d58299d7a88738cc95b0d35c"
|
||||
|
||||
[[package]]
|
||||
name = "once_cell"
|
||||
version = "1.19.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92"
|
||||
|
||||
[[package]]
|
||||
name = "paste"
|
||||
version = "1.0.9"
|
||||
@@ -343,6 +365,12 @@ version = "1.0.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "301abaae475aa91687eb82514b328ab47a211a533026cb25fc3e519b86adfc3c"
|
||||
|
||||
[[package]]
|
||||
name = "version_check"
|
||||
version = "0.9.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
|
||||
|
||||
[[package]]
|
||||
name = "winnow"
|
||||
version = "0.5.15"
|
||||
@@ -362,3 +390,23 @@ dependencies = [
|
||||
"bitflags",
|
||||
"raw-cpuid",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "zerocopy"
|
||||
version = "0.7.30"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "306dca4455518f1f31635ec308b6b3e4eb1b11758cefafc782827d0aa7acb5c7"
|
||||
dependencies = [
|
||||
"zerocopy-derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "zerocopy-derive"
|
||||
version = "0.7.30"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "be912bf68235a88fbefd1b73415cb218405958d1655b2ece9035a19920bdf6ba"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
@@ -12,6 +12,7 @@ toml = "0.7"
|
||||
[dependencies]
|
||||
bitflags = "1.2.1"
|
||||
bitfield = "0.13.2"
|
||||
hashbrown = { version = "0.14.3", default-features = false, features = ["ahash", "inline-more"] }
|
||||
linked_list_allocator = "0.9.0"
|
||||
log = "0.4"
|
||||
redox_syscall = { path = "syscall" }
|
||||
|
||||
+1
-1
Submodule rmm updated: a992ae89ed...d7d824552b
+3
-3
@@ -1,11 +1,11 @@
|
||||
//! # ACPI
|
||||
//! Code to parse the ACPI tables
|
||||
|
||||
use alloc::collections::BTreeMap;
|
||||
use alloc::string::String;
|
||||
use alloc::vec::Vec;
|
||||
use alloc::boxed::Box;
|
||||
|
||||
use hashbrown::HashMap;
|
||||
use spin::{Once, RwLock};
|
||||
|
||||
use crate::log::info;
|
||||
@@ -76,7 +76,7 @@ pub static RXSDT_ENUM: Once<RxsdtEnum> = Once::new();
|
||||
pub unsafe fn init(already_supplied_rsdps: Option<(u64, u64)>) {
|
||||
{
|
||||
let mut sdt_ptrs = SDT_POINTERS.write();
|
||||
*sdt_ptrs = Some(BTreeMap::new());
|
||||
*sdt_ptrs = Some(HashMap::new());
|
||||
}
|
||||
|
||||
// Search for RSDP
|
||||
@@ -148,7 +148,7 @@ pub unsafe fn init(already_supplied_rsdps: Option<(u64, u64)>) {
|
||||
}
|
||||
|
||||
pub type SdtSignature = (String, [u8; 6], [u8; 8]);
|
||||
pub static SDT_POINTERS: RwLock<Option<BTreeMap<SdtSignature, &'static Sdt>>> = RwLock::new(None);
|
||||
pub static SDT_POINTERS: RwLock<Option<HashMap<SdtSignature, &'static Sdt>>> = RwLock::new(None);
|
||||
|
||||
pub fn find_sdt(name: &str) -> Vec<&'static Sdt> {
|
||||
let mut sdts: Vec<&'static Sdt> = vec!();
|
||||
|
||||
+3
-3
@@ -3,7 +3,7 @@ use core::sync::atomic::{AtomicU32, Ordering};
|
||||
use core::mem;
|
||||
|
||||
use alloc::boxed::Box;
|
||||
use alloc::collections::BTreeMap;
|
||||
use hashbrown::HashMap;
|
||||
|
||||
use x86::segmentation::Descriptor as X86IdtEntry;
|
||||
use x86::dtables::{self, DescriptorTablePointer};
|
||||
@@ -68,7 +68,7 @@ impl Idt {
|
||||
static mut INIT_BSP_IDT: Idt = Idt::new();
|
||||
|
||||
// TODO: VecMap?
|
||||
pub static IDTS: RwLock<Option<BTreeMap<LogicalCpuId, &'static mut Idt>>> = RwLock::new(None);
|
||||
pub static IDTS: RwLock<Option<HashMap<LogicalCpuId, &'static mut Idt>>> = RwLock::new(None);
|
||||
|
||||
#[inline]
|
||||
pub fn is_reserved(cpu_id: LogicalCpuId, index: u8) -> bool {
|
||||
@@ -128,7 +128,7 @@ const fn new_idt_reservations() -> [AtomicU32; 8] {
|
||||
/// Initialize the IDT for a
|
||||
pub unsafe fn init_paging_post_heap(is_bsp: bool, cpu_id: LogicalCpuId) {
|
||||
let mut idts_guard = IDTS.write();
|
||||
let idts_btree = idts_guard.get_or_insert_with(BTreeMap::new);
|
||||
let idts_btree = idts_guard.get_or_insert_with(HashMap::new);
|
||||
|
||||
if is_bsp {
|
||||
idts_btree.insert(cpu_id, &mut INIT_BSP_IDT);
|
||||
|
||||
@@ -3,7 +3,7 @@ use core::sync::atomic::{AtomicU64, Ordering};
|
||||
use core::mem;
|
||||
|
||||
use alloc::boxed::Box;
|
||||
use alloc::collections::BTreeMap;
|
||||
use hashbrown::HashMap;
|
||||
|
||||
use x86::segmentation::Descriptor as X86IdtEntry;
|
||||
use x86::dtables::{self, DescriptorTablePointer};
|
||||
@@ -69,7 +69,7 @@ impl Idt {
|
||||
static mut INIT_BSP_IDT: Idt = Idt::new();
|
||||
|
||||
// TODO: VecMap?
|
||||
pub static IDTS: RwLock<Option<BTreeMap<LogicalCpuId, &'static mut Idt>>> = RwLock::new(None);
|
||||
pub static IDTS: RwLock<Option<HashMap<LogicalCpuId, &'static mut Idt>>> = RwLock::new(None);
|
||||
|
||||
#[inline]
|
||||
pub fn is_reserved(cpu_id: LogicalCpuId, index: u8) -> bool {
|
||||
@@ -113,7 +113,7 @@ const fn new_idt_reservations() -> [AtomicU64; 4] {
|
||||
/// Initialize the IDT for a
|
||||
pub unsafe fn init_paging_post_heap(is_bsp: bool, cpu_id: LogicalCpuId) {
|
||||
let mut idts_guard = IDTS.write();
|
||||
let idts_btree = idts_guard.get_or_insert_with(BTreeMap::new);
|
||||
let idts_btree = idts_guard.get_or_insert_with(HashMap::new);
|
||||
|
||||
if is_bsp {
|
||||
idts_btree.insert(cpu_id, &mut INIT_BSP_IDT);
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
#[macro_export]
|
||||
macro_rules! int_like {
|
||||
($new_type_name:ident, $backing_type: ident) => {
|
||||
#[derive(Default, PartialEq, Eq, PartialOrd, Ord, Debug, Clone, Copy)]
|
||||
#[derive(Default, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Clone, Copy)]
|
||||
pub struct $new_type_name($backing_type);
|
||||
|
||||
impl $new_type_name {
|
||||
|
||||
@@ -9,6 +9,7 @@ use super::context::{Context, ContextId};
|
||||
|
||||
/// Context list type
|
||||
pub struct ContextList {
|
||||
// Using a BTreeMap for it's range method
|
||||
map: BTreeMap<ContextId, Arc<RwLock<Context>>>,
|
||||
next_id: usize
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
use alloc::collections::BTreeMap;
|
||||
use alloc::{sync::Arc, vec::Vec};
|
||||
use hashbrown::HashMap;
|
||||
use syscall::{GrantFlags, MunmapFlags};
|
||||
use core::cmp;
|
||||
use core::fmt::Debug;
|
||||
@@ -404,13 +405,15 @@ impl AddrSpace {
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct UserGrants {
|
||||
// Using a BTreeMap for it's range method.
|
||||
inner: BTreeMap<Page, GrantInfo>,
|
||||
// Using a BTreeMap for it's range method.
|
||||
holes: BTreeMap<VirtualAddress, usize>,
|
||||
// TODO: Would an additional map ordered by (size,start) to allow for O(log n) allocations be
|
||||
// beneficial?
|
||||
|
||||
//TODO: technically VirtualAddress is from a scheme's context!
|
||||
pub funmap: BTreeMap<Page, (usize, Page)>,
|
||||
pub funmap: HashMap<Page, (usize, Page)>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
@@ -496,7 +499,7 @@ impl UserGrants {
|
||||
Self {
|
||||
inner: BTreeMap::new(),
|
||||
holes: core::iter::once((VirtualAddress::new(0), crate::USER_END_OFFSET)).collect::<BTreeMap<_, _>>(),
|
||||
funmap: BTreeMap::new(),
|
||||
funmap: HashMap::new(),
|
||||
}
|
||||
}
|
||||
/// Returns the grant, if any, which occupies the specified page
|
||||
|
||||
+8
-8
@@ -5,18 +5,18 @@ use crate::paging::{RmmA, RmmArch, TableKind, PAGE_SIZE};
|
||||
// Super unsafe due to page table switching and raw pointers!
|
||||
#[cfg(target_arch = "aarch64")]
|
||||
pub unsafe fn debugger(target_id: Option<crate::context::ContextId>) {
|
||||
use alloc::collections::{BTreeSet, BTreeMap};
|
||||
use hashbrown::HashSet;
|
||||
|
||||
use crate::memory::{RefCount, get_page_info};
|
||||
|
||||
println!("DEBUGGER START");
|
||||
println!();
|
||||
|
||||
let mut tree = BTreeMap::new();
|
||||
let mut tree = HashMap::new();
|
||||
|
||||
let old_table = RmmA::table(TableKind::User);
|
||||
|
||||
let mut spaces = BTreeSet::new();
|
||||
let mut spaces = HashSet::new();
|
||||
|
||||
for (id, context_lock) in crate::context::contexts().iter() {
|
||||
if target_id.map_or(false, |target_id| *id != target_id) { continue; }
|
||||
@@ -174,7 +174,7 @@ pub unsafe fn debugger(target_id: Option<crate::context::ContextId>) {
|
||||
// Super unsafe due to page table switching and raw pointers!
|
||||
#[cfg(target_arch = "x86_64")]
|
||||
pub unsafe fn debugger(target_id: Option<crate::context::ContextId>) {
|
||||
use alloc::collections::BTreeSet;
|
||||
use hashbrown::HashSet;
|
||||
|
||||
use crate::memory::{RefCount, get_page_info};
|
||||
|
||||
@@ -183,8 +183,8 @@ pub unsafe fn debugger(target_id: Option<crate::context::ContextId>) {
|
||||
println!("DEBUGGER START");
|
||||
println!();
|
||||
|
||||
let mut tree = BTreeMap::new();
|
||||
let mut spaces = BTreeSet::new();
|
||||
let mut tree = HashMap::new();
|
||||
let mut spaces = HashSet::new();
|
||||
|
||||
let old_table = RmmA::table(TableKind::User);
|
||||
|
||||
@@ -267,10 +267,10 @@ pub unsafe fn debugger(target_id: Option<crate::context::ContextId>) {
|
||||
unsafe { x86::bits64::rflags::clac(); }
|
||||
}
|
||||
#[cfg(any(target_arch = "aarch64", target_arch = "x86_64"))]
|
||||
use {alloc::collections::BTreeMap, crate::memory::Frame};
|
||||
use {hashbrown::HashMap, crate::memory::Frame};
|
||||
|
||||
#[cfg(any(target_arch = "aarch64", target_arch = "x86_64"))]
|
||||
pub unsafe fn check_consistency(addr_space: &mut crate::context::memory::AddrSpace, new_as: bool, tree: &mut BTreeMap<Frame, usize>) {
|
||||
pub unsafe fn check_consistency(addr_space: &mut crate::context::memory::AddrSpace, new_as: bool, tree: &mut HashMap<Frame, usize>) {
|
||||
|
||||
use crate::context::memory::PageSpan;
|
||||
use crate::memory::{get_page_info, RefCount};
|
||||
|
||||
+7
-7
@@ -1,6 +1,6 @@
|
||||
use alloc::sync::Arc;
|
||||
use alloc::collections::BTreeMap;
|
||||
use core::sync::atomic::{AtomicUsize, Ordering};
|
||||
use hashbrown::HashMap;
|
||||
use spin::{Once, RwLock, RwLockReadGuard, RwLockWriteGuard};
|
||||
|
||||
use crate::context;
|
||||
@@ -64,7 +64,7 @@ impl EventQueue {
|
||||
}
|
||||
}
|
||||
|
||||
pub type EventQueueList = BTreeMap<EventQueueId, Arc<EventQueue>>;
|
||||
pub type EventQueueList = HashMap<EventQueueId, Arc<EventQueue>>;
|
||||
|
||||
// Next queue id
|
||||
static NEXT_QUEUE_ID: AtomicUsize = AtomicUsize::new(0);
|
||||
@@ -79,7 +79,7 @@ static QUEUES: Once<RwLock<EventQueueList>> = Once::new();
|
||||
|
||||
/// Initialize queues, called if needed
|
||||
fn init_queues() -> RwLock<EventQueueList> {
|
||||
RwLock::new(BTreeMap::new())
|
||||
RwLock::new(HashMap::new())
|
||||
}
|
||||
|
||||
/// Get the event queues list, const
|
||||
@@ -92,20 +92,20 @@ pub fn queues_mut() -> RwLockWriteGuard<'static, EventQueueList> {
|
||||
QUEUES.call_once(init_queues).write()
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord)]
|
||||
#[derive(Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
|
||||
pub struct RegKey {
|
||||
pub scheme: SchemeId,
|
||||
pub number: usize,
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord)]
|
||||
#[derive(Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
|
||||
pub struct QueueKey {
|
||||
pub queue: EventQueueId,
|
||||
pub id: usize,
|
||||
pub data: usize,
|
||||
}
|
||||
|
||||
type Registry = BTreeMap<RegKey, BTreeMap<QueueKey, EventFlags>>;
|
||||
type Registry = HashMap<RegKey, HashMap<QueueKey, EventFlags>>;
|
||||
|
||||
static REGISTRY: Once<RwLock<Registry>> = Once::new();
|
||||
|
||||
@@ -128,7 +128,7 @@ pub fn register(reg_key: RegKey, queue_key: QueueKey, flags: EventFlags) {
|
||||
let mut registry = registry_mut();
|
||||
|
||||
let entry = registry.entry(reg_key).or_insert_with(|| {
|
||||
BTreeMap::new()
|
||||
HashMap::new()
|
||||
});
|
||||
|
||||
if flags.is_empty() {
|
||||
|
||||
+1
-1
@@ -293,7 +293,7 @@ mod kernel_executable_offsets {
|
||||
/// This is usually but not necessarily the same as the APIC ID.
|
||||
|
||||
// TODO: Differentiate between logical CPU IDs and hardware CPU IDs (e.g. APIC IDs)
|
||||
#[derive(Clone, Copy, Eq, Ord, PartialEq, PartialOrd)]
|
||||
#[derive(Clone, Copy, Eq, PartialEq, Hash)]
|
||||
// TODO: NonMaxUsize?
|
||||
// TODO: Optimize away this type if not cfg!(feature = "multi_core")
|
||||
struct LogicalCpuId(u32);
|
||||
|
||||
+1
-1
@@ -82,7 +82,7 @@ pub fn deallocate_frames(frame: Frame, count: usize) {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
|
||||
#[derive(Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
|
||||
pub struct Frame {
|
||||
// On x86/x86_64, all memory below 1 MiB is reserved, and although some frames in that range
|
||||
// may end up in the paging code, it's very unlikely that frame 0x0 would.
|
||||
|
||||
+4
-7
@@ -19,14 +19,11 @@ use crate::{
|
||||
|
||||
use alloc::{
|
||||
boxed::Box,
|
||||
collections::{
|
||||
BTreeMap,
|
||||
VecDeque,
|
||||
btree_map::Entry
|
||||
},
|
||||
collections::VecDeque,
|
||||
sync::Arc,
|
||||
};
|
||||
use core::cmp;
|
||||
use hashbrown::hash_map::{Entry, HashMap};
|
||||
use spin::{Mutex, Once, RwLock, RwLockReadGuard, RwLockWriteGuard};
|
||||
|
||||
// ____ _
|
||||
@@ -110,12 +107,12 @@ impl Session {
|
||||
}
|
||||
}
|
||||
|
||||
type SessionMap = BTreeMap<ContextId, Arc<Session>>;
|
||||
type SessionMap = HashMap<ContextId, Arc<Session>>;
|
||||
|
||||
static SESSIONS: Once<RwLock<SessionMap>> = Once::new();
|
||||
|
||||
fn init_sessions() -> RwLock<SessionMap> {
|
||||
RwLock::new(BTreeMap::new())
|
||||
RwLock::new(HashMap::new())
|
||||
}
|
||||
fn sessions() -> RwLockReadGuard<'static, SessionMap> {
|
||||
SESSIONS.call_once(init_sessions).read()
|
||||
|
||||
@@ -39,6 +39,7 @@ enum HandleKind {
|
||||
ShutdownPipe,
|
||||
}
|
||||
|
||||
// Using BTreeMap as hashbrown doesn't have a const constructor.
|
||||
static HANDLES: RwLock<BTreeMap<usize, Handle>> = RwLock::new(BTreeMap::new());
|
||||
static NEXT_FD: AtomicUsize = AtomicUsize::new(0);
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@ struct Handle {
|
||||
flags: usize,
|
||||
}
|
||||
|
||||
// Using BTreeMap as hashbrown doesn't have a const constructor.
|
||||
static HANDLES: RwLock<BTreeMap<usize, Handle>> = RwLock::new(BTreeMap::new());
|
||||
|
||||
/// Add to the input queue
|
||||
|
||||
+3
-3
@@ -1,7 +1,7 @@
|
||||
use core::sync::atomic::{self, AtomicUsize};
|
||||
|
||||
use alloc::boxed::Box;
|
||||
use alloc::collections::BTreeMap;
|
||||
use hashbrown::HashMap;
|
||||
use spin::{Once, RwLock};
|
||||
|
||||
use crate::dtb::DTB_BINARY;
|
||||
@@ -30,7 +30,7 @@ struct Handle {
|
||||
stat: bool,
|
||||
}
|
||||
|
||||
static HANDLES: RwLock<BTreeMap<usize, Handle>> = RwLock::new(BTreeMap::new());
|
||||
static HANDLES: RwLock<HashMap<usize, Handle>> = RwLock::new(HashMap::new());
|
||||
static NEXT_FD: AtomicUsize = AtomicUsize::new(0);
|
||||
static DATA: Once<Box<[u8]>> = Once::new();
|
||||
static SCHEME_ID: Once<SchemeId> = Once::new();
|
||||
@@ -157,7 +157,7 @@ impl KernelScheme for DtbScheme {
|
||||
let handles = HANDLES.read();
|
||||
let handle = handles.get(&id).ok_or(Error::new(EBADF))?;
|
||||
buf.copy_exactly(&match handle.kind {
|
||||
HandleKind::RawData => {
|
||||
HandleKind::RawData => {
|
||||
let data = DATA.get().ok_or(Error::new(EBADFD))?;
|
||||
Stat {
|
||||
st_mode: MODE_FILE,
|
||||
|
||||
@@ -21,6 +21,7 @@ use super::{GlobalSchemes, OpenResult, CallerCtx, calc_seek_offset};
|
||||
|
||||
/// IRQ queues
|
||||
pub(super) static COUNTS: Mutex<[usize; 224]> = Mutex::new([0; 224]);
|
||||
// Using BTreeMap as hashbrown doesn't have a const constructor.
|
||||
static HANDLES: RwLock<BTreeMap<usize, Handle>> = RwLock::new(BTreeMap::new());
|
||||
|
||||
/// These are IRQs 0..=15 (corresponding to interrupt vectors 32..=47). They are opened without the
|
||||
|
||||
@@ -12,6 +12,7 @@ use super::{KernelScheme, CallerCtx, OpenResult};
|
||||
pub struct ITimerScheme;
|
||||
|
||||
static NEXT_ID: AtomicUsize = AtomicUsize::new(1);
|
||||
// Using BTreeMap as hashbrown doesn't have a const constructor.
|
||||
static HANDLES: RwLock<BTreeMap<usize, usize>> = RwLock::new(BTreeMap::new());
|
||||
|
||||
impl KernelScheme for ITimerScheme {
|
||||
|
||||
+8
-7
@@ -13,6 +13,7 @@ use alloc::{
|
||||
sync::Arc,
|
||||
vec::Vec,
|
||||
};
|
||||
use hashbrown::HashMap;
|
||||
use syscall::{MunmapFlags, SendFdFlags, EventFlags, SEEK_SET, SEEK_CUR, SEEK_END};
|
||||
use core::sync::atomic::AtomicUsize;
|
||||
use spin::{Once, RwLock, RwLockReadGuard, RwLockWriteGuard};
|
||||
@@ -95,7 +96,7 @@ int_like!(SchemeId, usize);
|
||||
int_like!(FileHandle, AtomicFileHandle, usize, AtomicUsize);
|
||||
|
||||
pub struct SchemeIter<'a> {
|
||||
inner: Option<::alloc::collections::btree_map::Iter<'a, Box<str>, SchemeId>>
|
||||
inner: Option<hashbrown::hash_map::Iter<'a, Box<str>, SchemeId>>
|
||||
}
|
||||
|
||||
impl<'a> Iterator for SchemeIter<'a> {
|
||||
@@ -108,8 +109,8 @@ impl<'a> Iterator for SchemeIter<'a> {
|
||||
|
||||
/// Scheme list type
|
||||
pub struct SchemeList {
|
||||
map: BTreeMap<SchemeId, KernelSchemes>,
|
||||
pub(crate) names: BTreeMap<SchemeNamespace, BTreeMap<Box<str>, SchemeId>>,
|
||||
map: HashMap<SchemeId, KernelSchemes>,
|
||||
pub(crate) names: HashMap<SchemeNamespace, HashMap<Box<str>, SchemeId>>,
|
||||
next_ns: usize,
|
||||
next_id: usize,
|
||||
}
|
||||
@@ -117,8 +118,8 @@ impl SchemeList {
|
||||
/// Create a new scheme list.
|
||||
pub fn new() -> Self {
|
||||
let mut list = SchemeList {
|
||||
map: BTreeMap::new(),
|
||||
names: BTreeMap::new(),
|
||||
map: HashMap::new(),
|
||||
names: HashMap::new(),
|
||||
// Scheme namespaces always start at 1. 0 is a reserved namespace, the null namespace
|
||||
next_ns: 1,
|
||||
next_id: MAX_GLOBAL_SCHEMES,
|
||||
@@ -150,7 +151,7 @@ impl SchemeList {
|
||||
/// Initialize the null namespace
|
||||
fn new_null(&mut self) {
|
||||
let ns = SchemeNamespace(0);
|
||||
self.names.insert(ns, BTreeMap::new());
|
||||
self.names.insert(ns, HashMap::new());
|
||||
|
||||
//TODO: Only memory: is in the null namespace right now. It should be removed when
|
||||
//anonymous mmap's are implemented
|
||||
@@ -163,7 +164,7 @@ impl SchemeList {
|
||||
fn new_ns(&mut self) -> SchemeNamespace {
|
||||
let ns = SchemeNamespace(self.next_ns);
|
||||
self.next_ns += 1;
|
||||
self.names.insert(ns, BTreeMap::new());
|
||||
self.names.insert(ns, HashMap::new());
|
||||
|
||||
self.insert(ns, "", |scheme_id| KernelSchemes::Root(Arc::new(RootScheme::new(ns, scheme_id)))).unwrap();
|
||||
self.insert_global(ns, "event", GlobalSchemes::Event).unwrap();
|
||||
|
||||
@@ -19,6 +19,7 @@ use super::{KernelScheme, OpenResult, CallerCtx, GlobalSchemes};
|
||||
static PIPE_NEXT_ID: AtomicUsize = AtomicUsize::new(1);
|
||||
|
||||
// TODO: SLOB?
|
||||
// Using BTreeMap as hashbrown doesn't have a const constructor.
|
||||
static PIPES: RwLock<BTreeMap<usize, Arc<Pipe>>> = RwLock::new(BTreeMap::new());
|
||||
|
||||
const MAX_QUEUE_SIZE: usize = 65536;
|
||||
|
||||
@@ -226,6 +226,7 @@ impl Handle {
|
||||
pub struct ProcScheme<const FULL: bool>;
|
||||
|
||||
static NEXT_ID: AtomicUsize = AtomicUsize::new(1);
|
||||
// Using BTreeMap as hashbrown doesn't have a const constructor.
|
||||
static HANDLES: RwLock<BTreeMap<usize, Handle>> = RwLock::new(BTreeMap::new());
|
||||
|
||||
#[derive(PartialEq)]
|
||||
|
||||
+4
-4
@@ -1,10 +1,10 @@
|
||||
use alloc::{
|
||||
boxed::Box,
|
||||
collections::BTreeMap,
|
||||
string::ToString,
|
||||
sync::Arc,
|
||||
vec::Vec,
|
||||
};
|
||||
use hashbrown::HashMap;
|
||||
use core::str;
|
||||
use core::sync::atomic::{AtomicUsize, Ordering};
|
||||
use spin::{Mutex, RwLock};
|
||||
@@ -54,7 +54,7 @@ pub struct RootScheme {
|
||||
scheme_ns: SchemeNamespace,
|
||||
scheme_id: SchemeId,
|
||||
next_id: AtomicUsize,
|
||||
handles: RwLock<BTreeMap<usize, Handle>>,
|
||||
handles: RwLock<HashMap<usize, Handle>>,
|
||||
}
|
||||
|
||||
impl RootScheme {
|
||||
@@ -63,7 +63,7 @@ impl RootScheme {
|
||||
scheme_ns,
|
||||
scheme_id,
|
||||
next_id: AtomicUsize::new(0),
|
||||
handles: RwLock::new(BTreeMap::new()),
|
||||
handles: RwLock::new(HashMap::new()),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -298,7 +298,7 @@ impl KernelScheme for RootScheme {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fn kfstat(&self, file: usize, buf: UserSliceWo) -> Result<()> {
|
||||
let handle = {
|
||||
let handles = self.handles.read();
|
||||
|
||||
@@ -22,6 +22,7 @@ struct Handle {
|
||||
flags: usize,
|
||||
}
|
||||
|
||||
// Using BTreeMap as hashbrown doesn't have a const constructor.
|
||||
static HANDLES: RwLock<BTreeMap<usize, Handle>> = RwLock::new(BTreeMap::new());
|
||||
|
||||
/// Add to the input queue
|
||||
|
||||
@@ -36,6 +36,7 @@ type SysFn = fn() -> Result<Vec<u8>>;
|
||||
/// System information scheme
|
||||
pub struct SysScheme;
|
||||
static NEXT_ID: AtomicUsize = AtomicUsize::new(1);
|
||||
// Using BTreeMap as hashbrown doesn't have a const constructor.
|
||||
static HANDLES: RwLock<BTreeMap<usize, Handle>> = RwLock::new(BTreeMap::new());
|
||||
|
||||
const FILES: &[(&'static str, SysFn)] = &[
|
||||
|
||||
@@ -13,6 +13,7 @@ use crate::time;
|
||||
use super::{GlobalSchemes, KernelScheme, CallerCtx, OpenResult};
|
||||
|
||||
static NEXT_ID: AtomicUsize = AtomicUsize::new(1);
|
||||
// Using BTreeMap as hashbrown doesn't have a const constructor.
|
||||
static HANDLES: RwLock<BTreeMap<usize, usize>> = RwLock::new(BTreeMap::new());
|
||||
|
||||
pub struct TimeScheme;
|
||||
|
||||
+3
-4
@@ -1,13 +1,12 @@
|
||||
use alloc::collections::btree_map::Entry;
|
||||
use alloc::sync::{Arc, Weak};
|
||||
use alloc::boxed::Box;
|
||||
use alloc::collections::BTreeMap;
|
||||
use alloc::vec::Vec;
|
||||
use syscall::{SKMSG_FRETURNFD, SKMSG_PROVIDE_MMAP, MAP_FIXED_NOREPLACE, MunmapFlags, SKMSG_FOBTAINFD, FobtainFdFlags, SendFdFlags};
|
||||
use core::mem::size_of;
|
||||
use core::num::NonZeroUsize;
|
||||
use core::sync::atomic::{AtomicBool, Ordering};
|
||||
use core::{mem, usize};
|
||||
use hashbrown::hash_map::{Entry, HashMap};
|
||||
use spin::{Mutex, RwLock};
|
||||
|
||||
use crate::context::context::HardBlockedReason;
|
||||
@@ -37,7 +36,7 @@ pub struct UserInner {
|
||||
next_id: Mutex<u64>,
|
||||
context: Weak<RwLock<Context>>,
|
||||
todo: WaitQueue<Packet>,
|
||||
states: Mutex<BTreeMap<u64, State>>,
|
||||
states: Mutex<HashMap<u64, State>>,
|
||||
unmounting: AtomicBool,
|
||||
}
|
||||
|
||||
@@ -71,7 +70,7 @@ impl UserInner {
|
||||
context,
|
||||
todo: WaitQueue::new(),
|
||||
unmounting: AtomicBool::new(false),
|
||||
states: Mutex::new(BTreeMap::new()),
|
||||
states: Mutex::new(HashMap::new()),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ use crate::sync::WaitCondition;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct WaitMap<K, V> {
|
||||
// Using BTreeMap as this depends on .keys() providing elements in sorted order.
|
||||
pub inner: Mutex<BTreeMap<K, V>>,
|
||||
pub condition: WaitCondition
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user