2 * Copyright 2015 Facebook, Inc.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #ifndef __STDC_FORMAT_MACROS
18 #define __STDC_FORMAT_MACROS
21 #include <folly/io/async/EventBase.h>
23 #include <folly/ThreadName.h>
24 #include <folly/io/async/NotificationQueue.h>
26 #include <boost/static_assert.hpp>
27 #include <condition_variable>
36 using folly::EventBase;
38 template <typename Callback>
39 class FunctionLoopCallback : public EventBase::LoopCallback {
41 explicit FunctionLoopCallback(Cob&& function)
42 : function_(std::move(function)) {}
44 explicit FunctionLoopCallback(const Cob& function)
45 : function_(function) {}
47 void runLoopCallback() noexcept override {
63 * EventBase::FunctionRunner
66 class EventBase::FunctionRunner
67 : public NotificationQueue<std::pair<void (*)(void*), void*>>::Consumer {
69 void messageAvailable(std::pair<void (*)(void*), void*>&& msg) override {
71 // In libevent2, internal events do not break the loop.
72 // Most users would expect loop(), followed by runInEventBaseThread(),
73 // to break the loop and check if it should exit or not.
74 // To have similar bejaviour to libevent1.4, tell the loop to break here.
75 // Note that loop() may still continue to loop, but it will also check the
76 // stop_ flag as well as runInLoop callbacks, etc.
77 event_base_loopbreak(getEventBase()->evb_);
79 if (msg.first == nullptr && msg.second == nullptr) {
80 // terminateLoopSoon() sends a null message just to
81 // wake up the loop. We can ignore these messages.
85 // If function is nullptr, just log and move on
87 LOG(ERROR) << "nullptr callback registered to be run in "
88 << "event base thread";
92 // The function should never throw an exception, because we have no
93 // way of knowing what sort of error handling to perform.
95 // If it does throw, log a message and abort the program.
97 msg.first(msg.second);
98 } catch (const std::exception& ex) {
99 LOG(ERROR) << "runInEventBaseThread() function threw a "
100 << typeid(ex).name() << " exception: " << ex.what();
103 LOG(ERROR) << "runInEventBaseThread() function threw an exception";
110 * EventBase::CobTimeout methods
113 void EventBase::CobTimeout::timeoutExpired() noexcept {
114 // For now, we just swallow any exceptions that the callback threw.
117 } catch (const std::exception& ex) {
118 LOG(ERROR) << "EventBase::runAfterDelay() callback threw "
119 << typeid(ex).name() << " exception: " << ex.what();
121 LOG(ERROR) << "EventBase::runAfterDelay() callback threw non-exception "
125 // The CobTimeout object was allocated on the heap by runAfterDelay(),
126 // so delete it now that the it has fired.
131 // The interface used to libevent is not thread-safe. Calls to
132 // event_init() and event_base_free() directly modify an internal
133 // global 'current_base', so a mutex is required to protect this.
135 // event_init() should only ever be called once. Subsequent calls
136 // should be made to event_base_new(). We can recognise that
137 // event_init() has already been called by simply inspecting current_base.
138 static std::mutex libevent_mutex_;
144 EventBase::EventBase(bool enableTimeMeasurement)
145 : runOnceCallbacks_(nullptr)
151 , avgLoopTime_(2000000)
152 , maxLatencyLoopTime_(avgLoopTime_)
153 , enableTimeMeasurement_(enableTimeMeasurement)
154 , nextLoopCnt_(-40) // Early wrap-around so bugs will manifest soon
155 , latestLoopCnt_(nextLoopCnt_)
158 , observerSampleCount_(0)
159 , executionObserver_(nullptr) {
161 std::lock_guard<std::mutex> lock(libevent_mutex_);
163 // The value 'current_base' (libevent 1) or
164 // 'event_global_current_base_' (libevent 2) is filled in by event_set(),
165 // allowing examination of its value without an explicit reference here.
166 // If ev.ev_base is NULL, then event_init() must be called, otherwise
167 // call event_base_new().
169 event_set(&ev, 0, 0, nullptr, nullptr);
170 evb_ = (ev.ev_base) ? event_base_new() : event_init();
172 if (UNLIKELY(evb_ == nullptr)) {
173 LOG(ERROR) << "EventBase(): Failed to init event base.";
174 folly::throwSystemError("error in EventBase::EventBase()");
176 VLOG(5) << "EventBase(): Created.";
177 initNotificationQueue();
178 RequestContext::saveContext();
181 // takes ownership of the event_base
182 EventBase::EventBase(event_base* evb, bool enableTimeMeasurement)
183 : runOnceCallbacks_(nullptr)
190 , avgLoopTime_(2000000)
191 , maxLatencyLoopTime_(avgLoopTime_)
192 , enableTimeMeasurement_(enableTimeMeasurement)
193 , nextLoopCnt_(-40) // Early wrap-around so bugs will manifest soon
194 , latestLoopCnt_(nextLoopCnt_)
197 , observerSampleCount_(0)
198 , executionObserver_(nullptr) {
199 if (UNLIKELY(evb_ == nullptr)) {
200 LOG(ERROR) << "EventBase(): Pass nullptr as event base.";
201 throw std::invalid_argument("EventBase(): event base cannot be nullptr");
203 initNotificationQueue();
204 RequestContext::saveContext();
207 EventBase::~EventBase() {
208 // Call all destruction callbacks, before we start cleaning up our state.
209 while (!onDestructionCallbacks_.empty()) {
210 LoopCallback* callback = &onDestructionCallbacks_.front();
211 onDestructionCallbacks_.pop_front();
212 callback->runLoopCallback();
215 // Delete any unfired callback objects, so that we don't leak memory
216 // (Note that we don't fire them. The caller is responsible for cleaning up
217 // its own data structures if it destroys the EventBase with unfired events
219 while (!pendingCobTimeouts_.empty()) {
220 CobTimeout* timeout = &pendingCobTimeouts_.front();
224 while (!runBeforeLoopCallbacks_.empty()) {
225 delete &runBeforeLoopCallbacks_.front();
228 (void) runLoopCallbacks(false);
230 if (!fnRunner_->consumeUntilDrained()) {
231 LOG(ERROR) << "~EventBase(): Unable to drain notification queue";
234 // Stop consumer before deleting NotificationQueue
235 fnRunner_->stopConsuming();
237 std::lock_guard<std::mutex> lock(libevent_mutex_);
238 event_base_free(evb_);
241 while (!runAfterDrainCallbacks_.empty()) {
242 LoopCallback* callback = &runAfterDrainCallbacks_.front();
243 runAfterDrainCallbacks_.pop_front();
244 callback->runLoopCallback();
248 std::lock_guard<std::mutex> lock(localStorageMutex_);
249 for (auto storage : localStorageToDtor_) {
250 storage->onEventBaseDestruction(*this);
253 VLOG(5) << "EventBase(): Destroyed.";
256 int EventBase::getNotificationQueueSize() const {
257 return queue_->size();
260 void EventBase::setMaxReadAtOnce(uint32_t maxAtOnce) {
261 fnRunner_->setMaxReadAtOnce(maxAtOnce);
264 // Set smoothing coefficient for loop load average; input is # of milliseconds
265 // for exp(-1) decay.
266 void EventBase::setLoadAvgMsec(uint32_t ms) {
267 assert(enableTimeMeasurement_);
268 uint64_t us = 1000 * ms;
270 maxLatencyLoopTime_.setTimeInterval(us);
271 avgLoopTime_.setTimeInterval(us);
273 LOG(ERROR) << "non-positive arg to setLoadAvgMsec()";
277 void EventBase::resetLoadAvg(double value) {
278 assert(enableTimeMeasurement_);
279 avgLoopTime_.reset(value);
280 maxLatencyLoopTime_.reset(value);
283 static std::chrono::milliseconds
284 getTimeDelta(std::chrono::steady_clock::time_point* prev) {
285 auto result = std::chrono::steady_clock::now() - *prev;
286 *prev = std::chrono::steady_clock::now();
288 return std::chrono::duration_cast<std::chrono::milliseconds>(result);
291 void EventBase::waitUntilRunning() {
292 while (!isRunning()) {
297 // enters the event_base loop -- will only exit when forced to
298 bool EventBase::loop() {
302 bool EventBase::loopOnce(int flags) {
303 return loopBody(flags | EVLOOP_ONCE);
306 bool EventBase::loopBody(int flags) {
307 VLOG(5) << "EventBase(): Starting loop.";
309 bool ranLoopCallbacks;
310 bool blocking = !(flags & EVLOOP_NONBLOCK);
311 bool once = (flags & EVLOOP_ONCE);
313 // time-measurement variables.
314 std::chrono::steady_clock::time_point prev;
319 loopThread_.store(pthread_self(), std::memory_order_release);
321 if (!name_.empty()) {
322 setThreadName(name_);
325 if (enableTimeMeasurement_) {
326 prev = std::chrono::steady_clock::now();
327 idleStart = std::chrono::duration_cast<std::chrono::microseconds>(
328 std::chrono::steady_clock::now().time_since_epoch()).count();
331 while (!stop_.load(std::memory_order_acquire)) {
334 // Run the before loop callbacks
335 LoopCallbackList callbacks;
336 callbacks.swap(runBeforeLoopCallbacks_);
338 while(!callbacks.empty()) {
339 auto* item = &callbacks.front();
340 callbacks.pop_front();
341 item->runLoopCallback();
344 // nobody can add loop callbacks from within this thread if
345 // we don't have to handle anything to start with...
346 if (blocking && loopCallbacks_.empty()) {
347 res = event_base_loop(evb_, EVLOOP_ONCE);
349 res = event_base_loop(evb_, EVLOOP_ONCE | EVLOOP_NONBLOCK);
352 ranLoopCallbacks = runLoopCallbacks();
354 if (enableTimeMeasurement_) {
355 busy = std::chrono::duration_cast<std::chrono::microseconds>(
356 std::chrono::steady_clock::now().time_since_epoch()).count() -
358 idle = startWork_ - idleStart;
360 avgLoopTime_.addSample(idle, busy);
361 maxLatencyLoopTime_.addSample(idle, busy);
364 if (observerSampleCount_++ == observer_->getSampleRate()) {
365 observerSampleCount_ = 0;
366 observer_->loopSample(busy, idle);
370 VLOG(11) << "EventBase " << this << " did not timeout "
371 " loop time guess: " << busy + idle <<
372 " idle time: " << idle <<
373 " busy time: " << busy <<
374 " avgLoopTime: " << avgLoopTime_.get() <<
375 " maxLatencyLoopTime: " << maxLatencyLoopTime_.get() <<
376 " maxLatency_: " << maxLatency_ <<
377 " nothingHandledYet(): "<< nothingHandledYet();
379 // see if our average loop time has exceeded our limit
380 if ((maxLatency_ > 0) &&
381 (maxLatencyLoopTime_.get() > double(maxLatency_))) {
383 // back off temporarily -- don't keep spamming maxLatencyCob_
384 // if we're only a bit over the limit
385 maxLatencyLoopTime_.dampen(0.9);
388 // Our loop run did real work; reset the idle timer
389 idleStart = std::chrono::duration_cast<std::chrono::microseconds>(
390 std::chrono::steady_clock::now().time_since_epoch()).count();
392 VLOG(11) << "EventBase " << this << " did not timeout "
393 " time measurement is disabled "
394 " nothingHandledYet(): "<< nothingHandledYet();
397 // If the event loop indicate that there were no more events, and
398 // we also didn't have any loop callbacks to run, there is nothing left to
400 if (res != 0 && !ranLoopCallbacks) {
401 // Since Notification Queue is marked 'internal' some events may not have
402 // run. Run them manually if so, and continue looping.
404 if (getNotificationQueueSize() > 0) {
405 fnRunner_->handlerReady(0);
411 if (enableTimeMeasurement_) {
412 VLOG(5) << "EventBase " << this << " loop time: " <<
413 getTimeDelta(&prev).count();
420 // Reset stop_ so loop() can be called again
424 LOG(ERROR) << "EventBase: -- error in event loop, res = " << res;
426 } else if (res == 1) {
427 VLOG(5) << "EventBase: ran out of events (exiting loop)!";
428 } else if (res > 1) {
429 LOG(ERROR) << "EventBase: unknown event loop result = " << res;
433 loopThread_.store(0, std::memory_order_release);
435 VLOG(5) << "EventBase(): Done with loop.";
439 void EventBase::loopForever() {
440 // Update the notification queue event to treat it as a normal (non-internal)
441 // event. The notification queue event always remains installed, and the main
442 // loop won't exit with it installed.
443 fnRunner_->stopConsuming();
444 fnRunner_->startConsuming(this, queue_.get());
448 // Restore the notification queue internal flag
449 fnRunner_->stopConsuming();
450 fnRunner_->startConsumingInternal(this, queue_.get());
453 folly::throwSystemError("error in EventBase::loopForever()");
457 bool EventBase::bumpHandlingTime() {
458 VLOG(11) << "EventBase " << this << " " << __PRETTY_FUNCTION__ <<
459 " (loop) latest " << latestLoopCnt_ << " next " << nextLoopCnt_;
460 if(nothingHandledYet()) {
461 latestLoopCnt_ = nextLoopCnt_;
463 startWork_ = std::chrono::duration_cast<std::chrono::microseconds>(
464 std::chrono::steady_clock::now().time_since_epoch()).count();
466 VLOG(11) << "EventBase " << this << " " << __PRETTY_FUNCTION__ <<
467 " (loop) startWork_ " << startWork_;
473 void EventBase::terminateLoopSoon() {
474 VLOG(5) << "EventBase(): Received terminateLoopSoon() command.";
476 // Set stop to true, so the event loop will know to exit.
477 // TODO: We should really use an atomic operation here with a release
481 // Call event_base_loopbreak() so that libevent will exit the next time
483 event_base_loopbreak(evb_);
485 // If terminateLoopSoon() is called from another thread,
486 // the EventBase thread might be stuck waiting for events.
487 // In this case, it won't wake up and notice that stop_ is set until it
488 // receives another event. Send an empty frame to the notification queue
489 // so that the event loop will wake up even if there are no other events.
491 // We don't care about the return value of trySendFrame(). If it fails
492 // this likely means the EventBase already has lots of events waiting
495 queue_->putMessage(std::make_pair(nullptr, nullptr));
497 // We don't care if putMessage() fails. This likely means
498 // the EventBase already has lots of events waiting anyway.
502 void EventBase::runInLoop(LoopCallback* callback, bool thisIteration) {
503 DCHECK(isInEventBaseThread());
504 callback->cancelLoopCallback();
505 callback->context_ = RequestContext::saveContext();
506 if (runOnceCallbacks_ != nullptr && thisIteration) {
507 runOnceCallbacks_->push_back(*callback);
509 loopCallbacks_.push_back(*callback);
513 void EventBase::runInLoop(const Cob& cob, bool thisIteration) {
514 DCHECK(isInEventBaseThread());
515 auto wrapper = new FunctionLoopCallback<Cob>(cob);
516 wrapper->context_ = RequestContext::saveContext();
517 if (runOnceCallbacks_ != nullptr && thisIteration) {
518 runOnceCallbacks_->push_back(*wrapper);
520 loopCallbacks_.push_back(*wrapper);
524 void EventBase::runInLoop(Cob&& cob, bool thisIteration) {
525 DCHECK(isInEventBaseThread());
526 auto wrapper = new FunctionLoopCallback<Cob>(std::move(cob));
527 wrapper->context_ = RequestContext::saveContext();
528 if (runOnceCallbacks_ != nullptr && thisIteration) {
529 runOnceCallbacks_->push_back(*wrapper);
531 loopCallbacks_.push_back(*wrapper);
535 void EventBase::runAfterDrain(Cob&& cob) {
536 auto callback = new FunctionLoopCallback<Cob>(std::move(cob));
537 std::lock_guard<std::mutex> lg(runAfterDrainCallbacksMutex_);
538 callback->cancelLoopCallback();
539 runAfterDrainCallbacks_.push_back(*callback);
542 void EventBase::runOnDestruction(LoopCallback* callback) {
543 std::lock_guard<std::mutex> lg(onDestructionCallbacksMutex_);
544 callback->cancelLoopCallback();
545 onDestructionCallbacks_.push_back(*callback);
548 void EventBase::runBeforeLoop(LoopCallback* callback) {
549 DCHECK(isInEventBaseThread());
550 callback->cancelLoopCallback();
551 runBeforeLoopCallbacks_.push_back(*callback);
554 bool EventBase::runInEventBaseThread(void (*fn)(void*), void* arg) {
556 // It will be received by the FunctionRunner in the EventBase's thread.
558 // We try not to schedule nullptr callbacks
560 LOG(ERROR) << "EventBase " << this
561 << ": Scheduling nullptr callbacks is not allowed";
565 // Short-circuit if we are already in our event base
566 if (inRunningEventBaseThread()) {
567 runInLoop(new RunInLoopCallback(fn, arg));
573 queue_->putMessage(std::make_pair(fn, arg));
574 } catch (const std::exception& ex) {
575 LOG(ERROR) << "EventBase " << this << ": failed to schedule function "
576 << fn << "for EventBase thread: " << ex.what();
583 bool EventBase::runInEventBaseThread(const Cob& fn) {
584 // Short-circuit if we are already in our event base
585 if (inRunningEventBaseThread()) {
591 // Allocate a copy of the function so we can pass it to the other thread
592 // The other thread will delete this copy once the function has been run
594 fnCopy = new Cob(fn);
595 } catch (const std::bad_alloc& ex) {
596 LOG(ERROR) << "failed to allocate tr::function copy "
597 << "for runInEventBaseThread()";
601 if (!runInEventBaseThread(&EventBase::runFunctionPtr, fnCopy)) {
609 bool EventBase::runInEventBaseThreadAndWait(const Cob& fn) {
610 if (inRunningEventBaseThread()) {
611 LOG(ERROR) << "EventBase " << this << ": Waiting in the event loop is not "
618 std::condition_variable cv;
619 runInEventBaseThread([&] {
621 std::unique_lock<std::mutex> l(m);
624 // We cannot release the lock before notify_one, because a spurious
625 // wakeup in the waiting thread may lead to cv and m going out of scope
630 std::unique_lock<std::mutex> l(m);
631 cv.wait(l, [&] { return ready; });
636 bool EventBase::runImmediatelyOrRunInEventBaseThreadAndWait(const Cob& fn) {
637 if (isInEventBaseThread()) {
641 return runInEventBaseThreadAndWait(fn);
645 void EventBase::runAfterDelay(const Cob& cob,
647 TimeoutManager::InternalEnum in) {
648 if (!tryRunAfterDelay(cob, milliseconds, in)) {
649 folly::throwSystemError(
650 "error in EventBase::runAfterDelay(), failed to schedule timeout");
654 bool EventBase::tryRunAfterDelay(const Cob& cob,
656 TimeoutManager::InternalEnum in) {
657 CobTimeout* timeout = new CobTimeout(this, cob, in);
658 if (!timeout->scheduleTimeout(milliseconds)) {
662 pendingCobTimeouts_.push_back(*timeout);
666 bool EventBase::runLoopCallbacks(bool setContext) {
667 if (!loopCallbacks_.empty()) {
669 // Swap the loopCallbacks_ list with a temporary list on our stack.
670 // This way we will only run callbacks scheduled at the time
671 // runLoopCallbacks() was invoked.
673 // If any of these callbacks in turn call runInLoop() to schedule more
674 // callbacks, those new callbacks won't be run until the next iteration
675 // around the event loop. This prevents runInLoop() callbacks from being
676 // able to start file descriptor and timeout based events.
677 LoopCallbackList currentCallbacks;
678 currentCallbacks.swap(loopCallbacks_);
679 runOnceCallbacks_ = ¤tCallbacks;
681 while (!currentCallbacks.empty()) {
682 LoopCallback* callback = ¤tCallbacks.front();
683 currentCallbacks.pop_front();
685 RequestContext::setContext(callback->context_);
687 callback->runLoopCallback();
690 runOnceCallbacks_ = nullptr;
696 void EventBase::initNotificationQueue() {
697 // Infinite size queue
698 queue_.reset(new NotificationQueue<std::pair<void (*)(void*), void*>>());
700 // We allocate fnRunner_ separately, rather than declaring it directly
701 // as a member of EventBase solely so that we don't need to include
702 // NotificationQueue.h from EventBase.h
703 fnRunner_.reset(new FunctionRunner());
705 // Mark this as an internal event, so event_base_loop() will return if
706 // there are no other events besides this one installed.
708 // Most callers don't care about the internal notification queue used by
709 // EventBase. The queue is always installed, so if we did count the queue as
710 // an active event, loop() would never exit with no more events to process.
711 // Users can use loopForever() if they do care about the notification queue.
712 // (This is useful for EventBase threads that do nothing but process
713 // runInEventBaseThread() notifications.)
714 fnRunner_->startConsumingInternal(this, queue_.get());
717 void EventBase::SmoothLoopTime::setTimeInterval(uint64_t timeInterval) {
718 expCoeff_ = -1.0/timeInterval;
719 VLOG(11) << "expCoeff_ " << expCoeff_ << " " << __PRETTY_FUNCTION__;
722 void EventBase::SmoothLoopTime::reset(double value) {
726 void EventBase::SmoothLoopTime::addSample(int64_t idle, int64_t busy) {
728 * Position at which the busy sample is considered to be taken.
729 * (Allows to quickly skew our average without editing much code)
731 enum BusySamplePosition {
732 RIGHT = 0, // busy sample placed at the end of the iteration
733 CENTER = 1, // busy sample placed at the middle point of the iteration
734 LEFT = 2, // busy sample placed at the beginning of the iteration
737 // See http://en.wikipedia.org/wiki/Moving_average#Exponential_moving_average
738 // and D676020 for more info on this calculation.
739 VLOG(11) << "idle " << idle << " oldBusyLeftover_ " << oldBusyLeftover_ <<
740 " idle + oldBusyLeftover_ " << idle + oldBusyLeftover_ <<
741 " busy " << busy << " " << __PRETTY_FUNCTION__;
742 idle += oldBusyLeftover_ + busy;
743 oldBusyLeftover_ = (busy * BusySamplePosition::CENTER) / 2;
744 idle -= oldBusyLeftover_;
746 double coeff = exp(idle * expCoeff_);
748 value_ += (1.0 - coeff) * busy;
751 bool EventBase::nothingHandledYet() {
752 VLOG(11) << "latest " << latestLoopCnt_ << " next " << nextLoopCnt_;
753 return (nextLoopCnt_ != latestLoopCnt_);
757 void EventBase::runFunctionPtr(Cob* fn) {
758 // The function should never throw an exception, because we have no
759 // way of knowing what sort of error handling to perform.
761 // If it does throw, log a message and abort the program.
764 } catch (const std::exception &ex) {
765 LOG(ERROR) << "runInEventBaseThread() std::function threw a "
766 << typeid(ex).name() << " exception: " << ex.what();
769 LOG(ERROR) << "runInEventBaseThread() std::function threw an exception";
773 // The function object was allocated by runInEventBaseThread().
774 // Delete it once it has been run.
778 EventBase::RunInLoopCallback::RunInLoopCallback(void (*fn)(void*), void* arg)
782 void EventBase::RunInLoopCallback::runLoopCallback() noexcept {
787 void EventBase::attachTimeoutManager(AsyncTimeout* obj,
788 InternalEnum internal) {
790 struct event* ev = obj->getEvent();
791 assert(ev->ev_base == nullptr);
793 event_base_set(getLibeventBase(), ev);
794 if (internal == AsyncTimeout::InternalEnum::INTERNAL) {
795 // Set the EVLIST_INTERNAL flag
796 ev->ev_flags |= EVLIST_INTERNAL;
800 void EventBase::detachTimeoutManager(AsyncTimeout* obj) {
802 struct event* ev = obj->getEvent();
803 ev->ev_base = nullptr;
806 bool EventBase::scheduleTimeout(AsyncTimeout* obj,
807 TimeoutManager::timeout_type timeout) {
808 assert(isInEventBaseThread());
809 // Set up the timeval and add the event
811 tv.tv_sec = timeout.count() / 1000LL;
812 tv.tv_usec = (timeout.count() % 1000LL) * 1000LL;
814 struct event* ev = obj->getEvent();
815 if (event_add(ev, &tv) < 0) {
816 LOG(ERROR) << "EventBase: failed to schedule timeout: " << strerror(errno);
823 void EventBase::cancelTimeout(AsyncTimeout* obj) {
824 assert(isInEventBaseThread());
825 struct event* ev = obj->getEvent();
826 if (EventUtil::isEventRegistered(ev)) {
831 void EventBase::setName(const std::string& name) {
832 assert(isInEventBaseThread());
836 setThreadName(loopThread_.load(std::memory_order_relaxed),
841 const std::string& EventBase::getName() {
842 assert(isInEventBaseThread());
846 const char* EventBase::getLibeventVersion() { return event_get_version(); }
847 const char* EventBase::getLibeventMethod() { return event_get_method(); }