Skip to content

Commit cba5a29

Browse files
committed
remove Swift 5
1 parent 7a13942 commit cba5a29

15 files changed

+21
-791
lines changed

.github/workflows/build.yml

Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -55,33 +55,6 @@ jobs:
5555
- name: Test
5656
run: swift test --skip-build
5757

58-
xcode_15_4:
59-
runs-on: macos-14
60-
env:
61-
DEVELOPER_DIR: /Applications/Xcode_15.4.app/Contents/Developer
62-
steps:
63-
- name: Checkout
64-
uses: actions/checkout@v4
65-
- name: Version
66-
run: swift --version
67-
- name: Build
68-
run: swift build --build-tests
69-
- name: Test
70-
run: swift test --skip-build
71-
72-
linux_swift_5_10:
73-
runs-on: ubuntu-latest
74-
container: swift:5.10
75-
steps:
76-
- name: Checkout
77-
uses: actions/checkout@v4
78-
- name: Version
79-
run: swift --version
80-
- name: Build
81-
run: swift build --build-tests
82-
- name: Test
83-
run: swift test --skip-build
84-
8558
linux_swift_6_0:
8659
runs-on: ubuntu-latest
8760
container: swift:6.0.3
@@ -151,16 +124,15 @@ jobs:
151124
- name: Build
152125
run: swift build --swift-sdk aarch64-unknown-linux-android24
153126

154-
windows_swift_6_1:
127+
windows_swift_6_2:
155128
runs-on: windows-latest
156129
steps:
157130
- name: Checkout
158131
uses: actions/checkout@v4
159132
- name: Install Swift
160133
uses: SwiftyLab/setup-swift@latest
161134
with:
162-
swift-version: "6.1.2"
163-
visual-studio-components: Microsoft.VisualStudio.Component.Windows11SDK.22621
135+
swift-version: "6.2"
164136
- name: Version
165137
run: swift --version
166138
- name: Build

[email protected]

Lines changed: 0 additions & 38 deletions
This file was deleted.

Sources/Mutex.swift renamed to Sources/Mutex+Darwin.swift

Lines changed: 6 additions & 116 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,13 @@
2929
// SOFTWARE.
3030
//
3131

32-
#if compiler(>=6)
32+
#if canImport(Darwin)
3333

34-
#if !canImport(WinSDK)
34+
import struct os.os_unfair_lock_t
35+
import struct os.os_unfair_lock
36+
import func os.os_unfair_lock_lock
37+
import func os.os_unfair_lock_unlock
38+
import func os.os_unfair_lock_trylock
3539

3640
// Backports the Swift 6 type Mutex<Value> to all Darwin platforms
3741
struct Mutex<Value: ~Copyable>: ~Copyable {
@@ -60,44 +64,6 @@ struct Mutex<Value: ~Copyable>: ~Copyable {
6064

6165
extension Mutex: @unchecked Sendable where Value: ~Copyable { }
6266

63-
#else
64-
65-
// Windows doesn't support ~Copyable yet
66-
67-
struct Mutex<Value>: @unchecked Sendable {
68-
let storage: Storage<Value>
69-
70-
init(_ initialValue: consuming sending Value) {
71-
self.storage = Storage(initialValue)
72-
}
73-
74-
borrowing func withLock<Result, E: Error>(
75-
_ body: (inout sending Value) throws(E) -> sending Result
76-
) throws(E) -> sending Result {
77-
storage.lock()
78-
defer { storage.unlock() }
79-
return try body(&storage.value)
80-
}
81-
82-
borrowing func withLockIfAvailable<Result, E: Error>(
83-
_ body: (inout sending Value) throws(E) -> sending Result
84-
) throws(E) -> sending Result? {
85-
guard storage.tryLock() else { return nil }
86-
defer { storage.unlock() }
87-
return try body(&storage.value)
88-
}
89-
}
90-
91-
#endif
92-
93-
#if canImport(Darwin)
94-
95-
import struct os.os_unfair_lock_t
96-
import struct os.os_unfair_lock
97-
import func os.os_unfair_lock_lock
98-
import func os.os_unfair_lock_unlock
99-
import func os.os_unfair_lock_trylock
100-
10167
final class Storage<Value: ~Copyable> {
10268
private let _lock: os_unfair_lock_t
10369
var value: Value
@@ -126,80 +92,4 @@ final class Storage<Value: ~Copyable> {
12692
}
12793
}
12894

129-
#elseif canImport(Glibc) || canImport(Musl) || canImport(Bionic)
130-
131-
#if canImport(Musl)
132-
import Musl
133-
#elseif canImport(Bionic)
134-
import Android
135-
#else
136-
import Glibc
137-
#endif
138-
139-
final class Storage<Value: ~Copyable> {
140-
private let _lock: UnsafeMutablePointer<pthread_mutex_t>
141-
142-
var value: Value
143-
144-
init(_ initialValue: consuming Value) {
145-
var attr = pthread_mutexattr_t()
146-
pthread_mutexattr_init(&attr)
147-
self._lock = .allocate(capacity: 1)
148-
let err = pthread_mutex_init(self._lock, &attr)
149-
precondition(err == 0, "pthread_mutex_init error: \(err)")
150-
self.value = initialValue
151-
}
152-
153-
func lock() {
154-
let err = pthread_mutex_lock(_lock)
155-
precondition(err == 0, "pthread_mutex_lock error: \(err)")
156-
}
157-
158-
func unlock() {
159-
let err = pthread_mutex_unlock(_lock)
160-
precondition(err == 0, "pthread_mutex_unlock error: \(err)")
161-
}
162-
163-
func tryLock() -> Bool {
164-
pthread_mutex_trylock(_lock) == 0
165-
}
166-
167-
deinit {
168-
let err = pthread_mutex_destroy(self._lock)
169-
precondition(err == 0, "pthread_mutex_destroy error: \(err)")
170-
self._lock.deallocate()
171-
}
172-
}
173-
174-
#elseif canImport(WinSDK)
175-
176-
import ucrt
177-
import WinSDK
178-
179-
final class Storage<Value> {
180-
private let _lock: UnsafeMutablePointer<SRWLOCK>
181-
182-
var value: Value
183-
184-
init(_ initialValue: Value) {
185-
self._lock = .allocate(capacity: 1)
186-
InitializeSRWLock(self._lock)
187-
self.value = initialValue
188-
}
189-
190-
func lock() {
191-
AcquireSRWLockExclusive(_lock)
192-
}
193-
194-
func unlock() {
195-
ReleaseSRWLockExclusive(_lock)
196-
}
197-
198-
func tryLock() -> Bool {
199-
TryAcquireSRWLockExclusive(_lock) != 0
200-
}
201-
}
202-
203-
#endif
204-
20595
#endif

0 commit comments

Comments
 (0)