add tryReadUntil and make fixes along the way
authorJames Sedgwick <jsedgwick@fb.com>
Tue, 8 Nov 2016 07:13:30 +0000 (23:13 -0800)
committerFacebook Github Bot <facebook-github-bot-bot@fb.com>
Tue, 8 Nov 2016 07:23:29 +0000 (23:23 -0800)
commit5eb31cb370265933a05d1e162c137f7f0c74a5c8
treea211d20cfb2bd2fde442c7a82c4e574190ed0844
parent782325fde921b859ef6abec57eaee880d7d0d938
add tryReadUntil and make fixes along the way

Summary:
this diff adds tryReadUntil, which is a mirror of tryWriteUntil in both function and implementation.
Two bugs were exposed in the process of implementing and testing tryWriteUntil; they are fixed as well and are as follows:
  1. tryObtainPromisedPopTicket didn't assign to the passed ticket return reference in the failure case
  2. TurnSequencer::tryWaitForTurn() didn't distinguish between past turns and timeouts in the failure case; they need to be
     differentiated because SingleElementQueue::tryWaitFor{De/En}queue() should only fail in the timeout case, not if the turn has passed.

The two added unit tests are admittedly clumsy, but making the obvious simplifications to them keeps them from triggering the premature timeout race caused by bug 2 above, so I kept them as is.

Reviewed By: magedm

Differential Revision: D4050515

fbshipit-source-id: b0a3dd894d502c44be62d362ea347a1837df4c2f
folly/MPMCQueue.h
folly/detail/TurnSequencer.h
folly/experimental/LockFreeRingBuffer.h
folly/stop_watch.h
folly/test/MPMCQueueTest.cpp