Skip to content

Commit 36644d3

Browse files
committed
Make wait require a mutable reference to guard.
This fixes a clippy warning where it couldn't figure out how a variable could change.
1 parent a629f05 commit 36644d3

File tree

2 files changed

+5
-7
lines changed

2 files changed

+5
-7
lines changed

drivers/char/rust_example.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,9 @@ impl KernelModule for RustExample {
9999
let cv = Pin::from(Box::try_new(unsafe { CondVar::new() })?);
100100
condvar_init!(cv.as_ref(), "RustExample::init::cv1");
101101
{
102-
let guard = data.lock();
103-
#[allow(clippy::while_immutable_condition)]
102+
let mut guard = data.lock();
104103
while *guard != 10 {
105-
let _ = cv.wait(&guard);
104+
let _ = cv.wait(&mut guard);
106105
}
107106
}
108107
cv.notify_one();
@@ -122,10 +121,9 @@ impl KernelModule for RustExample {
122121
let cv = Pin::from(Box::try_new(unsafe { CondVar::new() })?);
123122
condvar_init!(cv.as_ref(), "RustExample::init::cv2");
124123
{
125-
let guard = data.lock();
126-
#[allow(clippy::while_immutable_condition)]
124+
let mut guard = data.lock();
127125
while *guard != 10 {
128-
let _ = cv.wait(&guard);
126+
let _ = cv.wait(&mut guard);
129127
}
130128
}
131129
cv.notify_one();

rust/kernel/sync/condvar.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ impl CondVar {
6565
///
6666
/// Returns whether there is a signal pending.
6767
#[must_use = "wait returns if a signal is pending, so the caller must check the return value"]
68-
pub fn wait<L: Lock>(&self, guard: &Guard<L>) -> bool {
68+
pub fn wait<L: Lock>(&self, guard: &mut Guard<L>) -> bool {
6969
let lock = guard.lock;
7070
let mut wait = MaybeUninit::<bindings::wait_queue_entry>::uninit();
7171

0 commit comments

Comments
 (0)