proxygen
folly::observer_detail::ObserverManager::CurrentQueue Class Reference

Public Member Functions

 CurrentQueue ()
 
 ~CurrentQueue ()
 
void add (Function< void()> task)
 

Private Attributes

MPMCQueue< Function< void()> > queue_
 
std::vector< std::thread > threads_
 

Detailed Description

Definition at line 45 of file ObserverManager.cpp.

Constructor & Destructor Documentation

folly::observer_detail::ObserverManager::CurrentQueue::CurrentQueue ( )
inline

Definition at line 47 of file ObserverManager.cpp.

References folly::exceptionStr(), i, folly::observer_detail::ObserverManager::inManagerThread_, int32_t, folly::observer_detail::kObserverManagerThreadNamePrefix, queue_, folly::setThreadName(), folly::sformat(), and threads_.

47  : queue_(kCurrentQueueSize) {
48  if (FLAGS_observer_manager_pool_size < 1) {
49  LOG(ERROR) << "--observer_manager_pool_size should be >= 1";
50  FLAGS_observer_manager_pool_size = 1;
51  }
52  for (int32_t i = 0; i < FLAGS_observer_manager_pool_size; ++i) {
53  threads_.emplace_back([this, i]() {
57 
58  while (true) {
59  Function<void()> task;
60  queue_.blockingRead(task);
61 
62  if (!task) {
63  return;
64  }
65 
66  try {
67  task();
68  } catch (...) {
69  LOG(ERROR) << "Exception while running CurrentQueue task: "
70  << exceptionStr(std::current_exception());
71  }
72  }
73  });
74  }
75  }
A polymorphic function wrapper that is not copyable and does not require the wrapped function to be c...
std::string sformat(StringPiece fmt, Args &&...args)
Definition: Format.h:280
fbstring exceptionStr(const std::exception &e)
static constexpr StringPiece kObserverManagerThreadNamePrefix
bool setThreadName(std::thread::id tid, StringPiece name)
Definition: ThreadName.cpp:109
folly::observer_detail::ObserverManager::CurrentQueue::~CurrentQueue ( )
inline

Definition at line 77 of file ObserverManager.cpp.

References i, queue_, and threads_.

77  {
78  for (size_t i = 0; i < threads_.size(); ++i) {
79  queue_.blockingWrite(nullptr);
80  }
81 
82  for (auto& thread : threads_) {
83  thread.join();
84  }
85 
86  CHECK(queue_.isEmpty());
87  }

Member Function Documentation

void folly::observer_detail::ObserverManager::CurrentQueue::add ( Function< void()>  task)
inline

Definition at line 89 of file ObserverManager.cpp.

References folly::observer_detail::ObserverManager::inManagerThread(), folly::gen::move, and queue_.

89  {
91  if (!queue_.write(std::move(task))) {
92  throw std::runtime_error("Too many Observers scheduled for update.");
93  }
94  } else {
95  queue_.blockingWrite(std::move(task));
96  }
97  }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567

Member Data Documentation

std::vector<std::thread> folly::observer_detail::ObserverManager::CurrentQueue::threads_
private

Definition at line 101 of file ObserverManager.cpp.

Referenced by CurrentQueue(), and ~CurrentQueue().


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