proxygen
folly::PriorityLifoSemMPMCQueue< T, kBehavior > Class Template Reference

#include <PriorityLifoSemMPMCQueue.h>

Inheritance diagram for folly::PriorityLifoSemMPMCQueue< T, kBehavior >:
folly::BlockingQueue< T >

Public Member Functions

 PriorityLifoSemMPMCQueue (uint8_t numPriorities, size_t max_capacity)
 
 PriorityLifoSemMPMCQueue (folly::Range< const size_t * > capacities)
 
uint8_t getNumPriorities () override
 
BlockingQueueAddResult add (T item) override
 
BlockingQueueAddResult addWithPriority (T item, int8_t priority) override
 
T take () override
 
folly::Optional< Ttry_take_for (std::chrono::milliseconds time) override
 
bool nonBlockingTake (T &item)
 
size_t size () override
 
size_t sizeGuess () const
 
- Public Member Functions inherited from folly::BlockingQueue< T >
virtual ~BlockingQueue ()=default
 

Private Attributes

folly::LifoSem sem_
 
std::vector< folly::MPMCQueue< T > > queues_
 

Detailed Description

template<class T, QueueBehaviorIfFull kBehavior = QueueBehaviorIfFull::THROW>
class folly::PriorityLifoSemMPMCQueue< T, kBehavior >

Definition at line 29 of file PriorityLifoSemMPMCQueue.h.

Constructor & Destructor Documentation

template<class T, QueueBehaviorIfFull kBehavior = QueueBehaviorIfFull::THROW>
folly::PriorityLifoSemMPMCQueue< T, kBehavior >::PriorityLifoSemMPMCQueue ( uint8_t  numPriorities,
size_t  max_capacity 
)
inline

Definition at line 34 of file PriorityLifoSemMPMCQueue.h.

References i, int8_t, and folly::PriorityLifoSemMPMCQueue< T, kBehavior >::queues_.

34  {
35  queues_.reserve(numPriorities);
36  for (int8_t i = 0; i < numPriorities; i++) {
37  queues_.emplace_back(max_capacity);
38  }
39  }
std::vector< folly::MPMCQueue< T > > queues_
template<class T, QueueBehaviorIfFull kBehavior = QueueBehaviorIfFull::THROW>
folly::PriorityLifoSemMPMCQueue< T, kBehavior >::PriorityLifoSemMPMCQueue ( folly::Range< const size_t * >  capacities)
inline

Definition at line 41 of file PriorityLifoSemMPMCQueue.h.

References folly::PriorityLifoSemMPMCQueue< T, kBehavior >::queues_, and folly::Range< Iter >::size().

41  {
42  CHECK_LT(capacities.size(), 256) << "At most 255 priorities supported";
43 
44  queues_.reserve(capacities.size());
45  for (auto capacity : capacities) {
46  queues_.emplace_back(capacity);
47  }
48  }
constexpr size_type size() const
Definition: Range.h:431
std::vector< folly::MPMCQueue< T > > queues_

Member Function Documentation

template<class T, QueueBehaviorIfFull kBehavior = QueueBehaviorIfFull::THROW>
BlockingQueueAddResult folly::PriorityLifoSemMPMCQueue< T, kBehavior >::add ( T  item)
inlineoverridevirtual

Implements folly::BlockingQueue< T >.

Definition at line 55 of file PriorityLifoSemMPMCQueue.h.

References folly::PriorityLifoSemMPMCQueue< T, kBehavior >::addWithPriority(), folly::Executor::MID_PRI, and folly::gen::move.

55  {
57  }
static const int8_t MID_PRI
Definition: Executor.h:49
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
BlockingQueueAddResult addWithPriority(T item, int8_t priority) override
template<class T, QueueBehaviorIfFull kBehavior = QueueBehaviorIfFull::THROW>
BlockingQueueAddResult folly::PriorityLifoSemMPMCQueue< T, kBehavior >::addWithPriority ( T  item,
int8_t  priority 
)
inlineoverridevirtual

Reimplemented from folly::BlockingQueue< T >.

Definition at line 59 of file PriorityLifoSemMPMCQueue.h.

References folly::BLOCK, folly::PriorityLifoSemMPMCQueue< T, kBehavior >::getNumPriorities(), max, min, folly::gen::move, folly::detail::LifoSemBase< Handoff, Atom >::post(), folly::PriorityLifoSemMPMCQueue< T, kBehavior >::queues_, folly::PriorityLifoSemMPMCQueue< T, kBehavior >::sem_, folly::THROW, and fizz::detail::write().

Referenced by folly::PriorityLifoSemMPMCQueue< T, kBehavior >::add(), and TEST().

59  {
60  int mid = getNumPriorities() / 2;
61  size_t queue = priority < 0
62  ? std::max(0, mid + priority)
63  : std::min(getNumPriorities() - 1, mid + priority);
64  CHECK_LT(queue, queues_.size());
65  switch (kBehavior) { // static
67  if (!queues_[queue].write(std::move(item))) {
68  throw QueueFullException("LifoSemMPMCQueue full, can't add item");
69  }
70  break;
72  queues_[queue].blockingWrite(std::move(item));
73  break;
74  }
75  return sem_.post();
76  }
void write(const T &in, folly::io::Appender &appender)
Definition: Types-inl.h:112
LogLevel max
Definition: LogLevel.cpp:31
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
bool post()
Silently saturates if value is already 2^32-1.
Definition: LifoSem.h:361
STL namespace.
std::vector< folly::MPMCQueue< T > > queues_
LogLevel min
Definition: LogLevel.cpp:30
template<class T, QueueBehaviorIfFull kBehavior = QueueBehaviorIfFull::THROW>
uint8_t folly::PriorityLifoSemMPMCQueue< T, kBehavior >::getNumPriorities ( )
inlineoverridevirtual

Reimplemented from folly::BlockingQueue< T >.

Definition at line 50 of file PriorityLifoSemMPMCQueue.h.

References folly::PriorityLifoSemMPMCQueue< T, kBehavior >::queues_.

Referenced by folly::PriorityLifoSemMPMCQueue< T, kBehavior >::addWithPriority().

50  {
51  return queues_.size();
52  }
std::vector< folly::MPMCQueue< T > > queues_
template<class T, QueueBehaviorIfFull kBehavior = QueueBehaviorIfFull::THROW>
bool folly::PriorityLifoSemMPMCQueue< T, kBehavior >::nonBlockingTake ( T item)
inline

Definition at line 100 of file PriorityLifoSemMPMCQueue.h.

References folly::PriorityLifoSemMPMCQueue< T, kBehavior >::queues_.

Referenced by folly::PriorityLifoSemMPMCQueue< T, kBehavior >::take(), and folly::PriorityLifoSemMPMCQueue< T, kBehavior >::try_take_for().

100  {
101  for (auto it = queues_.rbegin(); it != queues_.rend(); it++) {
102  if (it->readIfNotEmpty(item)) {
103  return true;
104  }
105  }
106  return false;
107  }
std::vector< folly::MPMCQueue< T > > queues_
template<class T, QueueBehaviorIfFull kBehavior = QueueBehaviorIfFull::THROW>
size_t folly::PriorityLifoSemMPMCQueue< T, kBehavior >::size ( )
inlineoverridevirtual

Implements folly::BlockingQueue< T >.

Definition at line 109 of file PriorityLifoSemMPMCQueue.h.

References folly::PriorityLifoSemMPMCQueue< T, kBehavior >::queues_.

Referenced by folly::PriorityLifoSemMPMCQueue< T, kBehavior >::sizeGuess().

109  {
110  size_t size = 0;
111  for (auto& q : queues_) {
112  size += q.size();
113  }
114  return size;
115  }
std::vector< folly::MPMCQueue< T > > queues_
template<class T, QueueBehaviorIfFull kBehavior = QueueBehaviorIfFull::THROW>
size_t folly::PriorityLifoSemMPMCQueue< T, kBehavior >::sizeGuess ( ) const
inline

Definition at line 117 of file PriorityLifoSemMPMCQueue.h.

References folly::PriorityLifoSemMPMCQueue< T, kBehavior >::queues_, and folly::PriorityLifoSemMPMCQueue< T, kBehavior >::size().

117  {
118  size_t size = 0;
119  for (auto& q : queues_) {
120  size += q.sizeGuess();
121  }
122  return size;
123  }
std::vector< folly::MPMCQueue< T > > queues_
template<class T, QueueBehaviorIfFull kBehavior = QueueBehaviorIfFull::THROW>
T folly::PriorityLifoSemMPMCQueue< T, kBehavior >::take ( )
inlineoverridevirtual
template<class T, QueueBehaviorIfFull kBehavior = QueueBehaviorIfFull::THROW>
folly::Optional<T> folly::PriorityLifoSemMPMCQueue< T, kBehavior >::try_take_for ( std::chrono::milliseconds  time)
inlineoverridevirtual

Implements folly::BlockingQueue< T >.

Definition at line 88 of file PriorityLifoSemMPMCQueue.h.

References folly::gen::move, folly::PriorityLifoSemMPMCQueue< T, kBehavior >::nonBlockingTake(), folly::none, folly::PriorityLifoSemMPMCQueue< T, kBehavior >::sem_, folly::T, and folly::detail::LifoSemBase< Handoff, Atom >::try_wait_for().

88  {
89  T item;
90  while (true) {
91  if (nonBlockingTake(item)) {
92  return std::move(item);
93  }
94  if (!sem_.try_wait_for(time)) {
95  return folly::none;
96  }
97  }
98  }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
folly::std T
bool try_wait_for(const std::chrono::duration< Rep, Period > &timeout)
Definition: LifoSem.h:472
std::chrono::nanoseconds time()
constexpr None none
Definition: Optional.h:87

Member Data Documentation


The documentation for this class was generated from the following file: