blob: f892483567f4f606ac2ef6ec50f5e12e6ea4029b (
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 © 2022 Mullvad VPN AB. All rights reserved.
//
import Foundation
extension REST {
private static let nslock = NSLock()
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)"
}
}
|