Skip to content

Commit

Permalink
Revert "ffi: duplicate the tokio runtime hack for Room"
Browse files Browse the repository at this point in the history
This reverts commit 1bbe2c4.
  • Loading branch information
bnjbvr committed Jun 5, 2024
1 parent cbcae18 commit d75b346
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 26 deletions.
3 changes: 1 addition & 2 deletions bindings/matrix-sdk-ffi/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ use ruma::{
use serde::{Deserialize, Serialize};
use serde_json::Value;
use tokio::sync::broadcast::error::RecvError;
use tracing::{debug, error, info};
use tracing::{debug, error};
use url::Url;

use super::{room::Room, session_verification::SessionVerificationController, RUNTIME};
Expand Down Expand Up @@ -179,7 +179,6 @@ impl Drop for Client {
// SAFETY: self.inner is never used again, which is the only requirement
// for ManuallyDrop::drop to be used safely.
unsafe {
info!("Dropping a client");
ManuallyDrop::drop(&mut self.inner);
}
}
Expand Down
28 changes: 5 additions & 23 deletions bindings/matrix-sdk-ffi/src/room.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{mem::ManuallyDrop, sync::Arc};
use std::sync::Arc;

use anyhow::{Context, Result};
use matrix_sdk::{
Expand All @@ -22,7 +22,7 @@ use ruma::{
EventId, Int, RoomAliasId, UserId,
};
use tokio::sync::RwLock;
use tracing::{error, info};
use tracing::error;

use super::RUNTIME;
use crate::{
Expand Down Expand Up @@ -58,35 +58,17 @@ pub(crate) type TimelineLock = Arc<RwLock<Option<Arc<Timeline>>>>;

#[derive(uniffi::Object)]
pub struct Room {
pub(super) inner: ManuallyDrop<SdkRoom>,
pub(super) inner: SdkRoom,
timeline: TimelineLock,
}

impl Drop for Room {
fn drop(&mut self) {
// A `Room` may be the ultimate holder of a `Client` reference, so it may
// release a `Client` too.
//
// Dropping the inner OlmMachine must happen within a tokio context
// because deadpool drops sqlite connections in the DB pool on tokio's
// blocking threadpool to avoid blocking async worker threads.
let _guard = RUNTIME.enter();
// SAFETY: self.inner is never used again, which is the only requirement
// for ManuallyDrop::drop to be used safely.
unsafe {
info!("Dropping a room");
ManuallyDrop::drop(&mut self.inner);
}
}
}

impl Room {
pub(crate) fn new(inner: SdkRoom) -> Self {
Room { inner: ManuallyDrop::new(inner), timeline: Default::default() }
Room { inner, timeline: Default::default() }
}

pub(crate) fn with_timeline(inner: SdkRoom, timeline: TimelineLock) -> Self {
Room { inner: ManuallyDrop::new(inner), timeline }
Room { inner, timeline }
}
}

Expand Down
2 changes: 1 addition & 1 deletion bindings/matrix-sdk-ffi/src/widget.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ impl WidgetDriver {
};

let capabilities_provider = CapabilitiesProviderWrap(capabilities_provider.into());
if let Err(()) = driver.run((*room.inner).clone(), capabilities_provider).await {
if let Err(()) = driver.run(room.inner.clone(), capabilities_provider).await {
// TODO
}
}
Expand Down

0 comments on commit d75b346

Please sign in to comment.