Files
ShadowsocksX-NG/Pods/RxSwift/Platform/Platform.Darwin.swift

37 lines
1005 B
Swift
Raw Permalink Normal View History

2017-03-17 23:08:52 +08:00
//
// Platform.Darwin.swift
// Platform
//
// Created by Krunoslav Zaher on 12/29/15.
// Copyright © 2015 Krunoslav Zaher. All rights reserved.
//
#if os(macOS) || os(iOS) || os(tvOS) || os(watchOS)
import Darwin
2017-03-20 21:26:25 +08:00
import class Foundation.Thread
import protocol Foundation.NSCopying
2017-03-17 23:08:52 +08:00
extension Thread {
2019-09-10 14:30:51 +08:00
static func setThreadLocalStorageValue<T: AnyObject>(_ value: T?, forKey key: NSCopying) {
2017-03-17 23:08:52 +08:00
let currentThread = Thread.current
let threadDictionary = currentThread.threadDictionary
if let newValue = value {
threadDictionary[key] = newValue
}
else {
threadDictionary[key] = nil
}
}
2019-09-10 14:30:51 +08:00
2017-03-20 21:26:25 +08:00
static func getThreadLocalStorageValueForKey<T>(_ key: NSCopying) -> T? {
2017-03-17 23:08:52 +08:00
let currentThread = Thread.current
let threadDictionary = currentThread.threadDictionary
return threadDictionary[key] as? T
}
}
#endif