1111
1212#if canImport(Synchronization)
1313import Synchronization
14- #else
14+ #endif // canImport(Synchronization)
1515
1616#if canImport(os)
1717internal import os
@@ -28,7 +28,6 @@ internal import C.os.lock
2828import WinSDK
2929#endif // canImport(os)
3030
31- #endif // canImport(Synchronization)
3231
3332internal struct AtomicBox : Sendable , ~ Copyable {
3433 internal typealias BitwiseXorFunc = ( OutputConsumptionState ) -> OutputConsumptionState
@@ -37,21 +36,26 @@ internal struct AtomicBox: Sendable, ~Copyable {
3736
3837 internal init ( ) {
3938 #if canImport(Synchronization)
40- guard #available( macOS 15 , * ) else {
41- fatalError ( " Unexpected configuration " )
42- }
43- let box = Atomic ( UInt8 ( 0 ) )
44- self . storage = {
45- return { input in
46- return box. _bitwiseXor ( input)
47- }
48- }
39+ let hasSynchronization = true
4940 #else
50- let state = LockedState ( OutputConsumptionState ( rawValue: 0 ) )
51- self . storage = {
52- return state. _bitwiseXor
53- }
41+ let hasSynchronization = false
5442 #endif
43+
44+ if hasSynchronization, #available( macOS 15 , * ) {
45+ let box = Atomic ( UInt8 ( 0 ) )
46+ self . storage = {
47+ return { input in
48+ return box. _bitwiseXor ( input)
49+ }
50+ }
51+ } else {
52+ let state = LockedState ( OutputConsumptionState ( rawValue: 0 ) )
53+ self . storage = {
54+ return { input in
55+ return state. _bitwiseXor ( input)
56+ }
57+ }
58+ }
5559 }
5660
5761 internal func bitwiseXor(
@@ -78,7 +82,8 @@ extension Atomic where Value == UInt8 {
7882 self = Atomic ( initialValue. rawValue)
7983 }
8084}
81- #else
85+ #endif
86+
8287// Fallback to LockedState if `Synchronization` is not available
8388extension LockedState where State == OutputConsumptionState {
8489 init ( _ initialValue: OutputConsumptionState ) {
@@ -237,5 +242,3 @@ extension LockedState where State == Void {
237242}
238243
239244extension LockedState : @unchecked Sendable where State: Sendable { }
240-
241- #endif
0 commit comments