在我的应用我添加CFMachPortRef(通过CFMachPortCreateRunLoopSource)的线程CFRunLoopGCD和RunLoops
现在,我问我自己,可以在此使用GCD做?比方说,而不是产卵我自己NSThread并通过CFRunLoopAddSource事件端口添加创建CFRunLoopSourceRef它的运行循环,增加调度的runloop?
我认为这很可能不起作用,因为GCD的内部工作原理,但我真的不知道。
更新
我得到这个至今,但没有回调函数的事件自来水也没有dispatch_source_event_handler块被调用。有任何想法吗?
CFMachPortRef port = CGEventTapCreate(kCGSessionEventTap,
kCGHeadInsertEventTap,
opts,
desc_.eventMask,
_CGEventCallback,
self);
// create dispatch source
dispatch_source_t source = dispatch_source_create(DISPATCH_SOURCE_TYPE_MACH_RECV,
CFMachPortGetPort(port),
0,
dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0));
// set event handler
dispatch_source_set_event_handler(source, ^{
printf("handle me!\n");
});
dispatch_resume(source);
'CFMachPort'结合了Mach端口和回调。如果您使用GCD来监控Mach端口,则忽略回调。在事件点击的情况下,回调在Core Graphics内部,大概是很重要的东西(例如接收来自端口的Mach消息,解码并调用* your * callback)。 – 2016-03-13 21:50:40