Commit 00c84e07 authored by Dan Melnic's avatar Dan Melnic Committed by Facebook GitHub Bot

Add support for creating an EventBaseManager with a custom backend factory method

Summary:
Add support for creating an EventBaseManager with a custom backend factory method

(Note: this ignores all push blocking failures!)

Reviewed By: kevin-vigor

Differential Revision: D20513736

fbshipit-source-id: 62edc876cd1c0667bd7beb85a3d6fbd9a5a03ebf
parent 3df1b70d
......@@ -115,6 +115,8 @@ class EventBaseEvent {
class EventBaseBackendBase {
public:
using Event = EventBaseEvent;
using FactoryFunc =
std::function<std::unique_ptr<folly::EventBaseBackendBase>()>;
EventBaseBackendBase() = default;
virtual ~EventBaseBackendBase() = default;
......
......@@ -66,7 +66,7 @@ EventBase* EventBaseManager::getEventBase() const {
// have one?
auto* info = localStore_.get();
if (!info) {
info = new EventBaseInfo();
info = func_ ? new EventBaseInfo(func_()) : new EventBaseInfo();
localStore_.reset(info);
if (observer_) {
......
......@@ -39,6 +39,9 @@ class EventBaseManager {
// encouraged. You should instead use the global singleton if possible.
EventBaseManager() {}
explicit EventBaseManager(folly::EventBaseBackendBase::FactoryFunc func)
: func_(func) {}
~EventBaseManager() {}
explicit EventBaseManager(const std::shared_ptr<EventBaseObserver>& observer)
......@@ -111,7 +114,8 @@ class EventBaseManager {
private:
struct EventBaseInfo {
EventBaseInfo(EventBase* evb, bool owned) : eventBase(evb), owned_(owned) {}
explicit EventBaseInfo(std::unique_ptr<EventBaseBackendBase>&& evb)
: eventBase(new EventBase(std::move(evb))), owned_(true) {}
EventBaseInfo() : eventBase(new EventBase), owned_(true) {}
EventBase* eventBase;
......@@ -137,6 +141,8 @@ class EventBaseManager {
eventBaseSet_.erase(evb);
}
folly::EventBaseBackendBase::FactoryFunc func_;
mutable folly::ThreadLocalPtr<EventBaseInfo> localStore_;
// set of "active" EventBase instances
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment