proxygen
folly::detail::EventBaseLocalBase Class Reference

#include <EventBaseLocal.h>

Inheritance diagram for folly::detail::EventBaseLocalBase:
folly::detail::EventBaseLocalBaseBase folly::EventBaseLocal< T >

Public Member Functions

 EventBaseLocalBase ()
 
 ~EventBaseLocalBase () override
 
void erase (EventBase &evb)
 
void onEventBaseDestruction (EventBase &evb) override
 
- Public Member Functions inherited from folly::detail::EventBaseLocalBaseBase
virtual ~EventBaseLocalBaseBase ()=default
 

Protected Member Functions

void setVoid (EventBase &evb, std::shared_ptr< void > &&ptr)
 
void * getVoid (EventBase &evb)
 

Protected Attributes

folly::Synchronized< std::unordered_set< EventBase * > > eventBases_
 
std::size_t key_ {keyCounter_++}
 

Static Protected Attributes

static std::atomic< std::size_t > keyCounter_ {0}
 

Detailed Description

Definition at line 31 of file EventBaseLocal.h.

Constructor & Destructor Documentation

folly::detail::EventBaseLocalBase::EventBaseLocalBase ( )
inline

Definition at line 33 of file EventBaseLocal.h.

References erase(), getVoid(), onEventBaseDestruction(), ptr, setVoid(), and ~EventBaseLocalBase().

33 {}
folly::detail::EventBaseLocalBase::~EventBaseLocalBase ( )
override

Definition at line 25 of file EventBaseLocal.cpp.

References eventBases_, and key_.

Referenced by EventBaseLocalBase().

25  {
26  auto locked = eventBases_.rlock();
27  for (auto* evb : *locked) {
28  evb->runInEventBaseThread([this, evb, key = key_] {
29  evb->localStorage_.erase(key);
30  evb->localStorageToDtor_.erase(this);
31  });
32  }
33 }
folly::Synchronized< std::unordered_set< EventBase * > > eventBases_

Member Function Documentation

void folly::detail::EventBaseLocalBase::erase ( EventBase evb)

Definition at line 41 of file EventBaseLocal.cpp.

References folly::EventBase::dcheckIsInEventBaseThread(), eventBases_, key_, folly::EventBase::localStorage_, and folly::EventBase::localStorageToDtor_.

Referenced by EventBaseLocalBase(), and TEST().

41  {
42  evb.dcheckIsInEventBaseThread();
43 
44  evb.localStorage_.erase(key_);
45  evb.localStorageToDtor_.erase(this);
46 
47  eventBases_.wlock()->erase(&evb);
48 }
folly::Synchronized< std::unordered_set< EventBase * > > eventBases_
void * folly::detail::EventBaseLocalBase::getVoid ( EventBase evb)
protected

Definition at line 35 of file EventBaseLocal.cpp.

References folly::EventBase::dcheckIsInEventBaseThread(), folly::get_default(), key_, and folly::EventBase::localStorage_.

Referenced by EventBaseLocalBase(), folly::EventBaseLocal< T >::get(), folly::EventBaseLocal< T >::getOrCreate(), and folly::EventBaseLocal< T >::getOrCreateFn().

35  {
36  evb.dcheckIsInEventBaseThread();
37 
38  return folly::get_default(evb.localStorage_, key_, {}).get();
39 }
Map::mapped_type get_default(const Map &map, const Key &key)
Definition: MapUtil.h:31
void folly::detail::EventBaseLocalBase::onEventBaseDestruction ( EventBase evb)
overridevirtual

Implements folly::detail::EventBaseLocalBaseBase.

Definition at line 50 of file EventBaseLocal.cpp.

References folly::EventBase::dcheckIsInEventBaseThread(), and eventBases_.

Referenced by EventBaseLocalBase().

50  {
51  evb.dcheckIsInEventBaseThread();
52 
53  eventBases_.wlock()->erase(&evb);
54 }
folly::Synchronized< std::unordered_set< EventBase * > > eventBases_
void folly::detail::EventBaseLocalBase::setVoid ( EventBase evb,
std::shared_ptr< void > &&  ptr 
)
protected

Definition at line 56 of file EventBaseLocal.cpp.

References folly::EventBase::dcheckIsInEventBaseThread(), eventBases_, key_, keyCounter_, folly::EventBase::localStorage_, folly::EventBase::localStorageToDtor_, folly::gen::move, and ptr.

Referenced by folly::EventBaseLocal< T >::emplace(), EventBaseLocalBase(), folly::EventBaseLocal< T >::getOrCreate(), and folly::EventBaseLocal< T >::getOrCreateFn().

56  {
57  evb.dcheckIsInEventBaseThread();
58 
59  auto alreadyExists = evb.localStorage_.find(key_) != evb.localStorage_.end();
60 
61  evb.localStorage_.emplace(key_, std::move(ptr));
62 
63  if (!alreadyExists) {
64  eventBases_.wlock()->insert(&evb);
65  evb.localStorageToDtor_.insert(this);
66  }
67 }
void * ptr
folly::Synchronized< std::unordered_set< EventBase * > > eventBases_
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567

Member Data Documentation

folly::Synchronized<std::unordered_set<EventBase*> > folly::detail::EventBaseLocalBase::eventBases_
protected

Definition at line 42 of file EventBaseLocal.h.

Referenced by erase(), onEventBaseDestruction(), setVoid(), and ~EventBaseLocalBase().

std::size_t folly::detail::EventBaseLocalBase::key_ {keyCounter_++}
protected

Definition at line 44 of file EventBaseLocal.h.

Referenced by erase(), getVoid(), setVoid(), and ~EventBaseLocalBase().

std::atomic< std::size_t > folly::detail::EventBaseLocalBase::keyCounter_ {0}
staticprotected

Definition at line 43 of file EventBaseLocal.h.

Referenced by setVoid().


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