proxygen
|
#include <EventBaseManager.h>
Classes | |
struct | EventBaseInfo |
Public Member Functions | |
EventBaseManager () | |
~EventBaseManager () | |
EventBaseManager (const std::shared_ptr< EventBaseObserver > &observer) | |
EventBase * | getEventBase () const |
EventBase * | getExistingEventBase () const |
void | setEventBase (EventBase *eventBase, bool takeOwnership) |
void | clearEventBase () |
template<typename FunctionType > | |
void | withEventBaseSet (const FunctionType &runnable) |
Static Public Member Functions | |
static EventBaseManager * | get () |
Private Member Functions | |
EventBaseManager (EventBaseManager const &) | |
EventBaseManager & | operator= (EventBaseManager const &) |
void | trackEventBase (EventBase *evb) |
void | untrackEventBase (EventBase *evb) |
Private Attributes | |
folly::ThreadLocalPtr< EventBaseInfo > | localStore_ |
std::set< EventBase * > | eventBaseSet_ |
std::mutex | eventBaseSetMutex_ |
std::shared_ptr< folly::EventBaseObserver > | observer_ |
Manager for per-thread EventBase objects. This class will find or create a EventBase for the current thread, associated with thread-specific storage for that thread. Although a typical application will generally only have one EventBaseManager, there is no restriction on multiple instances; the EventBases belong to one instance are isolated from those of another.
Definition at line 36 of file EventBaseManager.h.
|
inline |
Definition at line 40 of file EventBaseManager.h.
Referenced by get(), and folly::EventBaseManager::EventBaseInfo::~EventBaseInfo().
|
inline |
Definition at line 42 of file EventBaseManager.h.
|
inlineexplicit |
Definition at line 44 of file EventBaseManager.h.
References getEventBase().
|
private |
void folly::EventBaseManager::clearEventBase | ( | ) |
Clear the EventBase for this thread.
This can be used if the code driving the EventBase loop() has finished the loop and new events should no longer be added to the EventBase.
Definition at line 56 of file EventBaseManager.cpp.
References folly::EventBaseManager::EventBaseInfo::eventBase, deadlock::info(), localStore_, and untrackEventBase().
Referenced by proxygen::WorkerThread::cleanup(), getExistingEventBase(), folly::run(), HTTPDownstreamTest< SPDY3_1CodecPair >::SetUp(), and folly::IOThreadPoolExecutor::threadRun().
|
static |
Get the global EventBaseManager for this program. Ideally all users of EventBaseManager go through this interface and do not construct EventBaseManager directly.
Definition at line 23 of file EventBaseManager.cpp.
References EventBaseManager(), and folly::globalManager().
Referenced by wangle::ServerBootstrap< DefaultPipeline >::bind(), wangle::ClientBootstrap< DefaultPipeline >::connect(), TestClientPipelineFactory::newPipeline(), wangle::AsyncServerSocketFactory::newSocket(), wangle::AsyncUDPServerSocketFactory::newSocket(), StaticService::StaticHandler::onEgressResumed(), StaticService::StaticHandler::onRequest(), ProxyService::ProxyHandler::onRequest(), HTTPDownstreamTest< SPDY3_1CodecPair >::SetUp(), TEST(), wangle::TEST(), TEST_F(), and proxygen::WheelTimerInstance::WheelTimerInstance().
EventBase * folly::EventBaseManager::getEventBase | ( | ) | const |
Get the EventBase for this thread, or create one if none exists yet.
If no EventBase exists for this thread yet, a new one will be created and returned. May throw std::bad_alloc if allocation fails.
Definition at line 65 of file EventBaseManager.cpp.
References deadlock::info(), localStore_, and observer_.
Referenced by wangle::ClientBootstrap< DefaultPipeline >::connect(), EventBaseManager(), TestClientPipelineFactory::newPipeline(), wangle::AsyncServerSocketFactory::newSocket(), wangle::AsyncUDPServerSocketFactory::newSocket(), ProxyService::ProxyHandler::onRequest(), TEST(), wangle::TEST(), TEST_F(), folly::IOThreadPoolExecutor::threadRun(), and proxygen::WheelTimerInstance::WheelTimerInstance().
|
inline |
Get the EventBase for this thread.
Returns nullptr if no EventBase has been created for this thread yet.
Definition at line 67 of file EventBaseManager.h.
References clearEventBase(), folly::EventBaseManager::EventBaseInfo::eventBase, deadlock::info(), localStore_, and setEventBase().
|
private |
Referenced by folly::EventBaseManager::EventBaseInfo::~EventBaseInfo().
void folly::EventBaseManager::setEventBase | ( | EventBase * | eventBase, |
bool | takeOwnership | ||
) |
Set the EventBase to be used by this thread.
This may only be called if no EventBase has been defined for this thread yet. If a EventBase is already defined for this thread, a std::runtime_error is thrown. std::bad_alloc may also be thrown if allocation fails while setting the EventBase.
This should typically be invoked by the code that will call loop() on the EventBase, to make sure the EventBaseManager points to the correct EventBase that is actually running in this thread.
Definition at line 43 of file EventBaseManager.cpp.
References deadlock::info(), localStore_, and trackEventBase().
Referenced by getExistingEventBase(), folly::run(), proxygen::WorkerThread::setup(), and TEST_F().
|
inlineprivate |
Definition at line 130 of file EventBaseManager.h.
References eventBaseSet_, eventBaseSetMutex_, and g().
Referenced by setEventBase().
|
inlineprivate |
Definition at line 135 of file EventBaseManager.h.
References eventBaseSet_, eventBaseSetMutex_, and g().
Referenced by clearEventBase().
|
inline |
Gives the caller all references to all assigned EventBase instances at this moment in time. Locks a mutex so that these EventBase set cannot be changed, and also the caller can rely on no instances being destructed.
Definition at line 103 of file EventBaseManager.h.
References eventBaseSet_, eventBaseSetMutex_, and g().
Definition at line 145 of file EventBaseManager.h.
Referenced by trackEventBase(), untrackEventBase(), and withEventBaseSet().
|
private |
Definition at line 148 of file EventBaseManager.h.
Referenced by trackEventBase(), untrackEventBase(), and withEventBaseSet().
|
mutableprivate |
Definition at line 140 of file EventBaseManager.h.
Referenced by clearEventBase(), getEventBase(), getExistingEventBase(), and setEventBase().
|
private |
Definition at line 150 of file EventBaseManager.h.
Referenced by getEventBase().