runloop 源码#
nsrunloop 未开源,cfrunloopref 已开源。共有五个类
CFRunLoopRef (runloop对象)
CFRunLoopModeRef (runloop 模式)
CFRunLoopSourceRef (源 )
CFRunLoopTimerRef (定时器)
CFRunLoopObserverRef (观察者)
CFRunLoopRef#
首先看源码结构
struct __CFRunLoop {
CFMutableSetRef _commonModes; // Set
CFMutableSetRef _commonModeItems; // Set<Source/Observer/Timer>
CFRunLoopModeRef _currentMode; // Current Runloop Mode
CFMutableSetRef _modes; // Set
...
};_commonModes 具有common标识的所有mode。commonModeItems 中添加的item 会自动同步到_commonModes中。
CFRunLoopModeRef#
struct __CFRunLoopMode {
CFStringRef _name; // Mode Name, 例如 @"kCFRunLoopDefaultMode"
CFMutableSetRef _sources0; // Set
CFMutableSetRef _sources1; // Set
CFMutableArrayRef _observers; // Array
CFMutableArrayRef _timers; // Array
...
};