Expose move result from LockFreeRingBuffer::Cursor
authorDelyan Kratunov <delyank@fb.com>
Fri, 20 Nov 2015 00:25:09 +0000 (16:25 -0800)
committerfacebook-github-bot-4 <folly-bot@fb.com>
Fri, 20 Nov 2015 01:20:20 +0000 (17:20 -0800)
commit587e4b4d914c477b79120fb6559571d2dc5d040d
treee3d86e45567594910047f81c953e5547109ea79c
parent78022b6e547c088a585bc7c5d5400978498bacf5
Expose move result from LockFreeRingBuffer::Cursor

Summary: Without feedback that a `moveForward` or `moveBackward` did nothing, a user
cannot implement this idiom safely:

```
while(rb.tryRead(entry, cursor)) {
  doSomething(entry);
  cursor.moveBackward();
}
```

In the case where the ring buffer has not overflowed and slot 0 is still
available, the reader will get stuck at it (read it continuously) until
the buffer overflows.

This diff allows the above example to become:

```
while(rb.tryRead(entry, cursor)) {
  doSomething(etnry);
  if (!cursor.moveBackward()) {
    break;
  }
}
```

Reviewed By: bryceredd

Differential Revision: D2674975

fb-gh-sync-id: a0c5857daf186ef19e203f90acc2145590f85c3b
folly/experimental/LockFreeRingBuffer.h
folly/experimental/test/LockFreeRingBufferTest.cpp