An event loop that drives asynchronous I/O and timers.
Synopsis
Declared in <folly/io/async/EventBase.h>
class EventBase
: public TimeoutManager
, public DrivableExecutor
, public IOExecutor
, public SequencedExecutor
, public ScheduledExecutor
, public GetThreadIdCollector
Base Classes
Name |
Description |
Base interface to be implemented by all classes expecting to manage timeouts. AsyncTimeout will use implementations of this interface to schedule/cancel timeouts. |
|
An executor that can be driven forward via its |
|
An executor backed by an I/O event loop. |
|
An executor that sequences tasks whose submissions were sequenced. |
|
An executor that supports timed scheduling. Like RxScheduler. |
|
Interface for executors that provide a WorkerProvider to collect thread ids. |
Types
Name |
Description |
Loop callback that wraps and owns a folly::Function. |
|
On‐destruction callback that wraps and owns a folly::Function. |
|
A callback interface to use with runInLoop() |
|
Options controlling a single loopPoll() call. |
|
Base class for user callbacks run during EventBase destruction. |
|
Configuration options for constructing an EventBase. |
|
Exponentially‐smoothed moving average of loop times. |
|
Loop callback that wraps a function without allocating. |
Type Aliases
Name |
Description |
The duration type used for scheduling. |
|
Callable type used for functions scheduled on the EventBase. |
|
Alias for ExecutorKeepAlive, a safe pointer to an Executor. |
|
Trace callback invoked from keepAliveAcquire()/keepAliveRelease(). |
|
The time point type used for scheduling. |
|
Millisecond‐resolution timeout duration. |
|
Microsecond‐resolution timeout duration. |
Enums
Name |
Description |
Distinguishes internal timeouts from normal ones. |
|
Same semantics as loop(), but, instead of blocking, it returns in a "suspended" state. The caller must continue calling loopWithSuspension() until a non‐suspended state is reached. |
Member Functions
Name |
Description |
|
Constructors |
|
Destroys the EventBase and runs any on‐destruction callbacks. |
|
Deleted copy assignment. |
|
|
Setup execution observation/instrumentation for every EventHandler executed in this EventBase. |
|
|
Enqueue a function with a given priority, where 0 is the medium priority This is up to the implementation to enforce |
|
|
|
only EventHandler/AsyncTimeout subclasses and ourselves should ever call this. |
|
Cancels a scheduled timeout on this EventBase. |
Equivalent to CHECK(isInEventBaseThread()) (and assert/DCHECK for dcheckIsInEventBaseThread), but it prints more information on failure. |
|
Checks in debug builds that the caller is in the EventBase thread. |
|
|
Detaches a timeout from this EventBase's timeout manager. |
|
Implements the DrivableExecutor interface |
Get the average loop time in microseconds (an exponentially‐smoothed ave) |
|
Returns the backend driving the event loop. |
|
|
Implements the IOExecutor interface |
Gets the execution observer list associated with this EventBase. |
|
Returns the underlying libevent event_base. |
|
Returns the libevent method in use by this EventBase. |
|
Returns the timepoint at the start of the loop callbacks. |
|
Returns the ID of the thread that this event base is running in |
|
Returns the maximum number of reads performed per event. |
|
Returns the name of the thread that runs this event base. |
|
Returns the number of pending items in the notification queue. |
|
Returns the number of loop callbacks pending execution. If this is non‐zero, loopOnce() is guaranteed to run the callbacks without blocking. |
|
|
Returns the number of priority levels this executor supports. |
Returns the observer attached to this EventBase. |
|
|
Implements the GetThreadIdCollector interface |
Returns a VirtualEventBase attached to this EventBase. |
|
Returns true if and only if the loop is running in the current thread. |
|
Verify that current thread is the EventBase thread. |
|
|
Returns whether the caller runs in the timeout manager thread. |
Check if the event base loop is running. |
|
Runs the event loop. |
|
Runs the event loop. |
|
|
Same as loop(), but doesn't wait for all keep‐alive tokens to be released. |
Returns the number of outstanding loop keepalives. |
|
Wait for some events to become active, run them, then return. |
|
Poll the EventBase for active events, run them, then return. Unlike loopOnce, the expectation is that loopPoll will be called multiple times State is therefore persisted across calls to reflect that there is ongoing polling. Control will be returned to the calling thread between iterations. loopPollSetup and loopPollCleanup manage the maintained state across loopPoll calls. |
|
Clears state that was setup for active polling against the EventBase. Call after polling via loopPoolSetup and the subsequent loopPoll calls. |
|
Sets up state for active polling to be done against the EventBase. Call before polling via subsequent loopPoll calls. |
|
Runs the loop, returning in a suspended state instead of blocking. |
|
|
Get this executor's notion of time. Must be threadsafe. |
Removes an execution observer from this EventBase. |
|
reset the load average to a desired value |
|
Runs the given Cob at some time after the specified number of milliseconds. (No guarantees exactly when.) |
|
Adds a callback that will run immediately after the event loop. This can be used to delay some processing until after all the normal loop callback have been processed for this iteration. |
|
Adds a callback that will run immediately before the event loop. This is very similar to runInLoop(), but will not cause the loop to break: For example, this callback could be used to get loop times. |
|
Like runInEventBaseThread, but runs function immediately instead of at the end of the loop when called from the eventbase thread. |
|
Like runInEventBaseThreadAndWait, except if the caller is already in the event base thread, the functor is simply run inline. |
|
Run the specified function in the EventBase's thread. |
|
|
|
Like runInEventBaseThread, but the caller waits for the callback to be executed. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Schedules AsyncTimeout to fire after |
Set smoothing coefficient for loop load average; # of milliseconds for exp(‐1) (1/2.71828...) decay. |
|
Set the maximum desired latency in us and provide a callback which will be called when that latency is exceeded. OBS: This functionality depends on time‐measurement. |
|
Sets the maximum number of reads performed per event. |
|
Set the name of the thread that runs this event base. |
|
Sets the observer that samples loop activity. |
|
Enable strict loop thread mode. This is intended for executors that take ownership of the EventBase and run it continuously until joined. Once set, it is not possible to unset it. |
|
Causes the event loop to exit soon. |
|
Returns the wheel timer, creating it on first use. |
|
Attempts to run the given Cob after the specified delay. |
|
Wait until the event loop starts (after starting the event loop thread). |
Static Member Functions
Name |
Description |
Creates the default backend for an EventBase. |
|
|
|
Returns the libevent library version string. |
|
Creates a backend suitable for tests. |
|
Invokes |
|
Installs the process‐global keep‐alive acquire trace callback. |
|
Installs the process‐global keep‐alive release trace callback. |
Static Data Members
Name |
Description |
Highest schedulable priority. |
|
Lowest schedulable priority. |
|
Medium (default) schedulable priority. |
Protected Member Functions
Name |
Description |
Cancels and clears all callback timeouts registered via runAfterDelay. |
|
|
Acquires a keep‐alive token on this EventBase. |
|
Releases a keep‐alive token on this EventBase. |
Protected Static Member Functions
Name |
Description |
Returns true if the KeepAlive is constructed from an executor that does not support the keep alive ref‐counting functionality |
|
Acquires a keep‐alive reference on |
|
Releases a keep‐alive reference on |
|
Makes a counted (non‐dummy, non‐alias) keep‐alive referring to |
Friends
Name |
Description |
Storage for data tied to the lifetime of an EventBase. |
|
Helper that runs an EventBase loop on a dedicated std::thread. |
Non-Member Functions
Name |
Description |
methodset Deprecated |
|
methodset Executors |
|
Trace hook invoked when a Future is rescheduled onto an executor. |
|
Trace hook invoked when the global CPU executor is retrieved. |
|
Trace hook invoked when the global IO executor is retrieved. |
|
|
Trace hook invoked when the immutable CPU executor is retrieved. |
Trace hook invoked when the immutable IO executor is retrieved. |
|
Trace hook invoked when a SemiFuture is rescheduled onto an executor. |
|
Trace hook invoked when the global CPU executor is set. |
|
Trace hook invoked when the global IO executor is set. |
|
Returns the fiber manager keyed by the local type |
Created with MrDocs