explicit FunctionLoopCallback(const Cob& function)
: function_(function) {}
- virtual void runLoopCallback() noexcept {
+ void runLoopCallback() noexcept override {
function_();
delete this;
}
class EventBase::FunctionRunner
: public NotificationQueue<std::pair<void (*)(void*), void*>>::Consumer {
public:
- void messageAvailable(std::pair<void (*)(void*), void*>&& msg) {
+ void messageAvailable(std::pair<void (*)(void*), void*>&& msg) override {
// In libevent2, internal events do not break the loop.
// Most users would expect loop(), followed by runInEventBaseThread(),
, latestLoopCnt_(nextLoopCnt_)
, startWork_(0)
, observer_(nullptr)
- , observerSampleCount_(0) {
+ , observerSampleCount_(0)
+ , executionObserver_(nullptr) {
{
std::lock_guard<std::mutex> lock(libevent_mutex_);
}
VLOG(5) << "EventBase(): Created.";
initNotificationQueue();
- RequestContext::getStaticContext();
+ RequestContext::saveContext();
}
// takes ownership of the event_base
, latestLoopCnt_(nextLoopCnt_)
, startWork_(0)
, observer_(nullptr)
- , observerSampleCount_(0) {
+ , observerSampleCount_(0)
+ , executionObserver_(nullptr) {
if (UNLIKELY(evb_ == nullptr)) {
LOG(ERROR) << "EventBase(): Pass nullptr as event base.";
throw std::invalid_argument("EventBase(): event base cannot be nullptr");
}
initNotificationQueue();
- RequestContext::getStaticContext();
+ RequestContext::saveContext();
}
EventBase::~EventBase() {
std::chrono::steady_clock::now().time_since_epoch()).count();
}
- // TODO: Read stop_ atomically with an acquire barrier.
- while (!stop_) {
+ while (!stop_.load(std::memory_order_acquire)) {
++nextLoopCnt_;
// Run the before loop callbacks
}
void EventBase::runOnDestruction(LoopCallback* callback) {
- DCHECK(isInEventBaseThread());
+ std::lock_guard<std::mutex> lg(onDestructionCallbacksMutex_);
callback->cancelLoopCallback();
onDestructionCallbacks_.push_back(*callback);
}