You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

37 lines
964 B

5 years ago
  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