summaryrefslogtreecommitdiffhomepage
path: root/ios/MullvadREST/ApiHandlers/RESTTaskIdentifier.swift
blob: fc238a0921b48ee0c5c296adf57125ef2ff45646 (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
//
//  RESTTaskIdentifier.swift
//  MullvadREST
//
//  Created by pronebird on 16/04/2022.
//  Copyright © 2025 Mullvad VPN AB. All rights reserved.
//

import Foundation

extension REST {
    private static let nslock = NSLock()
    nonisolated(unsafe) private static var taskCount: UInt32 = 0

    static func getTaskIdentifier(name: String) -> String {
        nslock.lock()
        defer { nslock.unlock() }

        let (partialValue, isOverflow) = taskCount.addingReportingOverflow(1)
        let nextValue = isOverflow ? 1 : partialValue
        taskCount = nextValue

        return "\(name).\(nextValue)"
    }
}