mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
remove Mutex in server as Stream is now 'Sync'
This commit is contained in:
parent
c7ffe3dbeb
commit
cbfd398035
1
network/examples/chat/Cargo.lock
generated
1
network/examples/chat/Cargo.lock
generated
@ -795,6 +795,7 @@ version = "0.1.0"
|
||||
dependencies = [
|
||||
"async-std",
|
||||
"bincode",
|
||||
"crossbeam-channel",
|
||||
"futures",
|
||||
"lazy_static",
|
||||
"prometheus",
|
||||
|
1
network/examples/fileshare/Cargo.lock
generated
1
network/examples/fileshare/Cargo.lock
generated
@ -886,6 +886,7 @@ version = "0.1.0"
|
||||
dependencies = [
|
||||
"async-std",
|
||||
"bincode",
|
||||
"crossbeam-channel",
|
||||
"futures",
|
||||
"lazy_static",
|
||||
"prometheus",
|
||||
|
1
network/examples/network-speed/Cargo.lock
generated
1
network/examples/network-speed/Cargo.lock
generated
@ -877,6 +877,7 @@ version = "0.1.0"
|
||||
dependencies = [
|
||||
"async-std",
|
||||
"bincode",
|
||||
"crossbeam-channel",
|
||||
"futures",
|
||||
"lazy_static",
|
||||
"prometheus",
|
||||
|
@ -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,
|
||||
|
@ -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))));
|
||||
}
|
||||
}
|
||||
|
@ -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,
|
||||
};
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user