proxygen
folly::ThreadPoolExecutor::StoppedThreadQueue Class Reference

#include <ThreadPoolExecutor.h>

Inheritance diagram for folly::ThreadPoolExecutor::StoppedThreadQueue:
folly::BlockingQueue< ThreadPtr >

Public Member Functions

BlockingQueueAddResult add (ThreadPtr item) override
 
ThreadPtr take () override
 
size_t size () override
 
folly::Optional< ThreadPtrtry_take_for (std::chrono::milliseconds) override
 
- Public Member Functions inherited from folly::BlockingQueue< ThreadPtr >
virtual ~BlockingQueue ()=default
 
virtual BlockingQueueAddResult add (ThreadPtritem)=0
 
virtual BlockingQueueAddResult addWithPriority (ThreadPtritem, int8_t)
 
virtual uint8_t getNumPriorities ()
 

Private Attributes

folly::LifoSem sem_
 
std::mutex mutex_
 
std::queue< ThreadPtrqueue_
 

Detailed Description

Definition at line 273 of file ThreadPoolExecutor.h.

Member Function Documentation

BlockingQueueAddResult folly::ThreadPoolExecutor::StoppedThreadQueue::add ( ThreadPoolExecutor::ThreadPtr  item)
override

Definition at line 305 of file ThreadPoolExecutor.cpp.

References folly::gen::guard(), folly::gen::move, and mutex_.

Referenced by folly::IOThreadPoolExecutor::stopThreads(), and folly::CPUThreadPoolExecutor::threadRun().

306  {
307  std::lock_guard<std::mutex> guard(mutex_);
308  queue_.push(std::move(item));
309  return sem_.post();
310 }
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
GuardImpl guard(ErrorHandler &&handler)
Definition: Base.h:840
size_t folly::ThreadPoolExecutor::StoppedThreadQueue::size ( )
overridevirtual

Implements folly::BlockingQueue< ThreadPtr >.

Definition at line 344 of file ThreadPoolExecutor.cpp.

References folly::gen::guard(), and mutex_.

Referenced by folly::ThreadPoolExecutor::join(), and folly::ThreadPoolExecutor::stop().

344  {
345  std::lock_guard<std::mutex> guard(mutex_);
346  return queue_.size();
347 }
GuardImpl guard(ErrorHandler &&handler)
Definition: Base.h:840
ThreadPoolExecutor::ThreadPtr folly::ThreadPoolExecutor::StoppedThreadQueue::take ( )
overridevirtual

Implements folly::BlockingQueue< ThreadPtr >.

Definition at line 312 of file ThreadPoolExecutor.cpp.

References folly::gen::guard(), folly::gen::move, and mutex_.

Referenced by folly::ThreadPoolExecutor::joinStoppedThreads().

312  {
313  while (true) {
314  {
315  std::lock_guard<std::mutex> guard(mutex_);
316  if (queue_.size() > 0) {
317  auto item = std::move(queue_.front());
318  queue_.pop();
319  return item;
320  }
321  }
322  sem_.wait();
323  }
324 }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
GuardImpl guard(ErrorHandler &&handler)
Definition: Base.h:840
folly::Optional< ThreadPoolExecutor::ThreadPtr > folly::ThreadPoolExecutor::StoppedThreadQueue::try_take_for ( std::chrono::milliseconds  time)
overridevirtual

Implements folly::BlockingQueue< ThreadPtr >.

Definition at line 327 of file ThreadPoolExecutor.cpp.

References folly::gen::guard(), folly::gen::move, mutex_, and folly::none.

328  {
329  while (true) {
330  {
331  std::lock_guard<std::mutex> guard(mutex_);
332  if (queue_.size() > 0) {
333  auto item = std::move(queue_.front());
334  queue_.pop();
335  return item;
336  }
337  }
338  if (!sem_.try_wait_for(time)) {
339  return folly::none;
340  }
341  }
342 }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
GuardImpl guard(ErrorHandler &&handler)
Definition: Base.h:840
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

std::mutex folly::ThreadPoolExecutor::StoppedThreadQueue::mutex_
private

Definition at line 283 of file ThreadPoolExecutor.h.

std::queue<ThreadPtr> folly::ThreadPoolExecutor::StoppedThreadQueue::queue_
private

Definition at line 284 of file ThreadPoolExecutor.h.

folly::LifoSem folly::ThreadPoolExecutor::StoppedThreadQueue::sem_
private

Definition at line 282 of file ThreadPoolExecutor.h.


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