Platform.Linux.swift 964 B

12345678910111213141516171819202122232425262728293031323334353637
  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 class Foundation.Thread
  10. extension Thread {
  11. static func setThreadLocalStorageValue<T: AnyObject>(_ value: T?, forKey key: String) {
  12. let currentThread = Thread.current
  13. var threadDictionary = currentThread.threadDictionary
  14. if let newValue = value {
  15. threadDictionary[key] = newValue
  16. }
  17. else {
  18. threadDictionary[key] = nil
  19. }
  20. currentThread.threadDictionary = threadDictionary
  21. }
  22. static func getThreadLocalStorageValueForKey<T: AnyObject>(_ key: String) -> T? {
  23. let currentThread = Thread.current
  24. let threadDictionary = currentThread.threadDictionary
  25. return threadDictionary[key] as? T
  26. }
  27. }
  28. #endif