diff --git a/Sources/AsyncAlgorithms/Locking.swift b/Sources/AsyncAlgorithms/Locking.swift index a016d10f..6fc1d090 100644 --- a/Sources/AsyncAlgorithms/Locking.swift +++ b/Sources/AsyncAlgorithms/Locking.swift @@ -17,6 +17,8 @@ import Glibc import Musl #elseif canImport(WinSDK) import WinSDK +#elseif canImport(Bionic) +import Bionic #else #error("Unsupported platform") #endif @@ -24,7 +26,7 @@ import WinSDK internal struct Lock { #if canImport(Darwin) typealias Primitive = os_unfair_lock -#elseif canImport(Glibc) || canImport(Musl) +#elseif canImport(Glibc) || canImport(Musl) || canImport(Bionic) typealias Primitive = pthread_mutex_t #elseif canImport(WinSDK) typealias Primitive = SRWLOCK @@ -42,7 +44,7 @@ internal struct Lock { fileprivate static func initialize(_ platformLock: PlatformLock) { #if canImport(Darwin) platformLock.initialize(to: os_unfair_lock()) -#elseif canImport(Glibc) || canImport(Musl) +#elseif canImport(Glibc) || canImport(Musl) || canImport(Bionic) let result = pthread_mutex_init(platformLock, nil) precondition(result == 0, "pthread_mutex_init failed") #elseif canImport(WinSDK) @@ -53,7 +55,7 @@ internal struct Lock { } fileprivate static func deinitialize(_ platformLock: PlatformLock) { -#if canImport(Glibc) || canImport(Musl) +#if canImport(Glibc) || canImport(Musl) || canImport(Bionic) let result = pthread_mutex_destroy(platformLock) precondition(result == 0, "pthread_mutex_destroy failed") #endif @@ -63,7 +65,7 @@ internal struct Lock { fileprivate static func lock(_ platformLock: PlatformLock) { #if canImport(Darwin) os_unfair_lock_lock(platformLock) -#elseif canImport(Glibc) || canImport(Musl) +#elseif canImport(Glibc) || canImport(Musl) || canImport(Bionic) pthread_mutex_lock(platformLock) #elseif canImport(WinSDK) AcquireSRWLockExclusive(platformLock) @@ -75,7 +77,7 @@ internal struct Lock { fileprivate static func unlock(_ platformLock: PlatformLock) { #if canImport(Darwin) os_unfair_lock_unlock(platformLock) -#elseif canImport(Glibc) || canImport(Musl) +#elseif canImport(Glibc) || canImport(Musl) || canImport(Bionic) let result = pthread_mutex_unlock(platformLock) precondition(result == 0, "pthread_mutex_unlock failed") #elseif canImport(WinSDK) diff --git a/Sources/AsyncSequenceValidation/TaskDriver.swift b/Sources/AsyncSequenceValidation/TaskDriver.swift index 639557d0..50ed45ff 100644 --- a/Sources/AsyncSequenceValidation/TaskDriver.swift +++ b/Sources/AsyncSequenceValidation/TaskDriver.swift @@ -17,6 +17,8 @@ import Darwin import Glibc #elseif canImport(Musl) import Musl +#elseif canImport(Bionic) +import Bionic #elseif canImport(WinSDK) #error("TODO: Port TaskDriver threading to windows") #else @@ -28,11 +30,16 @@ func start_thread(_ raw: UnsafeMutableRawPointer) -> UnsafeMutableRawPointer? { Unmanaged.fromOpaque(raw).takeRetainedValue().run() return nil } -#elseif canImport(Glibc) || canImport(Musl) +#elseif (canImport(Glibc) && !os(Android)) || canImport(Musl) func start_thread(_ raw: UnsafeMutableRawPointer?) -> UnsafeMutableRawPointer? { Unmanaged.fromOpaque(raw!).takeRetainedValue().run() return nil } +#elseif os(Android) +func start_thread(_ raw: UnsafeMutableRawPointer) -> UnsafeMutableRawPointer { + Unmanaged.fromOpaque(raw).takeRetainedValue().run() + return UnsafeMutableRawPointer(bitPattern: 0xdeadbee)! +} #elseif canImport(WinSDK) #error("TODO: Port TaskDriver threading to windows") #endif @@ -42,7 +49,7 @@ final class TaskDriver { let queue: WorkQueue #if canImport(Darwin) var thread: pthread_t? -#elseif canImport(Glibc) || canImport(Musl) +#elseif canImport(Glibc) || canImport(Musl) || canImport(Bionic) var thread = pthread_t() #elseif canImport(WinSDK) #error("TODO: Port TaskDriver threading to windows") @@ -54,7 +61,7 @@ final class TaskDriver { } func start() { -#if canImport(Darwin) || canImport(Glibc) || canImport(Musl) +#if canImport(Darwin) || canImport(Glibc) || canImport(Musl) || canImport(Bionic) pthread_create(&thread, nil, start_thread, Unmanaged.passRetained(self).toOpaque()) #elseif canImport(WinSDK) @@ -72,7 +79,7 @@ final class TaskDriver { func join() { #if canImport(Darwin) pthread_join(thread!, nil) -#elseif canImport(Glibc) || canImport(Musl) +#elseif canImport(Glibc) || canImport(Musl) || canImport(Bionic) pthread_join(thread, nil) #elseif canImport(WinSDK) #error("TODO: Port TaskDriver threading to windows")