Skip to content

Commit

Permalink
Fix Swift 5.9 (#111)
Browse files Browse the repository at this point in the history
* Fix Swift 5.9

* Fix
  • Loading branch information
stephencelis authored Nov 27, 2024
1 parent dccdf5a commit 8d52279
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
7 changes: 6 additions & 1 deletion Sources/PerceptionCore/Internal/ThreadLocal.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@ import Foundation

struct _ThreadLocal {
#if os(WASI)
static nonisolated(unsafe) var value: UnsafeMutableRawPointer?
// NB: This can simply be 'nonisolated(unsafe)' when we drop support for Swift 5.9
static var value: UnsafeMutableRawPointer? {
get { _value.value }
set { _value.value = newValue }
}
private static let _value = UncheckedBox<UnsafeMutableRawPointer?>(nil)
#else
static var value: UnsafeMutableRawPointer? {
get { Thread.current.threadDictionary[Key()] as! UnsafeMutableRawPointer? }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
@usableFromInline final class UncheckedBox<Value>: @unchecked Sendable {
@usableFromInline var value: Value
@usableFromInline init(_ value: Value) {
self.value = value
}
}
@usableFromInline struct UncheckedSendable<Value>: @unchecked Sendable {
@usableFromInline let value: Value
@usableFromInline init(_ value: Value) {
Expand Down

0 comments on commit 8d52279

Please sign in to comment.