Skip to content

Commit 4e8ecb8

Browse files
committed
refactor(port_std): add a trait PortInstance to implement on a system type
1 parent 931a539 commit 4e8ecb8

File tree

1 file changed

+20
-5
lines changed
  • src/constance_port_std/src

1 file changed

+20
-5
lines changed

src/constance_port_std/src/lib.rs

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,16 @@ pub extern crate env_logger;
5050
/// defined as `0..NUM_INTERRUPT_LINES`
5151
pub const NUM_INTERRUPT_LINES: usize = 1024;
5252

53+
/// Implemented on a system type by [`use_port!`].
54+
///
55+
/// # Safety
56+
///
57+
/// Only meant to be implemented by [`use_port!`].
58+
#[doc(hidden)]
59+
pub unsafe trait PortInstance: Kernel + Port<PortTaskState = TaskState> {
60+
fn port_state() -> &'static State;
61+
}
62+
5363
/// The internal state of the port.
5464
///
5565
/// # Safety
@@ -394,9 +404,8 @@ impl State {
394404
self.dispatch_pending.store(true, Ordering::Relaxed);
395405
}
396406

397-
pub unsafe fn dispatch_first_task<System: Kernel>(&'static self) -> !
407+
pub unsafe fn dispatch_first_task<System: PortInstance>(&'static self) -> !
398408
where
399-
System: Port<PortTaskState = TaskState>,
400409
// FIXME: Work-around for <https://github.com/rust-lang/rust/issues/43475>
401410
System::TaskReadyQueue: std::borrow::BorrowMut<[StaticListHead<TaskCb<System>>]>,
402411
{
@@ -429,9 +438,8 @@ impl State {
429438
panic!("the system has been shut down");
430439
}
431440

432-
fn dispatcher_loop<System: Kernel>(&'static self)
441+
fn dispatcher_loop<System: PortInstance>(&'static self)
433442
where
434-
System: Port<PortTaskState = TaskState>,
435443
// FIXME: Work-around for <https://github.com/rust-lang/rust/issues/43475>
436444
System::TaskReadyQueue: std::borrow::BorrowMut<[StaticListHead<TaskCb<System>>]>,
437445
{
@@ -742,10 +750,17 @@ macro_rules! use_port {
742750
PendInterruptLineError, Port, QueryInterruptLineError, SetInterruptLinePriorityError,
743751
TaskCb, PortToKernel, PortInterrupts, PortThreading, UTicks, PortTimer,
744752
};
745-
use $crate::{State, TaskState};
753+
use $crate::{State, TaskState, PortInstance};
746754

747755
pub(super) static PORT_STATE: State = State::new();
748756

757+
unsafe impl PortInstance for $sys {
758+
#[inline]
759+
fn port_state() -> &'static State {
760+
&PORT_STATE
761+
}
762+
}
763+
749764
// Assume `$sys: Kernel`
750765
unsafe impl PortThreading for $sys {
751766
type PortTaskState = TaskState;

0 commit comments

Comments
 (0)