From 2012d2198b3fb03dd08a6a18272166d87873d3c9 Mon Sep 17 00:00:00 2001 From: Manos Pitsidianakis Date: Mon, 31 Mar 2025 15:28:04 +0300 Subject: [PATCH] video: don't needlessly clone Waker Clippy complains about Option::take() called on a temporary value: ```text error: called `Option::take()` on a temporary value --> vhost-device-video/src/stream.rs:125:30 | 125 | if let Some(waker) = self.waker().take() { | ^^^^^^^^^^^^^^^^^^^ | = note: `waker` creates a temporary value, so calling take() has no effect = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_option_take = note: `-D clippy::needless-option-take` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::needless_option_take)]` ``` But Waker is meant to be consumed when calling Waker::wake, so there's no need to clone temporary values. Move the .wake() call inside ResourceState's set_ready() method so we don't have to lock the mutex again. Signed-off-by: Manos Pitsidianakis --- staging/vhost-device-video/src/stream.rs | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/staging/vhost-device-video/src/stream.rs b/staging/vhost-device-video/src/stream.rs index e913ac6..ab8265c 100644 --- a/staging/vhost-device-video/src/stream.rs +++ b/staging/vhost-device-video/src/stream.rs @@ -63,6 +63,9 @@ impl SharedResourceState { pub fn set_ready(&mut self) { self.set_state(ResourceState::Ready); + if let Some(waker) = self.waker.take() { + waker.wake(); + } } fn set_state(&mut self, state: ResourceState) { @@ -122,9 +125,6 @@ impl Resource { pub fn set_ready(&mut self) { self.state.write().unwrap().set_ready(); - if let Some(waker) = self.waker().take() { - waker.wake(); - } } pub fn is_ready(&self) -> bool { @@ -138,10 +138,6 @@ impl Resource { pub fn set_queued(&mut self) { self.state.write().unwrap().set_queued(); } - - pub fn waker(&self) -> Option { - self.state.read().unwrap().waker.clone() - } } #[repr(u32)]