Home > Articles > Home & Office Computing > Mac OS X

  • Print
  • + Share This
From the author of Organizing Events

Organizing Events

Around 2000, the FreeBSD kernel team began noticing that the poll() system call didn't scale very well, and that there were a lot of different messages that the kernel might want to send to userspace that weren't handled in a consistent way. They were not the first to notice this; Solaris (and Windows NT) Completion Ports are both solutions to this problem.

The FreeBSD solution was the Kqueue framework, which provides two new system calls. The kqueue() call creates a new event queue, and the kevent() call modifies the queue and receives events. This framework has since been ported to the other BSDs. OS X uses a modified FreeBSD kernel to provide the BSD subsystem and inherits Kqueue from there.

Rather than just import it and ignore it, Apple extended Kqueue on Darwin to support things like messages from Mach ports and other Darwin-specific things. This means that Kqueue is a generic way of getting messages from the kernel. This includes file descriptors being ready for reading or writing, timer events, signals, Mach events, process creation, and so on.

This made it possible to port most of GCD to FreeBSD very quickly. Apple released the core of GCD, the libdispatch library, under the Apache 2.0 license. Most of the initial port to FreeBSD involved creating a build system that didn't require XCode and adding #ifdef statements around the Mach-specific parts.

  • + Share This
  • 🔖 Save To Your Account