From 5f29d42097c98323b159010bffd17143a2b632ea Mon Sep 17 00:00:00 2001 From: Donghyun Kim Date: Sun, 15 Sep 2024 12:07:59 +0900 Subject: [PATCH] Rename some variables --- rust_crate/src/channel.rs | 24 ++++++++++++------------ rust_crate/src/shutdown.rs | 12 ++++++------ 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/rust_crate/src/channel.rs b/rust_crate/src/channel.rs index 338c2e73..7a41c7df 100644 --- a/rust_crate/src/channel.rs +++ b/rust_crate/src/channel.rs @@ -35,15 +35,15 @@ impl SignalSender { /// message, it will be woken up. This method does not fail if the mutex /// is poisoned but simply ignores the failure. pub fn send(&self, msg: T) { - let mut inner = match self.inner.lock() { + let mut guard = match self.inner.lock() { Ok(inner) => inner, Err(poisoned) => poisoned.into_inner(), }; // Enqueue the message - inner.queue.push_back(msg); + guard.queue.push_back(msg); // Wake up the previous receiver making it receive `None`, if any - if let Some(waker) = inner.waker.take() { + if let Some(waker) = guard.waker.take() { waker.wake(); } } @@ -69,16 +69,16 @@ impl Clone for SignalReceiver { /// original receiver will no longer receive messages after this clone. /// This ensures only the most recent receiver can access the message queue. fn clone(&self) -> Self { - let mut inner = match self.inner.lock() { + let mut guard = match self.inner.lock() { Ok(inner) => inner, Err(poisoned) => poisoned.into_inner(), }; let new_receiver = SignalReceiver { inner: self.inner.clone(), - id: inner.active_receiver_id + 1, // Increment ID for new receiver + id: guard.active_receiver_id + 1, // Increment ID for new receiver }; - inner.active_receiver_id = new_receiver.id; - if let Some(waker) = inner.waker.take() { + guard.active_receiver_id = new_receiver.id; + if let Some(waker) = guard.waker.take() { waker.wake(); } new_receiver @@ -101,22 +101,22 @@ impl Future for RecvFuture { /// a message is sent. If this receiver is not the active receiver, it will /// return `None`. fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { - let mut inner = match self.inner.lock() { + let mut guard = match self.inner.lock() { Ok(inner) => inner, Err(poisoned) => poisoned.into_inner(), }; // Only allow the current active receiver to receive messages - if inner.active_receiver_id == self.receiver_id { - if let Some(msg) = inner.queue.pop_front() { + if guard.active_receiver_id == self.receiver_id { + if let Some(msg) = guard.queue.pop_front() { // Check if more messages are in the queue - if !inner.queue.is_empty() { + if !guard.queue.is_empty() { // If so, wake the current task immediately cx.waker().wake_by_ref(); } Poll::Ready(Some(msg)) } else { - inner.waker = Some(cx.waker().clone()); + guard.waker = Some(cx.waker().clone()); Poll::Pending } } else { diff --git a/rust_crate/src/shutdown.rs b/rust_crate/src/shutdown.rs index c2fbe15c..7e2046b3 100644 --- a/rust_crate/src/shutdown.rs +++ b/rust_crate/src/shutdown.rs @@ -45,16 +45,16 @@ impl Event { /// This will wake up any threads or async tasks. #[cfg(not(target_family = "wasm"))] pub fn set(&self) { - let mut inner = match self.inner.lock() { + let mut guard = match self.inner.lock() { Ok(inner) => inner, Err(poisoned) => poisoned.into_inner(), }; - inner.flag = true; // Set the flag - inner.session += 1; // Increment the session count + guard.flag = true; // Set the flag + guard.session += 1; // Increment the session count // Wake all threads and async tasks when the event is set self.condvar.notify_all(); - for waker in inner.wakers.drain(..) { + for waker in guard.wakers.drain(..) { waker.wake(); } } @@ -64,11 +64,11 @@ impl Event { /// block until the flag is set again. #[cfg(all(not(target_family = "wasm"), debug_assertions))] pub fn clear(&self) { - let mut inner = match self.inner.lock() { + let mut guard = match self.inner.lock() { Ok(inner) => inner, Err(poisoned) => poisoned.into_inner(), }; - inner.flag = false; // Clear the flag + guard.flag = false; // Clear the flag } /// Blocks the current thread until the flag is set to `true`.