Skip to content

Commit a5e8b60

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 63243de commit a5e8b60

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
@@ -101,10 +101,9 @@ impl KernelModule for RustExample {
101101
let cv = Pin::from(Box::try_new(unsafe { CondVar::new() })?);
102102
condvar_init!(cv.as_ref(), "RustExample::init::cv1");
103103
{
104-
let guard = data.lock();
105-
#[allow(clippy::while_immutable_condition)]
104+
let mut guard = data.lock();
106105
while *guard != 10 {
107-
let _ = cv.wait(&guard);
106+
let _ = cv.wait(&mut guard);
108107
}
109108
}
110109
cv.notify_one();
@@ -124,10 +123,9 @@ impl KernelModule for RustExample {
124123
let cv = Pin::from(Box::try_new(unsafe { CondVar::new() })?);
125124
condvar_init!(cv.as_ref(), "RustExample::init::cv2");
126125
{
127-
let guard = data.lock();
128-
#[allow(clippy::while_immutable_condition)]
126+
let mut guard = data.lock();
129127
while *guard != 10 {
130-
let _ = cv.wait(&guard);
128+
let _ = cv.wait(&mut guard);
131129
}
132130
}
133131
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)