Use of pthread_main_np() in NSOperation


(Chris Bailey) #1

NSOperation.swift currently makes a call to pthread_main_np() on line 536.
This causes a compilation failure on Linux as there isn't an
implementation of pthread_main_np() in Glibc.

There's few ways of fixing this. Before I go ahead and implement one of
them, I'd like to get some input on what we thing is the best approach.

The most obvious approach would be to leverage the shim we've added to
CoreFoundation already. We implemented pthread_main_np() using the
following function in CFPlatform.c:
Boolean _CFIsMainThread(void) {
    return syscall(SYS_gettid) == getpid();
}
This is only available internally to CF, but could be exposed to
Foundation, either as _CFIsMainThread() or as pthread_main_np().

Other options would be to expose the pthread_main_np() shim that's in
Dispatch already (again internally), or to add it to the Glibc overlay so
its available globally.

Any thoughts on the best approach?

Chris


(Tony Parker) #2

Since CF is really an implementation detail of Foundation for corelibs, let’s use the CF implementation for Foundation.

- Tony

···

On May 10, 2016, at 12:10 PM, Chris Bailey via swift-corelibs-dev <swift-corelibs-dev@swift.org> wrote:

NSOperation.swift currently makes a call to pthread_main_np() on line 536. This causes a compilation failure on Linux as there isn't an implementation of pthread_main_np() in Glibc.

There's few ways of fixing this. Before I go ahead and implement one of them, I'd like to get some input on what we thing is the best approach.

The most obvious approach would be to leverage the shim we've added to CoreFoundation already. We implemented pthread_main_np() using the following function in CFPlatform.c:
Boolean _CFIsMainThread(void) {
    return syscall(SYS_gettid) == getpid();
}
This is only available internally to CF, but could be exposed to Foundation, either as _CFIsMainThread() or as pthread_main_np().

Other options would be to expose the pthread_main_np() shim that's in Dispatch already (again internally), or to add it to the Glibc overlay so its available globally.

Any thoughts on the best approach?

Chris_______________________________________________
swift-corelibs-dev mailing list
swift-corelibs-dev@swift.org
https://lists.swift.org/mailman/listinfo/swift-corelibs-dev