Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 12 additions & 4 deletions kernel/src/benchmarks/oqueue.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MPL-2.0
//

#![allow(unsafe_code)]
use alloc::{
alloc::{alloc, handle_alloc_error},
Expand All @@ -26,7 +26,7 @@ use ostd::{
},
sync::Blocker,
},
sync::Waker,
sync::{Waker, WakerKey},
};

use super::{Benchmark, BenchmarkHarness, time, *};
Expand Down Expand Up @@ -301,7 +301,11 @@ impl<T: Copy + Send> Blocker for RigtorpProducer<T> {
true
}

fn prepare_to_wait(&self, _waker: &Arc<Waker>) {
fn enqueue(&self, _waker: &Arc<Waker>) -> WakerKey {
panic!("!");
}

fn remove(&self, _key: ostd::sync::WakerKey) {
panic!("!");
}
}
Expand All @@ -328,7 +332,11 @@ impl<T: Copy + Send> Blocker for RigtorpConsumer<T> {
true
}

fn prepare_to_wait(&self, _waker: &Arc<Waker>) {
fn enqueue(&self, _waker: &Arc<Waker>) -> WakerKey {
panic!("!");
}

fn remove(&self, _key: ostd::sync::WakerKey) {
panic!("!");
}
}
Expand Down
1 change: 1 addition & 0 deletions ostd/libs/orpc-macros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ proc-macro = true
proc-macro2 = "1.0"
quote = "1.0"
syn = { version = "1.0", features = ["full"] }
heck = "0.5.0"
57 changes: 56 additions & 1 deletion ostd/libs/orpc-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@
/// A set of macros for use with ORPC. The most important are the ORPC attribute macros `orpc_trait`, `orpc_server`, and
/// `orpc_impl`. The `select` macro (for waiting on multiple OQueues) is also defined here.
mod orpc_impl;
mod orpc_monitor;
mod orpc_server;
mod orpc_trait;
mod parsing_utils;
mod select;

use proc_macro::TokenStream;
use syn::{
ItemImpl, ItemStruct, ItemTrait, Path, Token, parse_macro_input, punctuated::Punctuated,
ItemImpl, ItemStruct, ItemTrait, Path, Token, Visibility, parse_macro_input,
punctuated::Punctuated,
};

/// Declare a trait as an ORPC trait that can be implemented by ORPC server.
Expand Down Expand Up @@ -130,6 +132,59 @@ pub fn orpc_impl(attr: TokenStream, input: TokenStream) -> TokenStream {
output.into()
}

/// Declare an [ORPC monitor type](`ostd::orpc::framework::monitor`). This is applied to the `impl`
/// for monitor methods.
///
/// This will generate the `*Monitor` type and methods on it to call methods and attach methods to
/// OQueues and a `start` method. The `start` method will initialize the monitor, giving it it's
/// initial state and associating it with a server. The default implementation spawns a thread which
/// handles all calls in an event loop.
///
/// ```ignore
/// pub struct XYZ {
/// x: i32,
/// }
///
/// #[orpc_monitor(pub)]
/// impl XYZ {
/// #[strong_observer]
/// pub fn update(&mut self, x: i32) -> Result<(), RPCError> {
/// // ...
/// Ok(())
/// }
///
/// #[consumer]
/// pub fn next(&mut self, _: ()) -> Result<(), RPCError> {
/// // ...
/// Ok(())
/// }
///
/// pub fn get(&mut self) -> Result<i32, RPCError> {
/// Ok(self.x)
/// }
/// }
/// ```
///
/// This will generate methods:
///
/// ```ignore
/// impl TestStateMonitor {
/// pub fn attach_update(&self, attachment: StrongObserver<i32>) -> Result<(), AttachmentError>;
/// pub fn update(&self, arg: i32) -> Result<(), RPCError>;
/// pub fn attach_next(&self, attachment: Consumer<()>) -> Result<(), AttachmentError>;
/// pub fn next(&self, arg: ()) -> Result<(), RPCError>;
/// pub fn get(&self) -> Result<i32, RPCError>;
/// fn start(&self, server: Arc<dyn Server>, state: TestState);
/// pub fn new() -> Self;
/// }
/// ```
#[proc_macro_attribute]
pub fn orpc_monitor(arg: TokenStream, input: TokenStream) -> TokenStream {
let input_impl = parse_macro_input!(input as ItemImpl);
let vis = parse_macro_input!(arg as Visibility);
orpc_monitor::orpc_monitor_impl(vis, input_impl).into()
}

// TODO: The select syntax (and name) should be revisited. This provides a good starting point, but it also has some
// issues, such as rust-analyzer refactors not working and not having a clean way to match over different message forms.

Expand Down
Loading
Loading