Skip to main content

kernel_api/syscall/
mod.rs

1//! Provides types for interacting with system calls.
2
3#[deprecated = "use the items in the `syscall` module root instead"]
4pub mod handle {
5	//! Provides types for working with userspace resources.
6	pub use super::handle_inner::*;
7}
8
9#[deprecated = "use the items in the `syscall` module root instead"]
10pub mod server {
11	//! Provides types for implementing servers.
12	pub use super::server_inner::*;
13}
14
15mod result;
16mod handle_inner;
17mod server_inner;
18
19pub use result::*;
20pub use handle_inner::*;
21pub use server_inner::*;
22
23use crate::channel;
24use crate::channel::Receiver;
25
26/// A map of pending async syscall results.
27///
28/// Each result is tied to the key that was used to submit the syscall.
29#[derive(Debug)]
30pub struct AsyncMap {
31	#[doc(hidden)]
32	pub queue: Receiver<(usize, Result<u128>)>,
33}
34
35impl AsyncMap {
36	/// Creates a new empty `AsyncMap`.
37	///
38	/// # Examples
39	///
40	/// ```
41	/// use kernel_api::syscall::AsyncMap;
42	///
43	/// let map = AsyncMap::new();
44	/// ```
45	#[must_use]
46	pub fn new() -> Self {
47		Self {
48			queue: channel::unbounded().1,
49		}
50	}
51
52	/// Adds a new result with the given `key` to the map.
53	///
54	/// # Examples
55	///
56	/// ```
57	/// use kernel_api::syscall::AsyncMap;
58	///
59	/// let mut map = AsyncMap::new();
60	/// map.push_result(5, Ok(0));
61	/// ```
62	pub fn push_result(&self, key: usize, result: Result<u128>) {
63		self.queue.push((key, result));
64	}
65}
66
67impl Default for AsyncMap {
68	fn default() -> Self {
69		Self::new()
70	}
71}