- if (stream->client->rlSource) {
- if (!__CFBitIsSet(stream->flags, SHARED_SOURCE)) {
- CFRunLoopSourceInvalidate(stream->client->rlSource);
- CFRelease(stream->client->rlSource);
- stream->client->rlSource = NULL;
- }
- else {
-
- CFArrayRef runLoopAndSourceKey;
- CFMutableArrayRef list;
- CFIndex c, i;
-
- __CFSpinLock(&sSourceLock);
-
- runLoopAndSourceKey = (CFArrayRef)CFDictionaryGetValue(sSharedSources, stream);
- list = (CFMutableArrayRef)CFDictionaryGetValue(sSharedSources, runLoopAndSourceKey);
-
- c = CFArrayGetCount(list);
- i = CFArrayGetFirstIndexOfValue(list, CFRangeMake(0, c), stream);
- if (i != kCFNotFound) {
- CFArrayRemoveValueAtIndex(list, i);
- c--;
- }
-
- if (!c) {
- CFRunLoopRemoveSource((CFRunLoopRef)CFArrayGetValueAtIndex(runLoopAndSourceKey, 0), stream->client->rlSource, (CFStringRef)CFArrayGetValueAtIndex(runLoopAndSourceKey, 1));
- CFRunLoopSourceInvalidate(stream->client->rlSource);
- CFDictionaryRemoveValue(sSharedSources, runLoopAndSourceKey);
- }
-
- CFDictionaryRemoveValue(sSharedSources, stream);
-
- CFRelease(stream->client->rlSource);
- stream->client->rlSource = NULL;
- __CFBitClear(stream->flags, SHARED_SOURCE);
-
- __CFSpinUnlock(&sSourceLock);
- }
- }