Platform.Linux.swift 804 B

1234567891011121314151617181920212223242526272829303132
  1. //
  2. // Platform.Linux.swift
  3. // Platform
  4. //
  5. // Created by Krunoslav Zaher on 12/29/15.
  6. // Copyright © 2015 Krunoslav Zaher. All rights reserved.
  7. //
  8. #if os(Linux)
  9. import Foundation
  10. extension Thread {
  11. static func setThreadLocalStorageValue<T: AnyObject>(_ value: T?, forKey key: String) {
  12. if let newValue = value {
  13. Thread.current.threadDictionary[key] = newValue
  14. }
  15. else {
  16. Thread.current.threadDictionary[key] = nil
  17. }
  18. }
  19. static func getThreadLocalStorageValueForKey<T: AnyObject>(_ key: String) -> T? {
  20. let currentThread = Thread.current
  21. let threadDictionary = currentThread.threadDictionary
  22. return threadDictionary[key] as? T
  23. }
  24. }
  25. #endif