proxygen
BlockingQueue.h
Go to the documentation of this file.
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 #pragma once
17 
18 #include <chrono>
19 #include <exception>
20 #include <stdexcept>
21 
22 #include <glog/logging.h>
23 
24 #include <folly/CPortability.h>
25 #include <folly/Optional.h>
26 
27 namespace folly {
28 
29 // Some queue implementations (for example, LifoSemMPMCQueue or
30 // PriorityLifoSemMPMCQueue) support both blocking (BLOCK) and
31 // non-blocking (THROW) behaviors.
33 
34 class FOLLY_EXPORT QueueFullException : public std::runtime_error {
35  using std::runtime_error::runtime_error; // Inherit constructors.
36 };
37 
39  BlockingQueueAddResult(bool reused = false) : reusedThread(reused) {}
41 };
42 
43 template <class T>
45  public:
46  virtual ~BlockingQueue() = default;
47  // Adds item to the queue (with priority).
48  //
49  // Returns true if an existing thread was able to work on it (used
50  // for dynamically sizing thread pools), false otherwise. Return false
51  // if this feature is not supported.
52  virtual BlockingQueueAddResult add(T item) = 0;
54  T item,
55  int8_t /* priority */) {
56  return add(std::move(item));
57  }
59  return 1;
60  }
61  virtual T take() = 0;
62  virtual folly::Optional<T> try_take_for(std::chrono::milliseconds time) = 0;
63  virtual size_t size() = 0;
64 };
65 
66 } // namespace folly
virtual uint8_t getNumPriorities()
Definition: BlockingQueue.h:58
auto add
Definition: BaseTest.cpp:70
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
folly::std T
—— Concurrent Priority Queue Implementation ——
Definition: AtomicBitSet.h:29
#define FOLLY_EXPORT
Definition: CPortability.h:133
virtual BlockingQueueAddResult addWithPriority(T item, int8_t)
Definition: BlockingQueue.h:53
BlockingQueueAddResult(bool reused=false)
Definition: BlockingQueue.h:39
constexpr auto size(C const &c) -> decltype(c.size())
Definition: Access.h:45
QueueBehaviorIfFull
Definition: BlockingQueue.h:32
detail::Take take(Number count)
Definition: Base-inl.h:2582
std::chrono::nanoseconds time()