Skip to content

Commit

Permalink
[WIP] Add register_files() API
Browse files Browse the repository at this point in the history
  • Loading branch information
ileixe committed Jul 11, 2024
1 parent 553ad10 commit 9fa72a8
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ macro_rules! syscall {
#[macro_use]
mod future;
mod io;
mod runtime;
pub mod runtime;

pub mod buf;
pub mod fs;
Expand Down
4 changes: 2 additions & 2 deletions src/runtime/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::runtime::driver::{Handle, WeakHandle};
use std::cell::RefCell;

/// Owns the driver and resides in thread-local storage.
pub(crate) struct RuntimeContext {
pub struct RuntimeContext {
driver: RefCell<Option<driver::Handle>>,
}

Expand Down Expand Up @@ -41,7 +41,7 @@ impl RuntimeContext {
.unwrap_or(false)
}

pub(crate) fn handle(&self) -> Option<Handle> {
pub fn handle(&self) -> Option<Handle> {
self.driver.borrow().clone()
}

Expand Down
6 changes: 5 additions & 1 deletion src/runtime/driver/handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use crate::runtime::driver::op::{Completable, MultiCQEFuture, Op, Updateable};
use crate::runtime::driver::Driver;

#[derive(Clone)]
pub(crate) struct Handle {
pub struct Handle {
pub(super) inner: Rc<RefCell<Driver>>,
}

Expand Down Expand Up @@ -63,6 +63,10 @@ impl Handle {
self.inner.borrow_mut().unregister_buffers(buffers)
}

pub fn register_files(&self, fds: &[RawFd]) -> io::Result<()> {
self.inner.borrow_mut().register_files(fds)
}

pub(crate) fn submit_op_2(&self, sqe: squeue::Entry) -> usize {
self.inner.borrow_mut().submit_op_2(sqe)
}
Expand Down
6 changes: 6 additions & 0 deletions src/runtime/driver/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,12 @@ impl Driver {
))
}

pub(crate) fn register_files(&mut self, fds: &[RawFd]) -> io::Result<()> {
unsafe { self.uring.submitter().register_files(fds) }?;

Ok(())
}

pub(crate) fn submit_op_2(&mut self, sqe: squeue::Entry) -> usize {
let index = self.ops.insert();

Expand Down
4 changes: 2 additions & 2 deletions src/runtime/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub(crate) mod driver;
pub(crate) use context::RuntimeContext;

thread_local! {
pub(crate) static CONTEXT: RuntimeContext = RuntimeContext::new();
pub static CONTEXT: RuntimeContext = RuntimeContext::new();
}

/// The Runtime Executor
Expand All @@ -29,7 +29,7 @@ pub struct Runtime {
local: ManuallyDrop<LocalSet>,

/// Strong reference to the driver.
driver: driver::Handle,
pub driver: driver::Handle,
}

/// Spawns a new asynchronous task, returning a [`JoinHandle`] for it.
Expand Down

0 comments on commit 9fa72a8

Please sign in to comment.