Reimplement base::WaitableEvent with a kqueue on Mac.

For a single WaitableEvent, a custom EVFILT_USER kevent is used to wait and
signal. This replaces the default POSIX implementation that uses a
pthread_cond_t and a boolean flag.

To implement WaitMany, a new kqueue is created to wait on all the individual
WaitableEvent's kqueue descriptor. This replaces a complex locking algorithm
used in the default POSIX implementation.

For the asynchronous WaitableEventWatcher, a TYPE_READ dispatch_source_t is
used to watch the WaitableEvent's kqueue. This replaces the POSIX
implementation of a reference-counted list of async watchers guarded by a lock.

Microbenchmarks show that the kqueue implementation is significantly faster in
most cases. The one potential drawback is hitting the low RLIMIT_NOFILE on
macOS, since each WaitableEvent and WaitableEventWatcher requires a new
descriptor.

Bug: 681167
Change-Id: I135012fdd25e547ffb911fc7adc97c203df38241
Reviewed-on: https://chromium-review.googlesource.com/553497
Reviewed-by: Robert Liao <robliao@chromium.org>
Reviewed-by: Mark Mentovai <mark@chromium.org>
Commit-Queue: Robert Sesek <rsesek@chromium.org>
Cr-Commit-Position: refs/heads/master@{#485788}

CrOS-Libchrome-Original-Commit: 2096391cdcc3bdf963e68977e9015aa8cdbe85c6
3 files changed
tree: d36e9f2a63477a72a562964736924afcd242f558
  1. base/
  2. build/
  3. components/
  4. dbus/
  5. device/
  6. ipc/
  7. mojo/
  8. testing/
  9. third_party/
  10. ui/