Skip to content

Commit 0759969

Browse files
committed
Use _CFIsMainThread as a shim for pthread_main_np on Linux
1 parent a1ea7f7 commit 0759969

File tree

4 files changed

+13
-2
lines changed

4 files changed

+13
-2
lines changed

CoreFoundation/Base.subproj/CFBase.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -623,6 +623,11 @@ CFIndex CFAllocatorGetPreferredSizeForSize(CFAllocatorRef allocator, CFIndex siz
623623
CF_EXPORT
624624
void CFAllocatorGetContext(CFAllocatorRef allocator, CFAllocatorContext *context);
625625

626+
#if DEPLOYMENT_TARGET_LINUX
627+
CF_EXPORT
628+
int _CFIsMainThread(void);
629+
#endif
630+
626631

627632
/* Polymorphic CF functions */
628633

CoreFoundation/Base.subproj/CFInternal.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -806,7 +806,7 @@ CF_EXPORT void _NS_pthread_setname_np(const char *name);
806806
#endif
807807

808808
#if DEPLOYMENT_TARGET_LINUX
809-
CF_EXPORT Boolean _CFIsMainThread(void);
809+
CF_EXPORT int _CFIsMainThread(void);
810810
#define pthread_main_np _CFIsMainThread
811811
#endif
812812

CoreFoundation/Base.subproj/CFPlatform.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ const char *_CFProcessPath(void) {
159159
#include <unistd.h>
160160
#include <syscall.h>
161161

162-
Boolean _CFIsMainThread(void) {
162+
int _CFIsMainThread(void) {
163163
return syscall(SYS_gettid) == getpid();
164164
}
165165

Foundation/NSOperation.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@
99

1010
#if DEPLOYMENT_ENABLE_LIBDISPATCH
1111
import Dispatch
12+
#if os(Linux)
13+
import CoreFoundation
14+
private func pthread_main_np() -> Int32 {
15+
return _CFIsMainThread()
16+
}
17+
#endif
1218
#endif
1319

1420
public class NSOperation : NSObject {

0 commit comments

Comments
 (0)