proxygen
folly::ScopedEventBaseThread Class Reference

#include <ScopedEventBaseThread.h>

Inheritance diagram for folly::ScopedEventBaseThread:
folly::IOExecutor folly::SequencedExecutor folly::Executor folly::Executor

Public Member Functions

 ScopedEventBaseThread ()
 
 ScopedEventBaseThread (const StringPiece &name)
 
 ScopedEventBaseThread (EventBaseManager *ebm)
 
 ScopedEventBaseThread (EventBaseManager *ebm, const StringPiece &name)
 
 ~ScopedEventBaseThread ()
 
EventBasegetEventBase () const
 
EventBasegetEventBase () override
 
std::thread::id getThreadId () const
 
void add (Func func) override
 
- Public Member Functions inherited from folly::IOExecutor
 ~IOExecutor () override=default
 
- Public Member Functions inherited from folly::Executor
virtual ~Executor ()
 
virtual void addWithPriority (Func, int8_t priority)
 
virtual uint8_t getNumPriorities () const
 

Private Member Functions

 ScopedEventBaseThread (ScopedEventBaseThread &&other)=delete
 
ScopedEventBaseThreadoperator= (ScopedEventBaseThread &&other)=delete
 
 ScopedEventBaseThread (const ScopedEventBaseThread &other)=delete
 
ScopedEventBaseThreadoperator= (const ScopedEventBaseThread &other)=delete
 

Private Attributes

EventBaseManagerebm_
 
union {
   EventBase   eb_
 
}; 
 
std::thread th_
 
folly::Baton stop_
 

Additional Inherited Members

- Static Public Member Functions inherited from folly::Executor
template<typename ExecutorT >
static KeepAlive< ExecutorT > getKeepAliveToken (ExecutorT *executor)
 
template<typename ExecutorT >
static KeepAlive< ExecutorT > getKeepAliveToken (ExecutorT &executor)
 
- Static Public Attributes inherited from folly::Executor
static const int8_t LO_PRI = SCHAR_MIN
 
static const int8_t MID_PRI = 0
 
static const int8_t HI_PRI = SCHAR_MAX
 
- Protected Member Functions inherited from folly::Executor
virtual bool keepAliveAcquire ()
 
virtual void keepAliveRelease ()
 
- Static Protected Member Functions inherited from folly::Executor
template<typename ExecutorT >
static bool isKeepAliveDummy (const KeepAlive< ExecutorT > &keepAlive)
 
template<typename ExecutorT >
static KeepAlive< ExecutorT > makeKeepAlive (ExecutorT *executor)
 

Detailed Description

A helper class to start a new thread running a EventBase loop.

The new thread will be started by the ScopedEventBaseThread constructor. When the ScopedEventBaseThread object is destroyed, the thread will be stopped.

Definition at line 39 of file ScopedEventBaseThread.h.

Constructor & Destructor Documentation

folly::ScopedEventBaseThread::ScopedEventBaseThread ( )

Definition at line 50 of file ScopedEventBaseThread.cpp.

Referenced by add().

folly::ScopedEventBaseThread::ScopedEventBaseThread ( const StringPiece name)
explicit

Definition at line 53 of file ScopedEventBaseThread.cpp.

54  : ScopedEventBaseThread(nullptr, name) {}
const char * name
Definition: http_parser.c:437
folly::ScopedEventBaseThread::ScopedEventBaseThread ( EventBaseManager ebm)
explicit

Definition at line 56 of file ScopedEventBaseThread.cpp.

folly::ScopedEventBaseThread::ScopedEventBaseThread ( EventBaseManager ebm,
const StringPiece name 
)
explicit

Definition at line 59 of file ScopedEventBaseThread.cpp.

References eb_, ebm_, folly::run(), stop_, th_, and folly::EventBase::waitUntilRunning().

62  : ebm_(ebm ? ebm : EventBaseManager::get()) {
63  new (&eb_) EventBase();
64  th_ = thread(run, ebm_, &eb_, &stop_, name);
66 }
static EventBaseManager * get()
const char * name
Definition: http_parser.c:437
static void run(EventBaseManager *ebm, EventBase *eb, folly::Baton<> *stop, const StringPiece &name)
void waitUntilRunning()
Definition: EventBase.cpp:249
folly::ScopedEventBaseThread::~ScopedEventBaseThread ( )
folly::ScopedEventBaseThread::ScopedEventBaseThread ( ScopedEventBaseThread &&  other)
privatedelete
folly::ScopedEventBaseThread::ScopedEventBaseThread ( const ScopedEventBaseThread other)
privatedelete

Member Function Documentation

void folly::ScopedEventBaseThread::add ( Func  )
inlineoverridevirtual

Enqueue a function to executed by this executor. This and all variants must be threadsafe.

Implements folly::Executor.

Definition at line 61 of file ScopedEventBaseThread.h.

References folly::EventBase::add(), getEventBase(), folly::gen::move, operator=(), and ScopedEventBaseThread().

61  {
62  getEventBase()->add(std::move(func));
63  }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
void add(Cob fn) override
Implements the Executor interface.
Definition: EventBase.h:624
EventBase* folly::ScopedEventBaseThread::getEventBase ( ) const
inline

Definition at line 49 of file ScopedEventBaseThread.h.

References eb_.

Referenced by add(), folly::EvbAndContext::getEventBase(), QueueTest::sendOne(), folly::TEST(), TEST(), and TEST_F().

49  {
50  return &eb_;
51  }
EventBase* folly::ScopedEventBaseThread::getEventBase ( )
inlineoverridevirtual

Implements folly::IOExecutor.

Definition at line 53 of file ScopedEventBaseThread.h.

References eb_.

53  {
54  return &eb_;
55  }
std::thread::id folly::ScopedEventBaseThread::getThreadId ( ) const
inline

Definition at line 57 of file ScopedEventBaseThread.h.

References th_.

Referenced by TEST_F().

57  {
58  return th_.get_id();
59  }
ScopedEventBaseThread& folly::ScopedEventBaseThread::operator= ( ScopedEventBaseThread &&  other)
privatedelete

Referenced by add().

ScopedEventBaseThread& folly::ScopedEventBaseThread::operator= ( const ScopedEventBaseThread other)
privatedelete

Member Data Documentation

union { ... }
EventBase folly::ScopedEventBaseThread::eb_
mutable
EventBaseManager* folly::ScopedEventBaseThread::ebm_
private

Definition at line 72 of file ScopedEventBaseThread.h.

Referenced by ScopedEventBaseThread().

folly::Baton folly::ScopedEventBaseThread::stop_
private

Definition at line 77 of file ScopedEventBaseThread.h.

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

std::thread folly::ScopedEventBaseThread::th_
private

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