mirror of
https://github.com/yonaskolb/XcodeGen.git
synced 2024-09-11 12:56:03 +03:00
Fix data races in SettingsBuilder.
**Reason:** - `configFileSettings` and `settingPresetSettings` caches were just global dictionaries. Data races were taken place at these points when multiple projects are generated in parallel. **Content:** - Dictionaries for caches moved to NSCache which is thread safe.
This commit is contained in:
parent
c1d5c65ae4
commit
74e99ecc51
37
Sources/XcodeGenKit/NSCacheExtensions.swift
Normal file
37
Sources/XcodeGenKit/NSCacheExtensions.swift
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
import XcodeProj
|
||||||
|
import Foundation
|
||||||
|
|
||||||
|
enum Cached<T> {
|
||||||
|
case cached(T)
|
||||||
|
case nothing
|
||||||
|
|
||||||
|
var value: T? {
|
||||||
|
switch self {
|
||||||
|
case let .cached(value): return value
|
||||||
|
case .nothing: return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
final class CacheContainer {
|
||||||
|
let value: Cached<BuildSettings>
|
||||||
|
|
||||||
|
init(value: Cached<BuildSettings>) {
|
||||||
|
self.value = value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
extension NSCache where KeyType == NSString, ObjectType == CacheContainer {
|
||||||
|
subscript(aKey: String) -> Cached<BuildSettings>? {
|
||||||
|
get {
|
||||||
|
object(forKey: aKey as NSString)?.value
|
||||||
|
}
|
||||||
|
set {
|
||||||
|
if let value = newValue {
|
||||||
|
setObject(CacheContainer(value: value), forKey: aKey as NSString)
|
||||||
|
} else {
|
||||||
|
removeObject(forKey: aKey as NSString)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -160,23 +160,11 @@ extension Project {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private enum Cached<T> {
|
|
||||||
case cached(T)
|
|
||||||
case nothing
|
|
||||||
|
|
||||||
var value: T? {
|
|
||||||
switch self {
|
|
||||||
case let .cached(value): return value
|
|
||||||
case .nothing: return nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// cached flattened xcconfig file settings
|
// cached flattened xcconfig file settings
|
||||||
private var configFileSettings: [String: Cached<BuildSettings>] = [:]
|
private var configFileSettings = NSCache<NSString, CacheContainer>()
|
||||||
|
|
||||||
// cached setting preset settings
|
// cached setting preset settings
|
||||||
private var settingPresetSettings: [String: Cached<BuildSettings>] = [:]
|
private var settingPresetSettings = NSCache<NSString, CacheContainer>()
|
||||||
|
|
||||||
extension SettingsPresetFile {
|
extension SettingsPresetFile {
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user