remove Mutex in server as Stream is now 'Sync'

This commit is contained in:
Marcel Märtens 2020-07-04 11:52:21 +02:00
parent c7ffe3dbeb
commit cbfd398035
7 changed files with 7 additions and 14 deletions

View File

@ -795,6 +795,7 @@ version = "0.1.0"
dependencies = [
"async-std",
"bincode",
"crossbeam-channel",
"futures",
"lazy_static",
"prometheus",

View File

@ -886,6 +886,7 @@ version = "0.1.0"
dependencies = [
"async-std",
"bincode",
"crossbeam-channel",
"futures",
"lazy_static",
"prometheus",

View File

@ -877,6 +877,7 @@ version = "0.1.0"
dependencies = [
"async-std",
"bincode",
"crossbeam-channel",
"futures",
"lazy_static",
"prometheus",

View File

@ -60,14 +60,10 @@ pub struct Participant {
///
/// Unlike [`Network`] and [`Participant`], `Streams` don't implement interior
/// mutability, as multiple threads don't need access to the same `Stream`.
/// [`Sync`] is not supported! In that case multiple `Streams` should be used
/// instead. However it's still possible to [`Send`] `Streams`.
///
/// [`Networks`]: crate::api::Network
/// [`open`]: Participant::open
/// [`opened`]: Participant::opened
/// [`Send`]: std::marker::Send
/// [`Sync`]: std::marker::Sync
#[derive(Debug)]
pub struct Stream {
pid: Pid,

View File

@ -7,7 +7,7 @@ use vek::*;
pub struct Client {
pub client_state: ClientState,
pub singleton_stream: std::sync::Mutex<Stream>,
pub singleton_stream: Stream,
pub last_ping: f64,
pub login_msg_sent: bool,
}
@ -17,9 +17,7 @@ impl Component for Client {
}
impl Client {
pub fn notify(&mut self, msg: ServerMsg) {
let _ = self.singleton_stream.lock().unwrap().send(msg);
}
pub fn notify(&mut self, msg: ServerMsg) { let _ = self.singleton_stream.send(msg); }
pub fn is_registered(&self) -> bool {
match self.client_state {
@ -39,16 +37,12 @@ impl Client {
self.client_state = new_state;
let _ = self
.singleton_stream
.lock()
.unwrap()
.send(ServerMsg::StateAnswer(Ok(new_state)));
}
pub fn error_state(&mut self, error: RequestStateError) {
let _ = self
.singleton_stream
.lock()
.unwrap()
.send(ServerMsg::StateAnswer(Err((error, self.client_state))));
}
}

View File

@ -601,7 +601,7 @@ impl Server {
let mut client = Client {
client_state: ClientState::Connected,
singleton_stream: std::sync::Mutex::new(singleton_stream),
singleton_stream,
last_ping: self.state.get_time(),
login_msg_sent: false,
};

View File

@ -57,7 +57,7 @@ impl Sys {
settings: &Read<'_, ServerSettings>,
) -> Result<(), crate::error::Error> {
loop {
let msg = client.singleton_stream.lock().unwrap().recv().await?;
let msg = client.singleton_stream.recv().await?;
*cnt += 1;
match msg {
// Go back to registered state (char selection screen)