Skip to content

Commit 2f028fd

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 583dec9 commit 2f028fd

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-
cv.wait(&guard);
106+
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-
cv.wait(&guard);
128+
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
@@ -64,7 +64,7 @@ impl CondVar {
6464
/// [`CondVar::notify_all`], or when the thread receives a signal.
6565
///
6666
/// Returns whether there is a signal pending.
67-
pub fn wait<L: Lock>(&self, guard: &Guard<L>) -> bool {
67+
pub fn wait<L: Lock>(&self, guard: &mut Guard<L>) -> bool {
6868
let lock = guard.lock;
6969
let mut wait = MaybeUninit::<bindings::wait_queue_entry>::uninit();
7070

0 commit comments

Comments
 (0)