folly/folly/io/async/EventBase.cpp

/*
 * Copyright (c) Meta Platforms, Inc. and affiliates.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef __STDC_FORMAT_MACROS
#define __STDC_FORMAT_MACROS
#endif

#include <folly/io/async/EventBase.h>

#include <fcntl.h>

#include <memory>
#include <mutex>
#include <thread>

#include <folly/Chrono.h>
#include <folly/ExceptionString.h>
#include <folly/Memory.h>
#include <folly/String.h>
#include <folly/io/async/EventBaseAtomicNotificationQueue.h>
#include <folly/io/async/EventBaseBackendBase.h>
#include <folly/io/async/EventBaseLocal.h>
#include <folly/io/async/VirtualEventBase.h>
#include <folly/lang/Assume.h>
#include <folly/portability/Unistd.h>
#include <folly/synchronization/Baton.h>
#include <folly/synchronization/EventCount.h>
#include <folly/system/ThreadId.h>
#include <folly/system/ThreadName.h>

#if defined(__linux__) && !FOLLY_MOBILE
#define FOLLY_USE_EPOLLET

#include <sys/epoll.h>

struct event_base {
  void* evsel;
  void* evbase;
};

struct epollop {
  void* fds;
  int nfds;
  void* events;
  int nevents;
  int epfd;
};
#endif

namespace {

class EventBaseBackend : public folly::EventBaseBackendBase {};

EventBaseBackend::EventBaseBackend() {}

EventBaseBackend::EventBaseBackend(event_base* evb) :{}

int EventBaseBackend::eb_event_base_loop(int flags) {}

int EventBaseBackend::eb_event_base_loopbreak() {}

int EventBaseBackend::eb_event_add(
    Event& event, const struct timeval* timeout) {}

int EventBaseBackend::eb_event_del(EventBaseBackendBase::Event& event) {}

bool EventBaseBackend::eb_event_active(Event& event, int res) {}

bool EventBaseBackend::setEdgeTriggered(Event& event) {}

EventBaseBackend::~EventBaseBackend() {}

} // namespace

namespace folly {

class EventBase::LoopCallbacksDeadline {};

class EventBase::FuncRunner {};

class EventBase::ThreadIdCollector : public WorkerProvider {};

/*
 * EventBase methods
 */

EventBase::EventBase(std::chrono::milliseconds tickInterval)
    :{}

EventBase::EventBase(bool enableTimeMeasurement)
    :{}

// takes ownership of the event_base
EventBase::EventBase(event_base* evb, bool enableTimeMeasurement)
    :{}

EventBase::EventBase(Options options)
    :{}

EventBase::~EventBase() {}

void EventBase::setStrictLoopThread() {}

bool EventBase::tryDeregister(detail::EventBaseLocalBase& evbl) {}

std::unique_ptr<EventBaseBackendBase> EventBase::getDefaultBackend() {}

size_t EventBase::getNotificationQueueSize() const {}

size_t EventBase::getNumLoopCallbacks() const {}

void EventBase::setMaxReadAtOnce(uint32_t maxAtOnce) {}

bool EventBase::isInEventBaseThread() const {}

bool EventBase::inRunningEventBaseThread() const {}

void EventBase::checkIsInEventBaseThread() const {}

// Set smoothing coefficient for loop load average; input is # of milliseconds
// for exp(-1) decay.
void EventBase::setLoadAvgMsec(std::chrono::milliseconds ms) {}

void EventBase::resetLoadAvg(double value) {}

static std::chrono::milliseconds getTimeDelta(
    std::chrono::steady_clock::time_point* prev) {}

void EventBase::waitUntilRunning() {}

// enters the event_base loop -- will only exit when forced to
bool EventBase::loop() {}

bool EventBase::loopIgnoreKeepAlive() {}

bool EventBase::loopOnce(int flags) {}

bool EventBase::isSuccess(LoopStatus status) {}

bool EventBase::loopBody(int flags, LoopOptions options) {}

void EventBase::loopPollSetup() {}

bool EventBase::loopPoll() {}

void EventBase::loopPollCleanup() {}

EventBase::LoopStatus EventBase::loopWithSuspension() {}

void EventBase::loopMainSetup() {}

EventBase::LoopStatus EventBase::loopMain(int flags, LoopOptions options) {}

void EventBase::loopMainCleanup() {}

bool EventBase::keepAliveAcquire() noexcept {}

void EventBase::keepAliveRelease() noexcept {}

size_t EventBase::loopKeepAliveCount() {}

void EventBase::applyLoopKeepAlive() {}

void EventBase::loopForever() {}

void EventBase::bumpHandlingTime() {}

void EventBase::terminateLoopSoon() {}

void EventBase::runInLoop(
    LoopCallback* callback,
    bool thisIteration,
    std::shared_ptr<RequestContext> rctx) {}

void EventBase::runInLoop(Func cob, bool thisIteration) {}

void EventBase::runOnDestruction(OnDestructionCallback& callback) {}

void EventBase::runOnDestruction(Func f) {}

void EventBase::runOnDestructionStart(OnDestructionCallback& callback) {}

void EventBase::runOnDestructionStart(Func f) {}

void EventBase::runBeforeLoop(LoopCallback* callback) {}

void EventBase::runAfterLoop(LoopCallback* callback) {}

void EventBase::runInEventBaseThread(Func fn) noexcept {}

void EventBase::runInEventBaseThreadAlwaysEnqueue(Func fn) noexcept {}

void EventBase::runInEventBaseThreadAndWait(Func fn) noexcept {}

void EventBase::runImmediatelyOrRunInEventBaseThreadAndWait(Func fn) noexcept {}

void EventBase::runImmediatelyOrRunInEventBaseThread(Func fn) noexcept {}

void EventBase::runLoopCallbackList(
    LoopCallbackList& currentCallbacks, const LoopCallbacksDeadline& deadline) {}

bool EventBase::runLoopCallbacks() {}

void EventBase::initNotificationQueue() {}

void EventBase::SmoothLoopTime::setTimeInterval(
    std::chrono::microseconds timeInterval) {}

void EventBase::SmoothLoopTime::reset(double value) {}

void EventBase::SmoothLoopTime::addSample(
    std::chrono::microseconds total, std::chrono::microseconds busy) {}

bool EventBase::nothingHandledYet() const noexcept {}

void EventBase::attachTimeoutManager(AsyncTimeout* obj, InternalEnum internal) {}

void EventBase::detachTimeoutManager(AsyncTimeout* obj) {}

bool EventBase::scheduleTimeout(
    AsyncTimeout* obj, TimeoutManager::timeout_type timeout) {}

void EventBase::cancelTimeout(AsyncTimeout* obj) {}

void EventBase::setName(const std::string& name) {}

const std::string& EventBase::getName() {}

std::thread::id EventBase::getLoopThreadId() {}

void EventBase::scheduleAt(Func&& fn, TimePoint const& timeout) {}

event_base* EventBase::getLibeventBase() const {}

const char* EventBase::getLibeventVersion() {}
const char* EventBase::getLibeventMethod() {}

VirtualEventBase& EventBase::getVirtualEventBase() {}

VirtualEventBase* EventBase::tryGetVirtualEventBase() {}

EventBase* EventBase::getEventBase() {}

WorkerProvider* EventBase::getThreadIdCollector() {}

EventBase::OnDestructionCallback::~OnDestructionCallback() {}

void EventBase::OnDestructionCallback::runCallback() noexcept {}

void EventBase::OnDestructionCallback::schedule(
    Function<void(OnDestructionCallback&)> linker,
    Function<void(OnDestructionCallback&)> eraser) {}

bool EventBase::OnDestructionCallback::cancel() {}

} // namespace folly