summaryrefslogtreecommitdiffhomepage
path: root/ios/MullvadVPN/Locking.swift
blob: 8610f95309762d37f2ae066bce24716002bc1bea (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
//
//  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()
    }
}