Dispatch already patches over the various platform-specific event APIs, and most platforms are handled: kqueue-based BSD systems, epoll-based Linux systems, and Win32-based Windows systems. This is the case for CFRunLoop as well, except that on macOS the implementation is based on Mach ports.

This leads us to a problem with Foundation bringup on kqueue-based systems without Mach ports, and some possible ways out of this. The obvious solution is to get these kqueue-based systems to essentially adapt from scratch the kqueue API to the CFRunLoop API. This is not a straightforward task as the impedance mismatch between the APIs seems somewhat large.

I am currently prodding at this obvious solution specifically, but now given the clarification that CoreFoundation is not intended to be exported alongside Foundation I am wondering whether it is more productive to stub out CFRunLoop and its dependencies in CF and instead move to adapting RunLoop.swift to use Dispatch under the hood.

However, I'm not very fluent in either API, so my question is as follows: is it actually feasible to do this, conceptually? Of course, there are other platforms which may have some quirkful dependencies on CFRunLoop, but a Dispatch implementation wouldn't replace the original CFRunLoop version.

Or should I grit my teeth and try and get the obvious solution done?

Typically the problem that you'll run into with basing a runloop implementation on dispatch is that dispatch's APIs (sources, queues, workloops) are non-reentrant, where runloops have more than one run invocation on the stack simultaneously.

Terms of Service

Privacy Policy

Cookie Policy