Skip to content

Commit efc0182

Browse files
[wasm] Port CFStream for no-dispatch platforms
This patch guards the use of RunLoop, which is not available on no-dispatch platforms.
1 parent 3451ceb commit efc0182

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

CoreFoundation/Stream.subproj/CFStream.c

+20
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ CF_INLINE CFRunLoopSourceRef _CFStreamCopySource(struct _CFStream* stream) {
9393
}
9494

9595
CF_INLINE void _CFStreamSetSource(struct _CFStream* stream, CFRunLoopSourceRef source, Boolean invalidateOldSource) {
96+
#if __HAS_DISPATCH__
9697
CFRunLoopSourceRef oldSource = NULL;
9798

9899
if (stream) {
@@ -119,6 +120,7 @@ CF_INLINE void _CFStreamSetSource(struct _CFStream* stream, CFRunLoopSourceRef s
119120
// And lose the one that held it in our stream as well
120121
CFRelease(oldSource);
121122
}
123+
#endif
122124
}
123125

124126
CF_INLINE const struct _CFStreamCallBacks *_CFStreamGetCallBackPtr(struct _CFStream *stream) {
@@ -135,6 +137,7 @@ CF_INLINE void _CFStreamSetStatusCode(struct _CFStream *stream, CFStreamStatus n
135137
}
136138

137139
CF_INLINE void _CFStreamScheduleEvent(struct _CFStream *stream, CFStreamEventType event) {
140+
#if __HAS_DISPATCH__
138141
if (stream->client && (stream->client->when & event)) {
139142
CFRunLoopSourceRef source = _CFStreamCopySource(stream);
140143
if (source) {
@@ -145,6 +148,7 @@ CF_INLINE void _CFStreamScheduleEvent(struct _CFStream *stream, CFStreamEventTyp
145148
_wakeUpRunLoop(stream);
146149
}
147150
}
151+
#endif
148152
}
149153

150154
CF_INLINE void _CFStreamSetStreamError(struct _CFStream *stream, CFStreamError *err) {
@@ -203,6 +207,7 @@ static void _CFStreamDetachSource(struct _CFStream* stream) {
203207

204208
CFAssert(CFArrayGetFirstIndexOfValue(list, CFRangeMake(0, CFArrayGetCount(list)), stream) == kCFNotFound, __kCFLogAssertion, "CFStreamClose: stream found twice in its shared source's list");
205209

210+
#if __HAS_DISPATCH__
206211
if (count == 0) {
207212
CFRunLoopSourceRef source = _CFStreamCopySource(stream);
208213
if (source) {
@@ -211,6 +216,7 @@ static void _CFStreamDetachSource(struct _CFStream* stream) {
211216
}
212217
CFDictionaryRemoveValue(sSharedSources, runLoopAndSourceKey);
213218
}
219+
#endif
214220

215221
CFDictionaryRemoveValue(sSharedSources, stream);
216222

@@ -653,6 +659,7 @@ static void _cfstream_shared_signalEventSync(void* info)
653659
break;
654660
}
655661
}
662+
#if __HAS_DISPATCH__
656663

657664
/* And then we also signal any other streams in this array so that we get them next go? */
658665
for (; i < c; i++) {
@@ -675,6 +682,7 @@ static void _cfstream_shared_signalEventSync(void* info)
675682
break;
676683
}
677684
}
685+
#endif
678686

679687
__CFUnlock(&sSourceLock);
680688

@@ -788,6 +796,7 @@ CF_PRIVATE void _CFStreamSignalEvent(struct _CFStream *stream, CFStreamEventType
788796
_CFStreamSetStatusCode(stream, kCFStreamStatusError);
789797
}
790798

799+
#if __HAS_DISPATCH__
791800
// Now signal any pertinent event - if not already signaled
792801
if (stream->client && (stream->client->when & event) != 0 && (stream->client->whatToSignal & event) == 0) {
793802
CFRunLoopSourceRef source = _CFStreamCopySource(stream);
@@ -824,6 +833,7 @@ CF_PRIVATE void _CFStreamSignalEvent(struct _CFStream *stream, CFStreamEventType
824833
CFRelease(source);
825834
}
826835
}
836+
#endif
827837
}
828838

829839
CF_PRIVATE CFStreamStatus _CFStreamGetStatus(struct _CFStream *stream) {
@@ -1469,6 +1479,7 @@ CF_PRIVATE void _CFStreamScheduleWithRunLoop(struct _CFStream *stream, CFRunLoop
14691479
count--;
14701480
}
14711481

1482+
#if __HAS_DISPATCH__
14721483
if (count == 0) {
14731484
CFRunLoopSourceRef source = _CFStreamCopySource(stream);
14741485
if (source) {
@@ -1477,6 +1488,7 @@ CF_PRIVATE void _CFStreamScheduleWithRunLoop(struct _CFStream *stream, CFRunLoop
14771488
}
14781489
CFDictionaryRemoveValue(sSharedSources, runLoopAndSourceKey);
14791490
}
1491+
#endif
14801492

14811493
CFDictionaryRemoveValue(sSharedSources, stream);
14821494

@@ -1518,6 +1530,7 @@ CF_PRIVATE void _CFStreamScheduleWithRunLoop(struct _CFStream *stream, CFRunLoop
15181530
__CFBitClear(stream->flags, CALLING_CLIENT);
15191531
}
15201532

1533+
#if __HAS_DISPATCH__
15211534
/*
15221535
* If we've got events pending, we need to wake up and signal
15231536
*/
@@ -1529,6 +1542,7 @@ CF_PRIVATE void _CFStreamScheduleWithRunLoop(struct _CFStream *stream, CFRunLoop
15291542
_wakeUpRunLoop(stream);
15301543
}
15311544
}
1545+
#endif
15321546
}
15331547

15341548
CF_EXPORT void CFReadStreamScheduleWithRunLoop(CFReadStreamRef stream, CFRunLoopRef runLoop, CFStringRef runLoopMode) {
@@ -1568,11 +1582,13 @@ CF_PRIVATE void _CFStreamUnscheduleFromRunLoop(struct _CFStream *stream, CFRunLo
15681582
if (!stream->client->rlSource) return;
15691583

15701584
if (!__CFBitIsSet(stream->flags, SHARED_SOURCE)) {
1585+
#if __HAS_DISPATCH__
15711586
CFRunLoopSourceRef source = _CFStreamCopySource(stream);
15721587
if (source) {
15731588
CFRunLoopRemoveSource(runLoop, source, runLoopMode);
15741589
CFRelease(source);
15751590
}
1591+
#endif
15761592
} else {
15771593
CFArrayRef runLoopAndSourceKey;
15781594
CFMutableArrayRef list;
@@ -1590,6 +1606,7 @@ CF_PRIVATE void _CFStreamUnscheduleFromRunLoop(struct _CFStream *stream, CFRunLo
15901606
count--;
15911607
}
15921608

1609+
#if __HAS_DISPATCH__
15931610
if (count == 0) {
15941611
CFRunLoopSourceRef source = _CFStreamCopySource(stream);
15951612
if (source) {
@@ -1598,6 +1615,7 @@ CF_PRIVATE void _CFStreamUnscheduleFromRunLoop(struct _CFStream *stream, CFRunLo
15981615
}
15991616
CFDictionaryRemoveValue(sSharedSources, runLoopAndSourceKey);
16001617
}
1618+
#endif
16011619

16021620
CFDictionaryRemoveValue(sSharedSources, stream);
16031621

@@ -1850,6 +1868,7 @@ dispatch_queue_t CFWriteStreamCopyDispatchQueue(CFWriteStreamRef stream)
18501868
#endif
18511869

18521870
static void waitForOpen(struct _CFStream *stream) {
1871+
#if __HAS_DISPATCH__
18531872
CFRunLoopRef runLoop = CFRunLoopGetCurrent();
18541873
CFStringRef privateMode = CFSTR("_kCFStreamBlockingOpenMode");
18551874
_CFStreamScheduleWithRunLoop(stream, runLoop, privateMode);
@@ -1858,6 +1877,7 @@ static void waitForOpen(struct _CFStream *stream) {
18581877
CFRunLoopRunInMode(privateMode, 1e+20, TRUE);
18591878
}
18601879
_CFStreamUnscheduleFromRunLoop(stream, runLoop, privateMode);
1880+
#endif
18611881
}
18621882

18631883
CF_PRIVATE CFArrayRef _CFReadStreamCopyRunLoopsAndModes(CFReadStreamRef readStream) {

0 commit comments

Comments
 (0)