From 927ae8959c8c4ed44cc78a8ffd1e8ed5b4609064 Mon Sep 17 00:00:00 2001 From: CPTforever Date: Thu, 1 Aug 2024 21:55:51 +0000 Subject: [PATCH] Added compaction to fd allocator --- src/lib/twizzler-abi/src/runtime/fs.rs | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/src/lib/twizzler-abi/src/runtime/fs.rs b/src/lib/twizzler-abi/src/runtime/fs.rs index 168be496..8fa4aa88 100644 --- a/src/lib/twizzler-abi/src/runtime/fs.rs +++ b/src/lib/twizzler-abi/src/runtime/fs.rs @@ -70,13 +70,23 @@ impl RustFsRuntime for MinimalRuntime { } }; } - let fd = get_fd_slots() - .lock() - .push(Arc::new(Mutex::new(FileDesc { - slot_id: 0, - pos: 0, - handle: handle - }))); + let mut binding = get_fd_slots() + .lock(); + + let elem = Arc::new(Mutex::new(FileDesc { + slot_id: 0, + pos: 0, + handle: handle + })); + + let fd = if binding.is_compact() { + binding.push(elem) + } + else { + let fd = binding.first_empty_slot_from(0).unwrap(); + binding.insert(fd, elem); + fd + }; Ok (fd.try_into().unwrap()) }