Skip to content

Commit afefbf9

Browse files
committed
Fix compilation issues with HAS_DISPATCH on Linux
1 parent ceb15d8 commit afefbf9

File tree

4 files changed

+16
-7
lines changed

4 files changed

+16
-7
lines changed

CoreFoundation/Base.subproj/CFInternal.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -805,7 +805,7 @@ CF_EXPORT void _NS_pthread_setname_np(const char *name);
805805
#define pthread_setname_np _NS_pthread_setname_np
806806
#endif
807807

808-
#if DEPLOYMENT_TARGET_WINDOWS
808+
#if DEPLOYMENT_TARGET_WINDOWS || DEPLOYMENT_TARGET_LINUX
809809
// replacement for DISPATCH_QUEUE_OVERCOMMIT until we get a bug fix in dispatch on Windows
810810
// <rdar://problem/7923891> dispatch on Windows: Need queue_private.h
811811
#define DISPATCH_QUEUE_OVERCOMMIT 2
@@ -850,9 +850,6 @@ CF_INLINE const char *CFPathRelativeToAppleFrameworksRoot(const char *path, Bool
850850
#if (DEPLOYMENT_TARGET_MACOSX || DEPLOYMENT_TARGET_EMBEDDED || DEPLOYMENT_TARGET_EMBEDDED_MINI || DEPLOYMENT_TARGET_LINUX)
851851
#if __HAS_DISPATCH__
852852

853-
#include <dispatch/dispatch.h>
854-
#include <dispatch/private.h>
855-
856853
#if DEPLOYMENT_TARGET_LINUX
857854
#define QOS_CLASS_USER_INITIATED DISPATCH_QUEUE_PRIORITY_HIGH
858855
#define QOS_CLASS_DEFAULT DISPATCH_QUEUE_PRIORITY_DEFAULT
@@ -866,7 +863,9 @@ CF_INLINE long qos_class_main() {
866863
CF_INLINE long qos_class_self() {
867864
return QOS_CLASS_DEFAULT;
868865
}
869-
866+
#else
867+
#include <dispatch/dispatch.h>
868+
#include <dispatch/private.h>
870869
#endif
871870

872871
// Returns a generic dispatch queue for when you want to just throw some work

CoreFoundation/Base.subproj/CFPlatform.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ const char *_CFProcessPath(void) {
157157

158158
#if DEPLOYMENT_TARGET_LINUX
159159
#include <unistd.h>
160+
#include <syscall.h>
160161

161162
const char *_CFProcessPath(void) {
162163
if (__CFProcessPath) return __CFProcessPath;
@@ -175,6 +176,11 @@ const char *_CFProcessPath(void) {
175176
}
176177
return __CFProcessPath;
177178
}
179+
180+
Boolean _CFIsMainThread(void) {
181+
return syscall(SYS_gettid) == getpid();
182+
}
183+
178184
#endif
179185

180186
CF_PRIVATE CFStringRef _CFProcessNameString(void) {

CoreFoundation/RunLoop.subproj/CFRunLoop.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2541,7 +2541,7 @@ static int32_t __CFRunLoopRun(CFRunLoopRef rl, CFRunLoopModeRef rlm, CFTimeInter
25412541
}
25422542

25432543
#if __HAS_DISPATCH__
2544-
mach_port_name_t dispatchPort = MACH_PORT_NULL;
2544+
__CFPort dispatchPort = CFPORT_NULL;
25452545
Boolean libdispatchQSafe = pthread_main_np() && ((HANDLE_DISPATCH_ON_BASE_INVOCATION_ONLY && NULL == previousMode) || (!HANDLE_DISPATCH_ON_BASE_INVOCATION_ONLY && 0 == _CFGetTSD(__CFTSDKeyIsInGCDMainQ)));
25462546
if (libdispatchQSafe && (CFRunLoopGetMain() == rl) && CFSetContainsValue(rl->_commonModes, rlm->_name)) dispatchPort = _dispatch_get_main_queue_port_4CF();
25472547
#endif
@@ -2798,7 +2798,7 @@ static int32_t __CFRunLoopRun(CFRunLoopRef rl, CFRunLoopModeRef rlm, CFTimeInter
27982798
__CFRunLoopModeUnlock(rlm);
27992799
__CFRunLoopUnlock(rl);
28002800
_CFSetTSD(__CFTSDKeyIsInGCDMainQ, (void *)6, NULL);
2801-
#if DEPLOYMENT_TARGET_WINDOWS
2801+
#if DEPLOYMENT_TARGET_WINDOWS || DEPLOYMENT_TARGET_LINUX
28022802
void *msg = 0;
28032803
#endif
28042804
__CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__(msg);

CoreFoundation/Stream.subproj/CFStream.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1690,7 +1690,11 @@ static void _perform(void* info)
16901690

16911691
static void* _legacyStreamRunLoop_workThread(void* arg)
16921692
{
1693+
#if DEPLOYMENT_TARGET_LINUX || DEPLOYMENT_TARGET_FREEBSD
1694+
pthread_setname_np(pthread_self(), "com.apple.CFStream.LegacyThread");
1695+
#else
16931696
pthread_setname_np("com.apple.CFStream.LegacyThread");
1697+
#endif
16941698
sLegacyRL = CFRunLoopGetCurrent();
16951699

16961700
#if defined(LOG_STREAM)

0 commit comments

Comments
 (0)