UnboundedBlockingQueue: Remove extra include
[folly.git] / folly / executors / task_queue / UnboundedBlockingQueue.h
1 /*
2  * Copyright 2017-present Facebook, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *   http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #pragma once
18
19 #include <folly/concurrency/UnboundedQueue.h>
20 #include <folly/executors/task_queue/BlockingQueue.h>
21 #include <folly/synchronization/LifoSem.h>
22
23 namespace folly {
24
25 template <class T>
26 class UnboundedBlockingQueue : public BlockingQueue<T> {
27  public:
28   virtual ~UnboundedBlockingQueue() {}
29
30   void add(T item) override {
31     queue_.enqueue(std::move(item));
32     sem_.post();
33   }
34
35   T take() override {
36     T item;
37     while (!queue_.try_dequeue(item)) {
38       sem_.wait();
39     }
40     return item;
41   }
42
43   size_t size() override {
44     return queue_.size();
45   }
46
47  private:
48   LifoSem sem_;
49   UMPMCQueue<T, false> queue_;
50 };
51
52 } // namespace folly