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

#include <LifoSemMPMCQueue.h>

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

Public Member Functions

 LifoSemMPMCQueue (size_t max_capacity)
 
BlockingQueueAddResult add (T item) override
 
T take () override
 
folly::Optional< Ttry_take_for (std::chrono::milliseconds time) override
 
size_t capacity ()
 
size_t size () override
 
- Public Member Functions inherited from folly::BlockingQueue< T >
virtual ~BlockingQueue ()=default
 
virtual BlockingQueueAddResult addWithPriority (T item, int8_t)
 
virtual uint8_t getNumPriorities ()
 

Private Attributes

folly::LifoSem sem_
 
folly::MPMCQueue< Tqueue_
 

Detailed Description

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

Definition at line 26 of file LifoSemMPMCQueue.h.

Constructor & Destructor Documentation

template<class T , QueueBehaviorIfFull kBehavior = QueueBehaviorIfFull::THROW>
folly::LifoSemMPMCQueue< T, kBehavior >::LifoSemMPMCQueue ( size_t  max_capacity)
inlineexplicit

Definition at line 29 of file LifoSemMPMCQueue.h.

29 : queue_(max_capacity) {}
folly::MPMCQueue< T > queue_

Member Function Documentation

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

Implements folly::BlockingQueue< T >.

Definition at line 31 of file LifoSemMPMCQueue.h.

References folly::BLOCK, folly::gen::move, folly::detail::LifoSemBase< Handoff, Atom >::post(), folly::LifoSemMPMCQueue< T, kBehavior >::queue_, folly::LifoSemMPMCQueue< T, kBehavior >::sem_, and folly::THROW.

31  {
32  switch (kBehavior) { // static
34  if (!queue_.write(std::move(item))) {
35  throw QueueFullException("LifoSemMPMCQueue full, can't add item");
36  }
37  break;
39  queue_.blockingWrite(std::move(item));
40  break;
41  }
42  return sem_.post();
43  }
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
folly::MPMCQueue< T > queue_
template<class T , QueueBehaviorIfFull kBehavior = QueueBehaviorIfFull::THROW>
size_t folly::LifoSemMPMCQueue< T, kBehavior >::capacity ( )
inline

Definition at line 63 of file LifoSemMPMCQueue.h.

References folly::LifoSemMPMCQueue< T, kBehavior >::queue_.

63  {
64  return queue_.capacity();
65  }
folly::MPMCQueue< T > queue_
template<class T , QueueBehaviorIfFull kBehavior = QueueBehaviorIfFull::THROW>
size_t folly::LifoSemMPMCQueue< T, kBehavior >::size ( )
inlineoverridevirtual

Implements folly::BlockingQueue< T >.

Definition at line 67 of file LifoSemMPMCQueue.h.

References folly::LifoSemMPMCQueue< T, kBehavior >::queue_.

67  {
68  return queue_.size();
69  }
folly::MPMCQueue< T > queue_
template<class T , QueueBehaviorIfFull kBehavior = QueueBehaviorIfFull::THROW>
T folly::LifoSemMPMCQueue< T, kBehavior >::take ( )
inlineoverridevirtual

Implements folly::BlockingQueue< T >.

Definition at line 45 of file LifoSemMPMCQueue.h.

References folly::LifoSemMPMCQueue< T, kBehavior >::queue_, folly::LifoSemMPMCQueue< T, kBehavior >::sem_, folly::T, and folly::detail::LifoSemBase< Handoff, Atom >::wait().

45  {
46  T item;
47  while (!queue_.readIfNotEmpty(item)) {
48  sem_.wait();
49  }
50  return item;
51  }
folly::std T
folly::MPMCQueue< T > queue_
template<class T , QueueBehaviorIfFull kBehavior = QueueBehaviorIfFull::THROW>
folly::Optional<T> folly::LifoSemMPMCQueue< T, kBehavior >::try_take_for ( std::chrono::milliseconds  time)
inlineoverridevirtual

Implements folly::BlockingQueue< T >.

Definition at line 53 of file LifoSemMPMCQueue.h.

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

53  {
54  T item;
55  while (!queue_.readIfNotEmpty(item)) {
56  if (!sem_.try_wait_for(time)) {
57  return folly::none;
58  }
59  }
60  return std::move(item);
61  }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
folly::std T
folly::MPMCQueue< T > queue_
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

template<class T , QueueBehaviorIfFull kBehavior = QueueBehaviorIfFull::THROW>
folly::LifoSem folly::LifoSemMPMCQueue< T, kBehavior >::sem_
private

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