Skip to content

Commit

Permalink
Merge branch 'release/0.22.3/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
pixlwave committed Feb 24, 2022
2 parents f72d529 + c267289 commit a0c0b80
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 12 deletions.
7 changes: 7 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## Changes in 0.22.3 (2022-02-24)

🐛 Bugfixes

- Thread Safety: Replace all objc_sync_enter/exit methods with recursive locks. ([#5675](https://github.com/vector-im/element-ios/issues/5675))


## Changes in 0.22.2 (2022-02-22)

🙌 Improvements
Expand Down
2 changes: 1 addition & 1 deletion MatrixSDK.podspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Pod::Spec.new do |s|

s.name = "MatrixSDK"
s.version = "0.22.2"
s.version = "0.22.3"
s.summary = "The iOS SDK to build apps compatible with Matrix (https://www.matrix.org)"

s.description = <<-DESC
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public class MXThreadEventTimeline: NSObject, MXEventTimeline {

/// The current pending request
private var currentHttpOperation: MXHTTPOperation?
private let lockListeners = NSRecursiveLock()

private lazy var threadEventFilter: MXRoomEventFilter = {
let filter = MXRoomEventFilter()
Expand Down Expand Up @@ -439,9 +440,9 @@ public class MXThreadEventTimeline: NSObject, MXEventTimeline {

/// Thread safe access to listeners array
private func synchronizeListeners(_ block: () -> Void) {
objc_sync_enter(listeners)
lockListeners.lock()
defer { lockListeners.unlock() }
block()
objc_sync_exit(listeners)
}

private func fixRoomId(inEvents events: [MXEvent]) {
Expand Down
2 changes: 1 addition & 1 deletion MatrixSDK/MatrixSDKVersion.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@

#import <Foundation/Foundation.h>

NSString *const MatrixSDKVersion = @"0.22.2";
NSString *const MatrixSDKVersion = @"0.22.3";
12 changes: 6 additions & 6 deletions MatrixSDK/Threads/MXThreadingService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public class MXThreadingService: NSObject {

private weak var session: MXSession?

private let lockThreads = NSRecursiveLock()
private var threads: [String: MXThread] = [:]
private let multicastDelegate: MXMulticastDelegate<MXThreadingServiceDelegate> = MXMulticastDelegate()

Expand Down Expand Up @@ -110,10 +111,9 @@ public class MXThreadingService: NSObject {
/// - Parameter identifier: identifier of a thread
/// - Returns: thread instance if found, nil otherwise
public func thread(withId identifier: String) -> MXThread? {
objc_sync_enter(threads)
let result = threads[identifier]
objc_sync_exit(threads)
return result
lockThreads.lock()
defer { lockThreads.unlock() }
return threads[identifier]
}

public func createTempThread(withId identifier: String, roomId: String) -> MXThread {
Expand Down Expand Up @@ -308,9 +308,9 @@ public class MXThreadingService: NSObject {
}

private func saveThread(_ thread: MXThread) {
objc_sync_enter(threads)
lockThreads.lock()
defer { lockThreads.unlock() }
threads[thread.id] = thread
objc_sync_exit(threads)
}

// MARK: - Delegate
Expand Down
5 changes: 3 additions & 2 deletions MatrixSDK/Utils/MXMulticastDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class MXMulticastDelegate <T: AnyObject> {
/// Weakly referenced delegates
private let delegates: NSHashTable<T> = NSHashTable.weakObjects()
private let dispatchQueue: DispatchQueue
private let lockDelegates = NSRecursiveLock()

/// Initializer
/// - Parameter dispatchQueue: Queue to invoke delegate methods
Expand Down Expand Up @@ -70,9 +71,9 @@ public class MXMulticastDelegate <T: AnyObject> {

/// Thread safe access to delegates array
private func synchronizeDelegates(_ block: () -> Void) {
objc_sync_enter(delegates)
lockDelegates.lock()
defer { lockDelegates.unlock() }
block()
objc_sync_exit(delegates)
}

deinit {
Expand Down

0 comments on commit a0c0b80

Please sign in to comment.