mirror of
https://github.com/callumio/suck.git
synced 2025-12-17 03:29:21 +00:00
Remove unnecessary Mutex
This commit is contained in:
parent
9843f2904c
commit
68369a7e4b
4 changed files with 12 additions and 6 deletions
|
|
@ -1,3 +1,4 @@
|
|||
use std::sync::atomic::{AtomicBool, Ordering};
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
use crate::error::Error;
|
||||
|
|
@ -12,7 +13,7 @@ where
|
|||
{
|
||||
pub(crate) request_tx: ST,
|
||||
pub(crate) response_rx: SR,
|
||||
pub(crate) closed: Mutex<bool>,
|
||||
pub(crate) closed: AtomicBool,
|
||||
pub(crate) _phantom: std::marker::PhantomData<T>,
|
||||
}
|
||||
|
||||
|
|
@ -127,7 +128,7 @@ where
|
|||
/// Get the current value from the producer
|
||||
pub fn get(&self) -> Result<T, Error> {
|
||||
// Check if locally marked as closed
|
||||
if *self.closed.lock().unwrap() {
|
||||
if self.closed.load(Ordering::Acquire) {
|
||||
return Err(Error::ChannelClosed);
|
||||
}
|
||||
|
||||
|
|
@ -152,7 +153,7 @@ where
|
|||
/// Close the channel from the consumer side
|
||||
pub fn close(&self) -> Result<(), Error> {
|
||||
// Mark locally as closed
|
||||
*self.closed.lock().unwrap() = true;
|
||||
self.closed.store(true, Ordering::Release);
|
||||
|
||||
// Send close request
|
||||
self.request_tx
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue