summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAndrej Mihajlov <and@mullvad.net>2022-03-16 12:41:27 +0100
committerAndrej Mihajlov <and@mullvad.net>2022-03-24 14:00:24 +0100
commit15b9b1fd707e60f208eccf344e80ed7c52233cd7 (patch)
tree7e6415788a060bca3405b8fc22c5611990db01a4
parent0cd501d8173087cc46593e6aaf00a15c0f3ca25f (diff)
downloadmullvadvpn-15b9b1fd707e60f208eccf344e80ed7c52233cd7.tar.xz
mullvadvpn-15b9b1fd707e60f208eccf344e80ed7c52233cd7.zip
Drop Locking extension
-rw-r--r--ios/MullvadVPN.xcodeproj/project.pbxproj8
-rw-r--r--ios/MullvadVPN/Locking.swift27
-rw-r--r--ios/MullvadVPN/Logging/OSLogHandler.swift19
-rw-r--r--ios/MullvadVPN/Operations/AsyncOperation.swift34
-rw-r--r--ios/MullvadVPN/Operations/ExclusivityController.swift38
5 files changed, 54 insertions, 72 deletions
diff --git a/ios/MullvadVPN.xcodeproj/project.pbxproj b/ios/MullvadVPN.xcodeproj/project.pbxproj
index 0f47216ca9..d18da9e902 100644
--- a/ios/MullvadVPN.xcodeproj/project.pbxproj
+++ b/ios/MullvadVPN.xcodeproj/project.pbxproj
@@ -109,7 +109,6 @@
5857F23024C843ED00CF6F47 /* ChainedError.swift in Sources */ = {isa = PBXBuildFile; fileRef = 58F840B12464491D0044E708 /* ChainedError.swift */; };
5857F23424C8443700CF6F47 /* AsyncOperation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 58E973DD24850EB600096F90 /* AsyncOperation.swift */; };
5857F23824C8446700CF6F47 /* AsyncBlockOperation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 580EE22324B3243100F9D8A1 /* AsyncBlockOperation.swift */; };
- 5857F23F24C844AD00CF6F47 /* Locking.swift in Sources */ = {isa = PBXBuildFile; fileRef = 58BA692D23E99EFF009DC256 /* Locking.swift */; };
5857F24324C8662600CF6F47 /* SelectLocationHeaderView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5857F24224C8662600CF6F47 /* SelectLocationHeaderView.swift */; };
5857F24724C882D700CF6F47 /* SelectLocationNavigationController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5857F24624C882D700CF6F47 /* SelectLocationNavigationController.swift */; };
585834F824D2BC1F00A8AF56 /* Logging in Frameworks */ = {isa = PBXBuildFile; productRef = 585834F724D2BC1F00A8AF56 /* Logging */; };
@@ -215,11 +214,9 @@
58B43C1925F77DB60002C8C3 /* ConnectMainContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 58B43C1825F77DB60002C8C3 /* ConnectMainContentView.swift */; };
58B67B482602079E008EF58E /* RelaySelector.swift in Sources */ = {isa = PBXBuildFile; fileRef = 58781CD422AFBA39009B9D8E /* RelaySelector.swift */; };
58B93A1326C3F13600A55733 /* TunnelState.swift in Sources */ = {isa = PBXBuildFile; fileRef = 58B93A1226C3F13600A55733 /* TunnelState.swift */; };
- 58B93A1826C54D7E00A55733 /* Locking.swift in Sources */ = {isa = PBXBuildFile; fileRef = 58BA692D23E99EFF009DC256 /* Locking.swift */; };
58B993B12608A34500BA7811 /* LoginContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 58B993B02608A34500BA7811 /* LoginContentView.swift */; };
58B9EB132488ED2100095626 /* AlertPresenter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 58B9EB122488ED2100095626 /* AlertPresenter.swift */; };
58B9EB152489139B00095626 /* DisplayChainedError.swift in Sources */ = {isa = PBXBuildFile; fileRef = 58B9EB142489139B00095626 /* DisplayChainedError.swift */; };
- 58BA692E23E99EFF009DC256 /* Locking.swift in Sources */ = {isa = PBXBuildFile; fileRef = 58BA692D23E99EFF009DC256 /* Locking.swift */; };
58BA693123EADA6A009DC256 /* SimulatorTunnelProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 58BA693023EADA6A009DC256 /* SimulatorTunnelProvider.swift */; };
58BA791B2578F092006FAEA0 /* WireGuardKit in Frameworks */ = {isa = PBXBuildFile; productRef = 58BA791A2578F092006FAEA0 /* WireGuardKit */; };
58BFA5C622A7C97F00A6173D /* RelayCacheTracker.swift in Sources */ = {isa = PBXBuildFile; fileRef = 58BFA5C522A7C97F00A6173D /* RelayCacheTracker.swift */; };
@@ -491,7 +488,6 @@
58B993B02608A34500BA7811 /* LoginContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoginContentView.swift; sourceTree = "<group>"; };
58B9EB122488ED2100095626 /* AlertPresenter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AlertPresenter.swift; sourceTree = "<group>"; };
58B9EB142489139B00095626 /* DisplayChainedError.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DisplayChainedError.swift; sourceTree = "<group>"; };
- 58BA692D23E99EFF009DC256 /* Locking.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Locking.swift; sourceTree = "<group>"; };
58BA693023EADA6A009DC256 /* SimulatorTunnelProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SimulatorTunnelProvider.swift; sourceTree = "<group>"; };
58BFA5C522A7C97F00A6173D /* RelayCacheTracker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RelayCacheTracker.swift; sourceTree = "<group>"; };
58BFA5CB22A7CE1F00A6173D /* ApplicationConfiguration.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ApplicationConfiguration.swift; sourceTree = "<group>"; };
@@ -880,7 +876,6 @@
58E20770274672CA00DE5D77 /* LaunchViewController.swift */,
58A1AA8623F43901009F7EA6 /* Location.swift */,
583DA21325FA4B5C00318683 /* LocationDataSource.swift */,
- 58BA692D23E99EFF009DC256 /* Locking.swift */,
5815039F24D6ECF200C9C50E /* Logging */,
58B993B02608A34500BA7811 /* LoginContentView.swift */,
58CE5E65224146200008646E /* LoginViewController.swift */,
@@ -1254,7 +1249,6 @@
5806766D27048E5500C858CB /* KeychainMatchLimit.swift in Sources */,
5819C2152726CC9400D6EC38 /* DataSourceSnapshot.swift in Sources */,
584E96BE240FD4DB00D3334F /* Location.swift in Sources */,
- 5857F23F24C844AD00CF6F47 /* Locking.swift in Sources */,
5857F23424C8443700CF6F47 /* AsyncOperation.swift in Sources */,
585DA8A626B14F5100B8C587 /* SSLPinningURLSessionDelegate.swift in Sources */,
58B0A2AC238EE6D500BC001D /* IPAddress+Codable.swift in Sources */,
@@ -1287,7 +1281,6 @@
5891BF5125E66B1E006D6FB0 /* UIBarButtonItem+KeyboardNavigation.swift in Sources */,
587B75412668FD7800DEF7E9 /* AccountExpiryNotificationProvider.swift in Sources */,
585DA89926B0329200B8C587 /* PacketTunnelStatus.swift in Sources */,
- 58BA692E23E99EFF009DC256 /* Locking.swift in Sources */,
5896CEF226972DEB00B0FAE8 /* AccountContentView.swift in Sources */,
5840250122B1124600E4CFEC /* IPAddress+Codable.swift in Sources */,
5857F24724C882D700CF6F47 /* SelectLocationNavigationController.swift in Sources */,
@@ -1467,7 +1460,6 @@
buildActionMask = 2147483647;
files = (
5850366825A47AC700A43E93 /* IPAddressRange+Codable.swift in Sources */,
- 58B93A1826C54D7E00A55733 /* Locking.swift in Sources */,
58FB865F26EA2E6D00F188BC /* LogFormatting.swift in Sources */,
5806767A27048E8800C858CB /* Keychain.swift in Sources */,
585DA89726B0328000B8C587 /* TunnelIPCResponse.swift in Sources */,
diff --git a/ios/MullvadVPN/Locking.swift b/ios/MullvadVPN/Locking.swift
deleted file mode 100644
index 8610f95309..0000000000
--- a/ios/MullvadVPN/Locking.swift
+++ /dev/null
@@ -1,27 +0,0 @@
-//
-// Locking.swift
-// MullvadVPN
-//
-// Created by pronebird on 04/02/2020.
-// Copyright © 2020 Mullvad VPN AB. All rights reserved.
-//
-
-import Foundation
-
-extension NSLock {
- func withCriticalBlock<T>(_ body: () -> T) -> T {
- lock()
- defer { unlock() }
-
- return body()
- }
-}
-
-extension NSRecursiveLock {
- func withCriticalBlock<T>(_ body: () -> T) -> T {
- lock()
- defer { unlock() }
-
- return body()
- }
-}
diff --git a/ios/MullvadVPN/Logging/OSLogHandler.swift b/ios/MullvadVPN/Logging/OSLogHandler.swift
index 34fd449c2f..8fcddcea15 100644
--- a/ios/MullvadVPN/Logging/OSLogHandler.swift
+++ b/ios/MullvadVPN/Logging/OSLogHandler.swift
@@ -26,15 +26,16 @@ struct OSLogHandler: LogHandler {
private static let registryLock = NSLock()
private static func getOSLog(subsystem: String, category: String) -> OSLog {
- return registryLock.withCriticalBlock {
- let key = RegistryKey(subsystem: subsystem, category: category)
- if let log = osLogRegistry[key] {
- return log
- } else {
- let newLog = OSLog(subsystem: subsystem, category: category)
- osLogRegistry[key] = newLog
- return newLog
- }
+ registryLock.lock()
+ defer { registryLock.unlock() }
+
+ let key = RegistryKey(subsystem: subsystem, category: category)
+ if let log = osLogRegistry[key] {
+ return log
+ } else {
+ let newLog = OSLog(subsystem: subsystem, category: category)
+ osLogRegistry[key] = newLog
+ return newLog
}
}
diff --git a/ios/MullvadVPN/Operations/AsyncOperation.swift b/ios/MullvadVPN/Operations/AsyncOperation.swift
index c4f628434d..62b6e6c36c 100644
--- a/ios/MullvadVPN/Operations/AsyncOperation.swift
+++ b/ios/MullvadVPN/Operations/AsyncOperation.swift
@@ -19,15 +19,24 @@ class AsyncOperation: Operation {
private var _isCancelled = false
final override var isExecuting: Bool {
- return stateLock.withCriticalBlock { _isExecuting }
+ stateLock.lock()
+ defer { stateLock.unlock() }
+
+ return _isExecuting
}
final override var isFinished: Bool {
- return stateLock.withCriticalBlock { _isFinished }
+ stateLock.lock()
+ defer { stateLock.unlock() }
+
+ return _isFinished
}
final override var isCancelled: Bool {
- return stateLock.withCriticalBlock { _isCancelled }
+ stateLock.lock()
+ defer { stateLock.unlock() }
+
+ return _isCancelled
}
final override var isAsynchronous: Bool {
@@ -35,9 +44,9 @@ class AsyncOperation: Operation {
}
final override func start() {
- stateLock.withCriticalBlock {
- setExecuting(true)
- }
+ stateLock.lock()
+ setExecuting(true)
+ stateLock.unlock()
main()
}
@@ -46,13 +55,14 @@ class AsyncOperation: Operation {
}
override func cancel() {
- stateLock.withCriticalBlock {
- if !_isCancelled {
- willChangeValue(for: \.isCancelled)
- _isCancelled = true
- didChangeValue(for: \.isCancelled)
- }
+ stateLock.lock()
+ if !_isCancelled {
+ willChangeValue(for: \.isCancelled)
+ _isCancelled = true
+ didChangeValue(for: \.isCancelled)
}
+ stateLock.unlock()
+
super.cancel()
}
diff --git a/ios/MullvadVPN/Operations/ExclusivityController.swift b/ios/MullvadVPN/Operations/ExclusivityController.swift
index cfbd3d7668..5e8fdaf97f 100644
--- a/ios/MullvadVPN/Operations/ExclusivityController.swift
+++ b/ios/MullvadVPN/Operations/ExclusivityController.swift
@@ -14,23 +14,27 @@ class ExclusivityController: NSObject {
private var categoriesByOperation: [Operation: [String]] = [:]
func addOperation(_ operation: Operation, categories: [String]) {
- lock.withCriticalBlock {
- categories.forEach { category in
- addOperation(operation, category: category)
- }
+ lock.lock()
- addObserverIfNeeded(operation: operation, categories: categories)
+ categories.forEach { category in
+ addOperation(operation, category: category)
}
+
+ addObserverIfNeeded(operation: operation, categories: categories)
+
+ lock.unlock()
}
func removeOperation(_ operation: Operation, categories: [String]) {
- lock.withCriticalBlock {
- categories.forEach { category in
- removeOperation(operation, category: category)
- }
+ lock.lock()
- removeObserverIfNeeded(operation: operation, categories: categories)
+ categories.forEach { category in
+ removeOperation(operation, category: category)
}
+
+ removeObserverIfNeeded(operation: operation, categories: categories)
+
+ lock.unlock()
}
override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
@@ -98,14 +102,16 @@ class ExclusivityController: NSObject {
}
private func operationDidFinish(_ operation: Operation) {
- lock.withCriticalBlock {
- let operationCategories = categoriesByOperation[operation] ?? []
+ lock.lock()
+
+ let operationCategories = categoriesByOperation[operation] ?? []
- removeObserverIfNeeded(operation: operation, categories: operationCategories)
+ removeObserverIfNeeded(operation: operation, categories: operationCategories)
- operationCategories.forEach { category in
- removeOperation(operation, category: category)
- }
+ operationCategories.forEach { category in
+ removeOperation(operation, category: category)
}
+
+ lock.unlock()
}
}