Skip to content

Commit e1b38fb

Browse files
committed
Base, RunLoop, Stream: s/pthread_t/_CFThreadRef/
Replace instances of raw `pthread_t` with `_CFThreadRef` to prepare for the Windows threading support.
1 parent b5d216e commit e1b38fb

File tree

6 files changed

+35
-35
lines changed

6 files changed

+35
-35
lines changed

CoreFoundation/Base.subproj/CFPlatform.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -558,10 +558,10 @@ CF_EXPORT void _NS_pthread_setname_np(const char *name) {
558558
}
559559
}
560560

561-
static pthread_t __initialPthread = { NULL, 0 };
561+
static _CFThreadRef __initialPthread = { NULL, 0 };
562562

563563
CF_EXPORT int _NS_pthread_main_np() {
564-
pthread_t me = pthread_self();
564+
_CFThreadRef me = pthread_self();
565565
if (NULL == __initialPthread.p) {
566566
__initialPthread.p = me.p;
567567
__initialPthread.x = me.x;
@@ -1242,7 +1242,7 @@ CF_INLINE void _CF_put_thread_semaphore(_CF_sema_t s) {
12421242
typedef struct _CF_dispatch_once_waiter_s {
12431243
volatile struct _CF_dispatch_once_waiter_s *volatile dow_next;
12441244
_CF_sema_t dow_sema;
1245-
pthread_t dow_thread;
1245+
_CFThreadRef dow_thread;
12461246
} *_CF_dispatch_once_waiter_t;
12471247

12481248
#if defined(__x86_64__) || defined(__i386__)
@@ -1369,12 +1369,12 @@ void _CFThreadSpecificSet(_CFThreadSpecificKey key, CFTypeRef _Nullable value) {
13691369
}
13701370

13711371
_CFThreadRef _CFThreadCreate(const _CFThreadAttributes attrs, void *_Nullable (* _Nonnull startfn)(void *_Nullable), void *_CF_RESTRICT _Nullable context) {
1372-
pthread_t thread;
1372+
_CFThreadRef thread;
13731373
pthread_create(&thread, &attrs, startfn, context);
13741374
return thread;
13751375
}
13761376

1377-
CF_CROSS_PLATFORM_EXPORT int _CFThreadSetName(pthread_t thread, const char *_Nonnull name) {
1377+
CF_CROSS_PLATFORM_EXPORT int _CFThreadSetName(_CFThreadRef thread, const char *_Nonnull name) {
13781378
#if DEPLOYMENT_TARGET_MACOSX || DEPLOYMENT_TARGET_EMBEDDED || DEPLOYMENT_TARGET_EMBEDDED_MINI
13791379
if (pthread_equal(pthread_self(), thread)) {
13801380
return pthread_setname_np(name);

CoreFoundation/Base.subproj/CFRuntime.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1073,7 +1073,7 @@ CF_PRIVATE Boolean __CFProcessIsRestricted() {
10731073
#if DEPLOYMENT_TARGET_WINDOWS
10741074
#define kNilPthreadT { nil, nil }
10751075
#else
1076-
#define kNilPthreadT (pthread_t)0
1076+
#define kNilPthreadT (_CFThreadRef)0
10771077
#endif
10781078

10791079

@@ -1090,12 +1090,12 @@ static Boolean __CFInitializing = 0;
10901090
Boolean __CFInitialized = 0;
10911091

10921092
// move the next 2 lines down into the #if below, and make it static, after Foundation gets off this symbol on other platforms.
1093-
CF_EXPORT pthread_t _CFMainPThread;
1094-
pthread_t _CFMainPThread = kNilPthreadT;
1093+
CF_EXPORT _CFThreadRef _CFMainPThread;
1094+
_CFThreadRef _CFMainPThread = kNilPthreadT;
10951095
#if DEPLOYMENT_TARGET_WINDOWS || DEPLOYMENT_TARGET_LINUX
10961096

1097-
CF_EXPORT pthread_t _CF_pthread_main_thread_np(void);
1098-
pthread_t _CF_pthread_main_thread_np(void) {
1097+
CF_EXPORT _CFThreadRef _CF_pthread_main_thread_np(void);
1098+
_CFThreadRef _CF_pthread_main_thread_np(void) {
10991099
return _CFMainPThread;
11001100
}
11011101
#define pthread_main_thread_np() _CF_pthread_main_thread_np()

CoreFoundation/Base.subproj/ForSwiftFoundationOnly.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -345,22 +345,22 @@ CF_EXPORT char *_Nullable *_Nonnull _CFEnviron(void);
345345

346346
CF_EXPORT void CFLog1(CFLogLevel lev, CFStringRef message);
347347

348+
typedef pthread_attr_t _CFThreadAttributes;
349+
typedef pthread_t _CFThreadRef;
350+
typedef pthread_key_t _CFThreadSpecificKey;
351+
348352
CF_CROSS_PLATFORM_EXPORT Boolean _CFIsMainThread(void);
349-
CF_EXPORT pthread_t _CFMainPThread;
353+
CF_EXPORT _CFThreadRef _CFMainPThread;
350354

351355
CF_EXPORT CFHashCode __CFHashDouble(double d);
352356

353-
typedef pthread_key_t _CFThreadSpecificKey;
354357
CF_EXPORT CFTypeRef _Nullable _CFThreadSpecificGet(_CFThreadSpecificKey key);
355358
CF_EXPORT void _CFThreadSpecificSet(_CFThreadSpecificKey key, CFTypeRef _Nullable value);
356359
CF_EXPORT _CFThreadSpecificKey _CFThreadSpecificKeyCreate(void);
357360

358-
typedef pthread_attr_t _CFThreadAttributes;
359-
typedef pthread_t _CFThreadRef;
360-
361361
CF_EXPORT _CFThreadRef _CFThreadCreate(const _CFThreadAttributes attrs, void *_Nullable (* _Nonnull startfn)(void *_Nullable), void *_CF_RESTRICT _Nullable context);
362362

363-
CF_CROSS_PLATFORM_EXPORT int _CFThreadSetName(pthread_t thread, const char *_Nonnull name);
363+
CF_CROSS_PLATFORM_EXPORT int _CFThreadSetName(_CFThreadRef thread, const char *_Nonnull name);
364364
CF_CROSS_PLATFORM_EXPORT int _CFThreadGetName(char *_Nonnull buf, int length);
365365

366366
CF_EXPORT Boolean _CFCharacterSetIsLongCharacterMember(CFCharacterSetRef theSet, UTF32Char theChar);

CoreFoundation/RunLoop.subproj/CFRunLoop.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ typedef int dispatch_runloop_handle_t;
9090

9191
extern void _dispatch_main_queue_callback_4CF(void *);
9292

93-
extern pthread_t pthread_main_thread_np(void);
93+
extern _CFThreadRef pthread_main_thread_np(void);
9494
typedef struct voucher_s *voucher_t;
9595

9696
extern voucher_t _Nullable voucher_copy(void);
@@ -125,7 +125,7 @@ extern void _dispatch_main_queue_callback_4CF(void *_Null_unspecified msg);
125125
#endif
126126

127127
#if DEPLOYMENT_TARGET_WINDOWS || DEPLOYMENT_TARGET_LINUX
128-
CF_EXPORT pthread_t _CF_pthread_main_thread_np(void);
128+
CF_EXPORT _CFThreadRef _CF_pthread_main_thread_np(void);
129129
#define pthread_main_thread_np() _CF_pthread_main_thread_np()
130130
#endif
131131

@@ -154,21 +154,21 @@ static void _runLoopTimerWithBlockContext(CFRunLoopTimerRef timer, void *opaqueB
154154

155155
#if DEPLOYMENT_TARGET_WINDOWS
156156

157-
static pthread_t const kNilPthreadT = { nil, nil };
157+
static _CFThreadRef const kNilPthreadT = { nil, nil };
158158
#define pthreadPointer(a) a.p
159159
typedef int kern_return_t;
160160
#define KERN_SUCCESS 0
161161

162162
#elif DEPLOYMENT_TARGET_LINUX
163163

164-
static pthread_t const kNilPthreadT = (pthread_t)0;
164+
static _CFThreadRef const kNilPthreadT = (_CFThreadRef)0;
165165
#define pthreadPointer(a) ((void*)a)
166166
typedef int kern_return_t;
167167
#define KERN_SUCCESS 0
168168

169169
#else
170170

171-
static pthread_t const kNilPthreadT = (pthread_t)0;
171+
static _CFThreadRef const kNilPthreadT = (_CFThreadRef)0;
172172
#define pthreadPointer(a) a
173173
#define lockCount(a) a
174174
#endif
@@ -785,7 +785,7 @@ struct __CFRunLoop {
785785
__CFPort _wakeUpPort; // used for CFRunLoopWakeUp
786786
Boolean _unused;
787787
volatile _per_run_data *_perRunData; // reset for runs of the run loop
788-
pthread_t _pthread;
788+
_CFThreadRef _pthread;
789789
uint32_t _winthread;
790790
CFMutableSetRef _commonModes;
791791
CFMutableSetRef _commonModeItems;
@@ -1373,7 +1373,7 @@ static void __CFRunLoopDeallocateTimers(const void *value, void *context) {
13731373
}
13741374
}
13751375

1376-
CF_EXPORT CFRunLoopRef _CFRunLoopGet0b(pthread_t t);
1376+
CF_EXPORT CFRunLoopRef _CFRunLoopGet0b(_CFThreadRef t);
13771377

13781378
static void __CFRunLoopDeallocate(CFTypeRef cf) {
13791379
CFRunLoopRef rl = (CFRunLoopRef)cf;
@@ -1459,7 +1459,7 @@ CFTypeID CFRunLoopGetTypeID(void) {
14591459
return _kCFRuntimeIDCFRunLoop;
14601460
}
14611461

1462-
static CFRunLoopRef __CFRunLoopCreate(pthread_t t) {
1462+
static CFRunLoopRef __CFRunLoopCreate(_CFThreadRef t) {
14631463
CFRunLoopRef loop = NULL;
14641464
CFRunLoopModeRef rlm;
14651465
uint32_t size = sizeof(struct __CFRunLoop) - sizeof(CFRuntimeBase);
@@ -1496,7 +1496,7 @@ static CFRunLoopRef __CFRunLoopCreate(pthread_t t) {
14961496
static CFMutableDictionaryRef __CFRunLoops = NULL;
14971497
static CFLock_t loopsLock = CFLockInit;
14981498

1499-
CF_PRIVATE CFRunLoopRef _CFRunLoopCacheLookup(pthread_t t, const Boolean createCache) {
1499+
CF_PRIVATE CFRunLoopRef _CFRunLoopCacheLookup(_CFThreadRef t, const Boolean createCache) {
15001500
CFRunLoopRef loop = NULL;
15011501
if (pthread_equal(t, kNilPthreadT)) {
15021502
t = pthread_main_thread_np();
@@ -1540,7 +1540,7 @@ CF_EXPORT Boolean _CFRunLoopIsCurrent(const CFRunLoopRef rl) {
15401540

15411541
// should only be called by Foundation
15421542
// t==0 is a synonym for "main thread" that always works
1543-
CF_EXPORT CFRunLoopRef _CFRunLoopGet0(pthread_t t) {
1543+
CF_EXPORT CFRunLoopRef _CFRunLoopGet0(_CFThreadRef t) {
15441544
if (pthread_equal(t, kNilPthreadT)) {
15451545
t = pthread_main_thread_np();
15461546
}
@@ -1575,7 +1575,7 @@ CF_EXPORT CFRunLoopRef _CFRunLoopGet0(pthread_t t) {
15751575
}
15761576

15771577
// should only be called by Foundation
1578-
CFRunLoopRef _CFRunLoopGet0b(pthread_t t) {
1578+
CFRunLoopRef _CFRunLoopGet0b(_CFThreadRef t) {
15791579
if (pthread_equal(t, kNilPthreadT)) {
15801580
t = pthread_main_thread_np();
15811581
}
@@ -1629,7 +1629,7 @@ CF_PRIVATE void __CFFinalizeRunLoop(uintptr_t data) {
16291629
}
16301630
}
16311631

1632-
pthread_t _CFRunLoopGet1(CFRunLoopRef rl) {
1632+
_CFThreadRef _CFRunLoopGet1(CFRunLoopRef rl) {
16331633
return rl->_pthread;
16341634
}
16351635

CoreFoundation/RunLoop.subproj/CFSocket.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1026,17 +1026,17 @@ static void timeradd(struct timeval *a, struct timeval *b, struct timeval *res)
10261026

10271027
#include <sys/syslog.h>
10281028

1029-
static pthread_t __cfSocketTid()
1029+
static _CFThreadRef __cfSocketTid()
10301030
{
10311031
#if DEPLOYMENT_TARGET_MACOSX || DEPLOYMENT_TARGET_EMBEDDED
10321032
uint64_t tid = 0;
10331033
if (0 != pthread_threadid_np(NULL, &tid))
10341034
tid = pthread_mach_thread_np(pthread_self());
1035-
return (pthread_t) tid;
1035+
return (_CFThreadRef) tid;
10361036
#elif DEPLOYMENT_TARGET_WINDOWS
1037-
return (pthread_t) GetCurrentThreadId();
1037+
return (_CFThreadRef) GetCurrentThreadId();
10381038
#else
1039-
return (pthread_t) pthread_self();
1039+
return (_CFThreadRef) pthread_self();
10401040
#endif
10411041
}
10421042

@@ -2615,7 +2615,7 @@ static CFSocketRef _CFSocketCreateWithNative(CFAllocatorRef allocator, CFSocketN
26152615
if (INVALID_SOCKET != sock) CFDictionaryAddValue(__CFAllSockets, (void *)(uintptr_t)sock, memory);
26162616
if (NULL == __CFSocketManagerThread) {
26172617
#if DEPLOYMENT_TARGET_MACOSX || DEPLOYMENT_TARGET_EMBEDDED || DEPLOYMENT_TARGET_EMBEDDED_MINI || DEPLOYMENT_TARGET_LINUX || DEPLOYMENT_TARGET_FREEBSD
2618-
pthread_t tid = 0;
2618+
_CFThreadRef tid = 0;
26192619
pthread_attr_t attr;
26202620
pthread_attr_init(&attr);
26212621
pthread_attr_setscope(&attr, PTHREAD_SCOPE_SYSTEM);
@@ -2625,7 +2625,7 @@ static CFSocketRef _CFSocketCreateWithNative(CFAllocatorRef allocator, CFSocketN
26252625
#endif
26262626
pthread_create(&tid, &attr, __CFSocketManager, 0);
26272627
pthread_attr_destroy(&attr);
2628-
//warning CF: we dont actually know that a pthread_t is the same size as void *
2628+
//warning CF: we dont actually know that a _CFThreadRef is the same size as void *
26292629
__CFSocketManagerThread = (void *)tid;
26302630
#elif DEPLOYMENT_TARGET_WINDOWS
26312631
unsigned tid;

CoreFoundation/Stream.subproj/CFStream.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1745,7 +1745,7 @@ static CFRunLoopRef _legacyStreamRunLoop()
17451745
#if DEPLOYMENT_TARGET_MACOSX || DEPLOYMENT_TARGET_EMBEDDED
17461746
pthread_attr_set_qos_class_np(&attr, qos_class_main(), 0);
17471747
#endif
1748-
pthread_t workThread;
1748+
_CFThreadRef workThread;
17491749
(void) pthread_create(&workThread, &attr, _legacyStreamRunLoop_workThread, &sem);
17501750
pthread_attr_destroy(&attr);
17511751
#endif

0 commit comments

Comments
 (0)