chore(bindings): Replace parking_lot RwLock by std RwLock

This commit is contained in:
Jonas Platte
2022-08-23 11:16:59 +02:00
committed by Jonas Platte
parent f83292fc75
commit 2313c099fa
6 changed files with 42 additions and 48 deletions

1
Cargo.lock generated
View File

@@ -2402,7 +2402,6 @@ dependencies = [
"futures-util",
"matrix-sdk",
"once_cell",
"parking_lot 0.12.1",
"sanitize-filename-reader-friendly",
"serde",
"serde_json",

View File

@@ -23,7 +23,6 @@ futures-core = "0.3.17"
futures-util = { version = "0.3.17", default-features = false }
matrix-sdk = { path = "../../crates/matrix-sdk", features = ["experimental-timeline", "markdown"] }
once_cell = "1.10.0"
parking_lot = "0.12.0"
sanitize-filename-reader-friendly = "2.2.1"
serde = { version = "1", features = ["derive"] }
serde_json = { version = "1" }

View File

@@ -1,11 +1,10 @@
use std::sync::Arc;
use std::sync::{Arc, RwLock};
use futures_util::future::join3;
use matrix_sdk::{
ruma::{OwnedDeviceId, UserId},
Session,
};
use parking_lot::RwLock;
use super::{client::Client, client_builder::ClientBuilder, RUNTIME};
@@ -66,7 +65,7 @@ impl AuthenticationService {
}
pub fn homeserver_details(&self) -> Option<Arc<HomeserverLoginDetails>> {
self.homeserver_details.read().clone()
self.homeserver_details.read().unwrap().clone()
}
/// Updates the service to authenticate with the homeserver for the
@@ -85,8 +84,8 @@ impl AuthenticationService {
RUNTIME.block_on(async move {
let details = Arc::new(self.details_from_client(&client).await?);
*self.client.write() = Some(client);
*self.homeserver_details.write() = Some(details);
*self.client.write().unwrap() = Some(client);
*self.homeserver_details.write().unwrap() = Some(details);
Ok(())
})
@@ -98,7 +97,7 @@ impl AuthenticationService {
username: String,
password: String,
) -> Result<Arc<Client>, AuthenticationError> {
match self.client.read().as_ref() {
match self.client.read().unwrap().as_ref() {
Some(client) => {
// Login and ask the server for the full user ID as this could be different from
// the username that was entered.
@@ -137,7 +136,7 @@ impl AuthenticationService {
token: String,
device_id: String,
) -> Result<Arc<Client>, AuthenticationError> {
match self.client.read().as_ref() {
match self.client.read().unwrap().as_ref() {
Some(client) => {
// Restore the client and ask the server for the full user ID as this
// could be different from the username that was entered.

View File

@@ -1,4 +1,4 @@
use std::sync::Arc;
use std::sync::{Arc, RwLock};
use anyhow::anyhow;
use matrix_sdk::{
@@ -16,7 +16,6 @@ use matrix_sdk::{
},
Client as MatrixClient, LoopCtrl, Session,
};
use parking_lot::RwLock;
use super::{
room::Room, session_verification::SessionVerificationController, ClientState, RestoreToken,
@@ -78,7 +77,7 @@ impl Client {
}
pub fn set_delegate(&self, delegate: Option<Box<dyn ClientDelegate>>) {
*self.delegate.write() = delegate;
*self.delegate.write().unwrap() = delegate;
}
/// The homeserver this client is configured to use.
@@ -137,18 +136,18 @@ impl Client {
client
.sync_with_callback(sync_settings, |sync_response| async {
if !state.read().has_first_synced {
state.write().has_first_synced = true
if !state.read().unwrap().has_first_synced {
state.write().unwrap().has_first_synced = true;
}
if state.read().should_stop_syncing {
state.write().is_syncing = false;
if state.read().unwrap().should_stop_syncing {
state.write().unwrap().is_syncing = false;
return LoopCtrl::Break;
} else if !state.read().is_syncing {
state.write().is_syncing = true;
} else if !state.read().unwrap().is_syncing {
state.write().unwrap().is_syncing = true;
}
if let Some(delegate) = &*delegate.read() {
if let Some(delegate) = &*delegate.read().unwrap() {
delegate.did_receive_sync_update()
}
@@ -169,17 +168,17 @@ impl Client {
/// Indication whether we've received a first sync response since
/// establishing the client (in memory)
pub fn has_first_synced(&self) -> bool {
self.state.read().has_first_synced
self.state.read().unwrap().has_first_synced
}
/// Indication whether we are currently syncing
pub fn is_syncing(&self) -> bool {
self.state.read().has_first_synced
self.state.read().unwrap().has_first_synced
}
/// Is this a guest account?
pub fn is_guest(&self) -> bool {
self.state.read().is_guest
self.state.read().unwrap().is_guest
}
pub fn restore_token(&self) -> anyhow::Result<String> {
@@ -189,7 +188,7 @@ impl Client {
Ok(serde_json::to_string(&RestoreToken {
session,
homeurl,
is_guest: self.state.read().is_guest,
is_guest: self.state.read().unwrap().is_guest,
})?)
})
}

View File

@@ -1,4 +1,4 @@
use std::sync::Arc;
use std::sync::{Arc, RwLock};
use anyhow::{bail, Result};
use futures_util::{pin_mut, StreamExt};
@@ -6,7 +6,6 @@ use matrix_sdk::{
room::Room as MatrixRoom,
ruma::{events::room::message::RoomMessageEventContent, UserId},
};
use parking_lot::RwLock;
use super::{
backward_stream::BackwardsStream,
@@ -40,7 +39,7 @@ impl Room {
}
pub fn set_delegate(&self, delegate: Option<Box<dyn RoomDelegate>>) {
*self.delegate.write() = delegate;
*self.delegate.write().unwrap() = delegate;
}
pub fn id(&self) -> String {
@@ -115,11 +114,11 @@ impl Room {
}
pub fn start_live_event_listener(&self) -> Option<Arc<BackwardsStream>> {
if *self.is_listening_to_live_events.read() {
if *self.is_listening_to_live_events.read().unwrap() {
return None;
}
*self.is_listening_to_live_events.write() = true;
*self.is_listening_to_live_events.write().unwrap() = true;
let room = self.room.clone();
let delegate = self.delegate.clone();
@@ -133,11 +132,11 @@ impl Room {
pin_mut!(forward_stream);
while let Some(sync_event) = forward_stream.next().await {
if !(*is_listening_to_live_events.read()) {
if !(*is_listening_to_live_events.read().unwrap()) {
return;
}
if let Some(delegate) = &*delegate.read() {
if let Some(delegate) = &*delegate.read().unwrap() {
if let Some(message) = sync_event_to_message(sync_event) {
delegate.did_receive_message(message)
}
@@ -148,7 +147,7 @@ impl Room {
}
pub fn stop_live_event_listener(&self) {
*self.is_listening_to_live_events.write() = false;
*self.is_listening_to_live_events.write().unwrap() = false;
}
pub fn send(&self, msg: Arc<RoomMessageEventContent>, txn_id: Option<String>) -> Result<()> {

View File

@@ -1,4 +1,4 @@
use std::sync::Arc;
use std::sync::{Arc, RwLock};
use matrix_sdk::{
encryption::{
@@ -10,7 +10,6 @@ use matrix_sdk::{
events::{key::verification::VerificationMethod, AnyToDeviceEvent},
},
};
use parking_lot::RwLock;
use super::RUNTIME;
@@ -55,7 +54,7 @@ impl SessionVerificationController {
}
pub fn set_delegate(&self, delegate: Option<Box<dyn SessionVerificationControllerDelegate>>) {
*self.delegate.write() = delegate;
*self.delegate.write().unwrap() = delegate;
}
pub fn is_verified(&self) -> bool {
@@ -67,7 +66,7 @@ impl SessionVerificationController {
let methods = vec![VerificationMethod::SasV1];
let verification_request =
self.user_identity.request_verification_with_methods(methods).await?;
*self.verification_request.write() = Some(verification_request);
*self.verification_request.write().unwrap() = Some(verification_request);
Ok(())
})
@@ -75,7 +74,7 @@ impl SessionVerificationController {
pub fn approve_verification(&self) -> anyhow::Result<()> {
RUNTIME.block_on(async move {
let sas_verification = self.sas_verification.read().clone();
let sas_verification = self.sas_verification.read().unwrap().clone();
if let Some(sas_verification) = sas_verification {
sas_verification.confirm().await?;
}
@@ -86,7 +85,7 @@ impl SessionVerificationController {
pub fn decline_verification(&self) -> anyhow::Result<()> {
RUNTIME.block_on(async move {
let sas_verification = self.sas_verification.read().clone();
let sas_verification = self.sas_verification.read().unwrap().clone();
if let Some(sas_verification) = sas_verification {
sas_verification.mismatch().await?;
}
@@ -97,7 +96,7 @@ impl SessionVerificationController {
pub fn cancel_verification(&self) -> anyhow::Result<()> {
RUNTIME.block_on(async move {
let verification_request = self.verification_request.read().clone();
let verification_request = self.verification_request.read().unwrap().clone();
if let Some(verification) = verification_request {
verification.cancel().await?;
}
@@ -122,7 +121,7 @@ impl SessionVerificationController {
return;
}
if let Some(delegate) = &*self.delegate.read() {
if let Some(delegate) = &*self.delegate.read().unwrap() {
delegate.did_cancel()
}
}
@@ -131,9 +130,9 @@ impl SessionVerificationController {
return;
}
if let Some(sas_verification) = &*sas_verification.read() {
if let Some(sas_verification) = &*sas_verification.read().unwrap() {
if let Some(emojis) = sas_verification.emoji() {
if let Some(delegate) = &*self.delegate.read() {
if let Some(delegate) = &*self.delegate.read().unwrap() {
let emojis = emojis
.iter()
.map(|e| {
@@ -146,10 +145,10 @@ impl SessionVerificationController {
delegate.did_receive_verification_data(emojis);
}
} else if let Some(delegate) = &*self.delegate.read() {
} else if let Some(delegate) = &*self.delegate.read().unwrap() {
delegate.did_fail()
}
} else if let Some(delegate) = &*self.delegate.read() {
} else if let Some(delegate) = &*self.delegate.read().unwrap() {
delegate.did_fail()
}
}
@@ -158,7 +157,7 @@ impl SessionVerificationController {
return;
}
if let Some(delegate) = &*self.delegate.read() {
if let Some(delegate) = &*self.delegate.read().unwrap() {
delegate.did_finish()
}
}
@@ -168,7 +167,7 @@ impl SessionVerificationController {
}
fn is_transaction_id_valid(&self, transaction_id: String) -> bool {
if let Some(verification) = &*self.verification_request.read() {
if let Some(verification) = &*self.verification_request.read().unwrap() {
return verification.flow_id() == transaction_id;
}
@@ -176,14 +175,14 @@ impl SessionVerificationController {
}
async fn start_sas_verification(&self) {
let verification_request = self.verification_request.read().clone();
let verification_request = self.verification_request.read().unwrap().clone();
if let Some(verification) = verification_request {
match verification.start_sas().await {
Ok(verification) => {
*self.sas_verification.write() = verification;
*self.sas_verification.write().unwrap() = verification;
}
Err(_) => {
if let Some(delegate) = &*self.delegate.read() {
if let Some(delegate) = &*self.delegate.read().unwrap() {
delegate.did_fail()
}
}