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 std::sync::{Arc, Mutex};
|
||||||
|
|
||||||
use crate::error::Error;
|
use crate::error::Error;
|
||||||
|
|
@ -12,7 +13,7 @@ where
|
||||||
{
|
{
|
||||||
pub(crate) request_tx: ST,
|
pub(crate) request_tx: ST,
|
||||||
pub(crate) response_rx: SR,
|
pub(crate) response_rx: SR,
|
||||||
pub(crate) closed: Mutex<bool>,
|
pub(crate) closed: AtomicBool,
|
||||||
pub(crate) _phantom: std::marker::PhantomData<T>,
|
pub(crate) _phantom: std::marker::PhantomData<T>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -127,7 +128,7 @@ where
|
||||||
/// Get the current value from the producer
|
/// Get the current value from the producer
|
||||||
pub fn get(&self) -> Result<T, Error> {
|
pub fn get(&self) -> Result<T, Error> {
|
||||||
// Check if locally marked as closed
|
// Check if locally marked as closed
|
||||||
if *self.closed.lock().unwrap() {
|
if self.closed.load(Ordering::Acquire) {
|
||||||
return Err(Error::ChannelClosed);
|
return Err(Error::ChannelClosed);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -152,7 +153,7 @@ where
|
||||||
/// Close the channel from the consumer side
|
/// Close the channel from the consumer side
|
||||||
pub fn close(&self) -> Result<(), Error> {
|
pub fn close(&self) -> Result<(), Error> {
|
||||||
// Mark locally as closed
|
// Mark locally as closed
|
||||||
*self.closed.lock().unwrap() = true;
|
self.closed.store(true, Ordering::Release);
|
||||||
|
|
||||||
// Send close request
|
// Send close request
|
||||||
self.request_tx
|
self.request_tx
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
use std::sync::atomic::AtomicBool;
|
||||||
|
|
||||||
#[cfg(feature = "sync-crossbeam")]
|
#[cfg(feature = "sync-crossbeam")]
|
||||||
use crate::sync::traits::{ChannelError, ChannelReceiver, ChannelSender, ChannelType};
|
use crate::sync::traits::{ChannelError, ChannelReceiver, ChannelSender, ChannelType};
|
||||||
use crate::types;
|
use crate::types;
|
||||||
|
|
@ -70,7 +72,7 @@ impl<T> CrossbeamSuck<T> {
|
||||||
let sucker = crate::Sucker {
|
let sucker = crate::Sucker {
|
||||||
request_tx,
|
request_tx,
|
||||||
response_rx,
|
response_rx,
|
||||||
closed: std::sync::Mutex::new(false),
|
closed: AtomicBool::new(false),
|
||||||
_phantom: std::marker::PhantomData,
|
_phantom: std::marker::PhantomData,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
use std::sync::atomic::AtomicBool;
|
||||||
|
|
||||||
#[cfg(feature = "sync-flume")]
|
#[cfg(feature = "sync-flume")]
|
||||||
use crate::sync::traits::{ChannelError, ChannelReceiver, ChannelSender, ChannelType};
|
use crate::sync::traits::{ChannelError, ChannelReceiver, ChannelSender, ChannelType};
|
||||||
use crate::types;
|
use crate::types;
|
||||||
|
|
@ -70,7 +72,7 @@ impl<T> FlumeSuck<T> {
|
||||||
let sucker = crate::Sucker {
|
let sucker = crate::Sucker {
|
||||||
request_tx,
|
request_tx,
|
||||||
response_rx,
|
response_rx,
|
||||||
closed: std::sync::Mutex::new(false),
|
closed: AtomicBool::new(false),
|
||||||
_phantom: std::marker::PhantomData,
|
_phantom: std::marker::PhantomData,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
use crate::sync::traits::{ChannelError, ChannelReceiver, ChannelSender, ChannelType};
|
use crate::sync::traits::{ChannelError, ChannelReceiver, ChannelSender, ChannelType};
|
||||||
use crate::types;
|
use crate::types;
|
||||||
|
use std::sync::atomic::AtomicBool;
|
||||||
#[cfg(feature = "sync-std")]
|
#[cfg(feature = "sync-std")]
|
||||||
use std::sync::mpsc;
|
use std::sync::mpsc;
|
||||||
|
|
||||||
|
|
@ -68,7 +69,7 @@ impl<T> StdSuck<T> {
|
||||||
let sucker = crate::Sucker {
|
let sucker = crate::Sucker {
|
||||||
request_tx,
|
request_tx,
|
||||||
response_rx,
|
response_rx,
|
||||||
closed: std::sync::Mutex::new(false),
|
closed: AtomicBool::new(false),
|
||||||
_phantom: std::marker::PhantomData,
|
_phantom: std::marker::PhantomData,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue