void CFMessagePortInvalidate(CFMessagePortRef ms) { __CFGenericValidateType(ms, __kCFMessagePortTypeID); if (!__CFMessagePortIsDeallocing(ms)) { CFRetain(ms); } __CFMessagePortLock(ms); if (__CFMessagePortIsValid(ms)) { CFMessagePortInvalidationCallBack callout = ms->_icallout; CFRunLoopSourceRef source = ms->_source; CFMachPortRef replyPort = ms->_replyPort; CFMachPortRef port = ms->_port; CFStringRef name = ms->_name; void *info = NULL; __CFMessagePortUnsetValid(ms); if (!__CFMessagePortIsRemote(ms)) { info = ms->_context.info; ms->_context.info = NULL; } ms->_source = NULL; ms->_replyPort = NULL; __CFMessagePortUnlock(ms); __CFSpinLock(&__CFAllMessagePortsLock); if (NULL != (__CFMessagePortIsRemote(ms) ? __CFAllRemoteMessagePorts : __CFAllLocalMessagePorts)) { CFDictionaryRemoveValue(__CFMessagePortIsRemote(ms) ? __CFAllRemoteMessagePorts : __CFAllLocalMessagePorts, name); } __CFSpinUnlock(&__CFAllMessagePortsLock); if (NULL != callout) { callout(ms, info); } // We already know we're going invalid, don't need this callback // anymore; plus, this solves a reentrancy deadlock; also, this // must be done before the deallocate of the Mach port, to // avoid a race between the notification message which could be // handled in another thread, and this NULL'ing out. CFMachPortSetInvalidationCallBack(port, NULL); // For hashing and equality purposes, cannot get rid of _port here if (!__CFMessagePortIsRemote(ms) && NULL != ms->_context.release) { ms->_context.release(info); } if (NULL != source) { CFRunLoopSourceInvalidate(source); CFRelease(source); } if (NULL != replyPort) { CFMachPortInvalidate(replyPort); CFRelease(replyPort); } if (__CFMessagePortIsRemote(ms)) { // Get rid of our extra ref on the Mach port gotten from bs server mach_port_deallocate(mach_task_self(), CFMachPortGetPort(port)); } } else { __CFMessagePortUnlock(ms); } if (!__CFMessagePortIsDeallocing(ms)) { CFRelease(ms); } }
static CFStringRef __CFMessagePortCopyDescription(CFTypeRef cf) { CFMessagePortRef ms = (CFMessagePortRef)cf; CFStringRef result; const char *locked; CFStringRef contextDesc = NULL; locked = "Maybe"; if (__CFMessagePortIsRemote(ms)) { result = CFStringCreateWithFormat(kCFAllocatorSystemDefault, NULL, CFSTR("<CFMessagePort %p [%p]>{locked = %s, valid = %s, remote = %s, name = %@}"), cf, CFGetAllocator(ms), locked, (__CFMessagePortIsValid(ms) ? "Yes" : "No"), (__CFMessagePortIsRemote(ms) ? "Yes" : "No"), ms->_name); } else { if (NULL != ms->_context.info && NULL != ms->_context.copyDescription) { contextDesc = ms->_context.copyDescription(ms->_context.info); } if (NULL == contextDesc) { contextDesc = CFStringCreateWithFormat(kCFAllocatorSystemDefault, NULL, CFSTR("<CFMessagePort context %p>"), ms->_context.info); } void *addr = ms->_callout ? (void *)ms->_callout : (void *)ms->_calloutEx; Dl_info info; const char *name = (dladdr(addr, &info) && info.dli_saddr == addr && info.dli_sname) ? info.dli_sname : "???"; result = CFStringCreateWithFormat(kCFAllocatorSystemDefault, NULL, CFSTR("<CFMessagePort %p [%p]>{locked = %s, valid = %s, remote = %s, name = %@, source = %p, callout = %s (%p), context = %@}"), cf, CFGetAllocator(ms), locked, (__CFMessagePortIsValid(ms) ? "Yes" : "No"), (__CFMessagePortIsRemote(ms) ? "Yes" : "No"), ms->_name, ms->_source, name, addr, (NULL != contextDesc ? contextDesc : CFSTR("<no description>"))); } if (NULL != contextDesc) { CFRelease(contextDesc); } return result; }
static CFStringRef __CFMessagePortCopyDescription(CFTypeRef cf) { CFMessagePortRef ms = (CFMessagePortRef)cf; CFStringRef result; const char *locked; CFStringRef contextDesc = NULL; locked = ms->_lock ? "Yes" : "No"; if (!__CFMessagePortIsRemote(ms)) { if (NULL != ms->_context.info && NULL != ms->_context.copyDescription) { contextDesc = ms->_context.copyDescription(ms->_context.info); } if (NULL == contextDesc) { contextDesc = CFStringCreateWithFormat(CFGetAllocator(ms), NULL, CFSTR("<CFMessagePort context %p>"), ms->_context.info); } result = CFStringCreateWithFormat(CFGetAllocator(ms), NULL, CFSTR("<CFMessagePort %p [%p]>{locked = %s, valid = %s, remote = %s, name = %@}"), cf, CFGetAllocator(ms), locked, (__CFMessagePortIsValid(ms) ? "Yes" : "No"), (__CFMessagePortIsRemote(ms) ? "Yes" : "No"), ms->_name); } else { result = CFStringCreateWithFormat(CFGetAllocator(ms), NULL, CFSTR("<CFMessagePort %p [%p]>{locked = %s, valid = %s, remote = %s, name = %@, source = %p, callout = %p, context = %@}"), cf, CFGetAllocator(ms), locked, (__CFMessagePortIsValid(ms) ? "Yes" : "No"), (__CFMessagePortIsRemote(ms) ? "Yes" : "No"), ms->_name, ms->_source, ms->_callout, (NULL != contextDesc ? contextDesc : CFSTR("<no description>"))); } if (NULL != contextDesc) { CFRelease(contextDesc); } return result; }
Boolean CFMessagePortIsRemote(CFMessagePortRef ms) { __CFGenericValidateType(ms, __kCFMessagePortTypeID); return __CFMessagePortIsRemote(ms); }