Skip to content

Commit e283ee2

Browse files
Darksonnojeda
authored andcommitted
rust: kernel: add reexports for macros
Currently, all macros are reexported with #[macro_export] only, which means that to access `new_work!` from the workqueue, you need to import it from the path `kernel::new_work` instead of importing it from the workqueue module like all other items in the workqueue. By adding reexports of the macros, it becomes possible to import the macros from the correct modules. It's still possible to import the macros from the root, but I don't think we can do anything about that. There is no functional change. This is merely a code cleanliness improvement. Signed-off-by: Alice Ryhl <[email protected]> Reviewed-by: Trevor Gross <[email protected]> Reviewed-by: Martin Rodriguez Reboredo <[email protected]> Tested-by: Boqun Feng <[email protected]> Link: https://lore.kernel.org/r/[email protected] [ Removed new `use kernel::prelude::*`s, reworded title. ] Signed-off-by: Miguel Ojeda <[email protected]>
1 parent ed6d0be commit e283ee2

File tree

6 files changed

+18
-17
lines changed

6 files changed

+18
-17
lines changed

rust/kernel/init.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
//!
3737
//! ```rust
3838
//! # #![allow(clippy::disallowed_names)]
39-
//! use kernel::{prelude::*, sync::Mutex, new_mutex};
39+
//! use kernel::sync::{new_mutex, Mutex};
4040
//! # use core::pin::Pin;
4141
//! #[pin_data]
4242
//! struct Foo {
@@ -56,7 +56,7 @@
5656
//!
5757
//! ```rust
5858
//! # #![allow(clippy::disallowed_names)]
59-
//! # use kernel::{prelude::*, sync::Mutex, new_mutex};
59+
//! # use kernel::sync::{new_mutex, Mutex};
6060
//! # use core::pin::Pin;
6161
//! # #[pin_data]
6262
//! # struct Foo {
@@ -79,7 +79,7 @@
7979
//! above method only works for types where you can access the fields.
8080
//!
8181
//! ```rust
82-
//! # use kernel::{new_mutex, sync::{Arc, Mutex}};
82+
//! # use kernel::sync::{new_mutex, Arc, Mutex};
8383
//! let mtx: Result<Arc<Mutex<usize>>> = Arc::pin_init(new_mutex!(42, "example::mtx"));
8484
//! ```
8585
//!

rust/kernel/sync.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ pub mod lock;
1313
mod locked_by;
1414

1515
pub use arc::{Arc, ArcBorrow, UniqueArc};
16-
pub use condvar::{CondVar, CondVarTimeoutResult};
17-
pub use lock::{mutex::Mutex, spinlock::SpinLock};
16+
pub use condvar::{new_condvar, CondVar, CondVarTimeoutResult};
17+
pub use lock::mutex::{new_mutex, Mutex};
18+
pub use lock::spinlock::{new_spinlock, SpinLock};
1819
pub use locked_by::LockedBy;
1920

2021
/// Represents a lockdep class. It's a wrapper around C's `lock_class_key`.

rust/kernel/sync/condvar.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ macro_rules! new_condvar {
2727
$crate::sync::CondVar::new($crate::optional_name!($($name)?), $crate::static_lock_class!())
2828
};
2929
}
30+
pub use new_condvar;
3031

3132
/// A conditional variable.
3233
///
@@ -44,8 +45,7 @@ macro_rules! new_condvar {
4445
/// The following is an example of using a condvar with a mutex:
4546
///
4647
/// ```
47-
/// use kernel::sync::{CondVar, Mutex};
48-
/// use kernel::{new_condvar, new_mutex};
48+
/// use kernel::sync::{new_condvar, new_mutex, CondVar, Mutex};
4949
///
5050
/// #[pin_data]
5151
/// pub struct Example {

rust/kernel/sync/lock/mutex.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ macro_rules! new_mutex {
1717
$inner, $crate::optional_name!($($name)?), $crate::static_lock_class!())
1818
};
1919
}
20+
pub use new_mutex;
2021

2122
/// A mutual exclusion primitive.
2223
///
@@ -35,7 +36,7 @@ macro_rules! new_mutex {
3536
/// contains an inner struct (`Inner`) that is protected by a mutex.
3637
///
3738
/// ```
38-
/// use kernel::{init::InPlaceInit, init::PinInit, new_mutex, pin_init, sync::Mutex};
39+
/// use kernel::sync::{new_mutex, Mutex};
3940
///
4041
/// struct Inner {
4142
/// a: u32,

rust/kernel/sync/lock/spinlock.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ macro_rules! new_spinlock {
1717
$inner, $crate::optional_name!($($name)?), $crate::static_lock_class!())
1818
};
1919
}
20+
pub use new_spinlock;
2021

2122
/// A spinlock.
2223
///
@@ -33,7 +34,7 @@ macro_rules! new_spinlock {
3334
/// contains an inner struct (`Inner`) that is protected by a spinlock.
3435
///
3536
/// ```
36-
/// use kernel::{init::InPlaceInit, init::PinInit, new_spinlock, pin_init, sync::SpinLock};
37+
/// use kernel::sync::{new_spinlock, SpinLock};
3738
///
3839
/// struct Inner {
3940
/// a: u32,

rust/kernel/workqueue.rs

+6-8
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@
3535
//! ```
3636
//! use kernel::prelude::*;
3737
//! use kernel::sync::Arc;
38-
//! use kernel::workqueue::{self, Work, WorkItem};
39-
//! use kernel::{impl_has_work, new_work};
38+
//! use kernel::workqueue::{self, impl_has_work, new_work, Work, WorkItem};
4039
//!
4140
//! #[pin_data]
4241
//! struct MyStruct {
@@ -78,8 +77,7 @@
7877
//! ```
7978
//! use kernel::prelude::*;
8079
//! use kernel::sync::Arc;
81-
//! use kernel::workqueue::{self, Work, WorkItem};
82-
//! use kernel::{impl_has_work, new_work};
80+
//! use kernel::workqueue::{self, impl_has_work, new_work, Work, WorkItem};
8381
//!
8482
//! #[pin_data]
8583
//! struct MyStruct {
@@ -147,6 +145,7 @@ macro_rules! new_work {
147145
$crate::workqueue::Work::new($crate::optional_name!($($name)?), $crate::static_lock_class!())
148146
};
149147
}
148+
pub use new_work;
150149

151150
/// A kernel work queue.
152151
///
@@ -405,9 +404,8 @@ impl<T: ?Sized, const ID: u64> Work<T, ID> {
405404
/// like this:
406405
///
407406
/// ```no_run
408-
/// use kernel::impl_has_work;
409407
/// use kernel::prelude::*;
410-
/// use kernel::workqueue::Work;
408+
/// use kernel::workqueue::{impl_has_work, Work};
411409
///
412410
/// struct MyWorkItem {
413411
/// work_field: Work<MyWorkItem, 1>,
@@ -475,9 +473,8 @@ pub unsafe trait HasWork<T, const ID: u64 = 0> {
475473
/// # Examples
476474
///
477475
/// ```
478-
/// use kernel::impl_has_work;
479476
/// use kernel::sync::Arc;
480-
/// use kernel::workqueue::{self, Work};
477+
/// use kernel::workqueue::{self, impl_has_work, Work};
481478
///
482479
/// struct MyStruct {
483480
/// work_field: Work<MyStruct, 17>,
@@ -509,6 +506,7 @@ macro_rules! impl_has_work {
509506
}
510507
)*};
511508
}
509+
pub use impl_has_work;
512510

513511
impl_has_work! {
514512
impl<T> HasWork<Self> for ClosureWork<T> { self.work }

0 commit comments

Comments
 (0)