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; sem_.wait();
while (!queue_.try_dequeue(item)) { return queue_.dequeue();
sem_.wait();
}
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; if (!sem_.try_wait_for(time)) {
while (!queue_.try_dequeue(item)) { return folly::none;
if (!sem_.try_wait_for(time)) {
return folly::none;
}
} }
return std::move(item); return queue_.dequeue();
} }
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