Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion Sources/NIOPosix/ThreadPosix.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,30 @@ private func sysPthread_create(
)
#else
var handleLinux = pthread_t()
#if os(Android)
// NDK 27 signature:
// int pthread_create(pthread_t* _Nonnull __pthread_ptr, pthread_attr_t const* _Nullable __attr, void* _Nonnull (* _Nonnull __start_routine)(void* _Nonnull), void* _Nullable);
func coerceThreadDestructor(
_ destructor: @escaping ThreadDestructor
) -> (@convention(c) (UnsafeMutableRawPointer) -> UnsafeMutableRawPointer) {
destructor
}

// NDK 28 signature:
// int pthread_create(pthread_t* _Nonnull __pthread_ptr, pthread_attr_t const* _Nullable __attr, void* _Nullable (* _Nonnull __start_routine)(void* _Nullable), void* _Nullable);
func coerceThreadDestructor(
_ destructor: @escaping ThreadDestructor
) -> (@convention(c) (UnsafeMutableRawPointer?) -> UnsafeMutableRawPointer?) {
unsafeBitCast(destructor, to: (@convention(c) (UnsafeMutableRawPointer?) -> UnsafeMutableRawPointer?).self)
}
#else
// Linux doesn't change the signature
func coerceThreadDestructor(_ destructor: ThreadDestructor) -> ThreadDestructor { destructor }
#endif
let result = pthread_create(
&handleLinux,
nil,
destructor,
coerceThreadDestructor(destructor),
args
)
#endif
Expand Down
Loading