Convert a polling loop to a futex wait
authorPhil Willoughby <philwill@fb.com>
Tue, 15 Mar 2016 08:39:48 +0000 (01:39 -0700)
committerFacebook Github Bot 6 <facebook-github-bot-6-bot@fb.com>
Tue, 15 Mar 2016 08:50:22 +0000 (01:50 -0700)
commitd43e710c813ee30f0537688dffa4cdb0b1fc5ced
tree22cbff79e37b15ada44aec877a1d6b7077084026
parentf509d73d61af081db4f29a5d272e599785a38cbf
Convert a polling loop to a futex wait

Summary:Add a new method to MPMCQueue:
```
template <class Clock, typename... Args>
  bool tryWriteUntil(const std::chrono::time_point<Clock>& when,
                     Args&&... args) noexcept
```
This allows you to write producers which terminate reliably in the absence of consumers.

Returns `true` if `args` was enqueued, `false` otherwise.

`Clock` must be one of the types supported by the underlying call to `folly::detail::Futex::futexWaitUntil`; at time of writing these are `std::chrono::steady_clock` and `std::chrono::system_clock`.

Reviewed By: nbronson

Differential Revision: D2895574

fb-gh-sync-id: bdfabcd043191c149f1271e30ffc28476cc8a36e
shipit-source-id: bdfabcd043191c149f1271e30ffc28476cc8a36e
folly/MPMCQueue.h
folly/detail/TurnSequencer.h
folly/test/MPMCQueueTest.cpp