Skip to content

Commit

Permalink
Added compaction to fd allocator
Browse files Browse the repository at this point in the history
  • Loading branch information
CPTforever committed Aug 1, 2024
1 parent 38eb2c1 commit 927ae89
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions src/lib/twizzler-abi/src/runtime/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
Expand Down

0 comments on commit 927ae89

Please sign in to comment.