Skip to content

Commit

Permalink
task: add manual Sync impl for VerificationCache to avoid overflowing…
Browse files Browse the repository at this point in the history
… evaluation requirements
  • Loading branch information
bnjbvr committed Nov 20, 2024
1 parent 75cef7e commit cf03eea
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion crates/matrix-sdk-base/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ uniffi = ["dep:uniffi", "matrix-sdk-crypto?/uniffi", "matrix-sdk-common/uniffi"]
# Private feature, see
# https://github.com/matrix-org/matrix-rust-sdk/pull/3749#issuecomment-2312939823 for the gory
# details.
test-send-sync = []
test-send-sync = ["matrix-sdk-crypto?/test-send-sync"]

# "message-ids" feature doesn't do anything and is deprecated.
message-ids = []
Expand Down
5 changes: 5 additions & 0 deletions crates/matrix-sdk-crypto/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ experimental-algorithms = []
uniffi = ["dep:uniffi"]
_disable-minimum-rotation-period-ms = []

# Private feature, see
# https://github.com/matrix-org/matrix-rust-sdk/pull/3749#issuecomment-2312939823 for the gory
# details.
test-send-sync = []

# "message-ids" feature doesn't do anything and is deprecated.
message-ids = []

Expand Down
13 changes: 13 additions & 0 deletions crates/matrix-sdk-crypto/src/verification/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,19 @@ pub struct VerificationCache {
inner: Arc<VerificationCacheInner>,
}

// See https://github.com/matrix-org/matrix-rust-sdk/pull/3749#issuecomment-2312939823.
#[cfg(not(feature = "test-send-sync"))]
unsafe impl Sync for VerificationCache {}

#[cfg(feature = "test-send-sync")]
#[test]
// See https://github.com/matrix-org/matrix-rust-sdk/pull/3749#issuecomment-2312939823.
fn test_send_sync_for_room() {
fn assert_send_sync<T: Send + Sync>() {}

assert_send_sync::<VerificationCache>();
}

#[derive(Debug, Default)]
struct VerificationCacheInner {
verification: StdRwLock<BTreeMap<OwnedUserId, BTreeMap<String, Verification>>>,
Expand Down

0 comments on commit cf03eea

Please sign in to comment.