Commit 053c2e89 authored by Yedidya Feldblum's avatar Yedidya Feldblum Committed by Facebook Github Bot

Fix semaphore usage in UnboundedBlockingQueue

Summary:
[Folly] Fix semaphore usage in `UnboundedBlockingQueue`.

Ensure that `wait` is paired 1:1 with `post`.

Reviewed By: davidtgoldblatt, magedm

Differential Revision: D14537954

fbshipit-source-id: def54263da1a33c1b3ffa1de237a2b786572759a
parent 028e81b5
...@@ -33,21 +33,15 @@ class UnboundedBlockingQueue : public BlockingQueue<T> { ...@@ -33,21 +33,15 @@ class UnboundedBlockingQueue : public BlockingQueue<T> {
} }
T take() override { T take() override {
T item;
while (!queue_.try_dequeue(item)) {
sem_.wait(); sem_.wait();
} return queue_.dequeue();
return item;
} }
folly::Optional<T> try_take_for(std::chrono::milliseconds time) override { folly::Optional<T> try_take_for(std::chrono::milliseconds time) override {
T item;
while (!queue_.try_dequeue(item)) {
if (!sem_.try_wait_for(time)) { if (!sem_.try_wait_for(time)) {
return folly::none; return folly::none;
} }
} return queue_.dequeue();
return std::move(item);
} }
size_t size() override { size_t size() override {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment