Skip to content

Commit ee5eedc

Browse files
committed
Use Bionic module from new Android overlay in Swift 6 instead
The new module and overlay were merged into Swift 6 in swiftlang/swift#74758.
1 parent e83857c commit ee5eedc

File tree

2 files changed

+18
-9
lines changed

2 files changed

+18
-9
lines changed

Sources/AsyncAlgorithms/Locking.swift

+7-5
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,16 @@ import Glibc
1717
import Musl
1818
#elseif canImport(WinSDK)
1919
import WinSDK
20+
#elseif canImport(Bionic)
21+
import Bionic
2022
#else
2123
#error("Unsupported platform")
2224
#endif
2325

2426
internal struct Lock {
2527
#if canImport(Darwin)
2628
typealias Primitive = os_unfair_lock
27-
#elseif canImport(Glibc) || canImport(Musl)
29+
#elseif canImport(Glibc) || canImport(Musl) || canImport(Bionic)
2830
typealias Primitive = pthread_mutex_t
2931
#elseif canImport(WinSDK)
3032
typealias Primitive = SRWLOCK
@@ -42,7 +44,7 @@ internal struct Lock {
4244
fileprivate static func initialize(_ platformLock: PlatformLock) {
4345
#if canImport(Darwin)
4446
platformLock.initialize(to: os_unfair_lock())
45-
#elseif canImport(Glibc) || canImport(Musl)
47+
#elseif canImport(Glibc) || canImport(Musl) || canImport(Bionic)
4648
let result = pthread_mutex_init(platformLock, nil)
4749
precondition(result == 0, "pthread_mutex_init failed")
4850
#elseif canImport(WinSDK)
@@ -53,7 +55,7 @@ internal struct Lock {
5355
}
5456

5557
fileprivate static func deinitialize(_ platformLock: PlatformLock) {
56-
#if canImport(Glibc) || canImport(Musl)
58+
#if canImport(Glibc) || canImport(Musl) || canImport(Bionic)
5759
let result = pthread_mutex_destroy(platformLock)
5860
precondition(result == 0, "pthread_mutex_destroy failed")
5961
#endif
@@ -63,7 +65,7 @@ internal struct Lock {
6365
fileprivate static func lock(_ platformLock: PlatformLock) {
6466
#if canImport(Darwin)
6567
os_unfair_lock_lock(platformLock)
66-
#elseif canImport(Glibc) || canImport(Musl)
68+
#elseif canImport(Glibc) || canImport(Musl) || canImport(Bionic)
6769
pthread_mutex_lock(platformLock)
6870
#elseif canImport(WinSDK)
6971
AcquireSRWLockExclusive(platformLock)
@@ -75,7 +77,7 @@ internal struct Lock {
7577
fileprivate static func unlock(_ platformLock: PlatformLock) {
7678
#if canImport(Darwin)
7779
os_unfair_lock_unlock(platformLock)
78-
#elseif canImport(Glibc) || canImport(Musl)
80+
#elseif canImport(Glibc) || canImport(Musl) || canImport(Bionic)
7981
let result = pthread_mutex_unlock(platformLock)
8082
precondition(result == 0, "pthread_mutex_unlock failed")
8183
#elseif canImport(WinSDK)

Sources/AsyncSequenceValidation/TaskDriver.swift

+11-4
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ import Darwin
1717
import Glibc
1818
#elseif canImport(Musl)
1919
import Musl
20+
#elseif canImport(Bionic)
21+
import Bionic
2022
#elseif canImport(WinSDK)
2123
#error("TODO: Port TaskDriver threading to windows")
2224
#else
@@ -28,11 +30,16 @@ func start_thread(_ raw: UnsafeMutableRawPointer) -> UnsafeMutableRawPointer? {
2830
Unmanaged<TaskDriver>.fromOpaque(raw).takeRetainedValue().run()
2931
return nil
3032
}
31-
#elseif canImport(Glibc) || canImport(Musl)
33+
#elseif (canImport(Glibc) && !os(Android)) || canImport(Musl)
3234
func start_thread(_ raw: UnsafeMutableRawPointer?) -> UnsafeMutableRawPointer? {
3335
Unmanaged<TaskDriver>.fromOpaque(raw!).takeRetainedValue().run()
3436
return nil
3537
}
38+
#elseif os(Android)
39+
func start_thread(_ raw: UnsafeMutableRawPointer) -> UnsafeMutableRawPointer {
40+
Unmanaged<TaskDriver>.fromOpaque(raw).takeRetainedValue().run()
41+
return UnsafeMutableRawPointer(bitPattern: 0xdeadbee)!
42+
}
3643
#elseif canImport(WinSDK)
3744
#error("TODO: Port TaskDriver threading to windows")
3845
#endif
@@ -42,7 +49,7 @@ final class TaskDriver {
4249
let queue: WorkQueue
4350
#if canImport(Darwin)
4451
var thread: pthread_t?
45-
#elseif canImport(Glibc) || canImport(Musl)
52+
#elseif canImport(Glibc) || canImport(Musl) || canImport(Bionic)
4653
var thread = pthread_t()
4754
#elseif canImport(WinSDK)
4855
#error("TODO: Port TaskDriver threading to windows")
@@ -54,7 +61,7 @@ final class TaskDriver {
5461
}
5562

5663
func start() {
57-
#if canImport(Darwin) || canImport(Glibc) || canImport(Musl)
64+
#if canImport(Darwin) || canImport(Glibc) || canImport(Musl) || canImport(Bionic)
5865
pthread_create(&thread, nil, start_thread,
5966
Unmanaged.passRetained(self).toOpaque())
6067
#elseif canImport(WinSDK)
@@ -72,7 +79,7 @@ final class TaskDriver {
7279
func join() {
7380
#if canImport(Darwin)
7481
pthread_join(thread!, nil)
75-
#elseif canImport(Glibc) || canImport(Musl)
82+
#elseif canImport(Glibc) || canImport(Musl) || canImport(Bionic)
7683
pthread_join(thread, nil)
7784
#elseif canImport(WinSDK)
7885
#error("TODO: Port TaskDriver threading to windows")

0 commit comments

Comments
 (0)