From 624b203cbcea647a6c984502d5db81c816332f4d Mon Sep 17 00:00:00 2001 From: Antonio Vicente Date: Wed, 16 Dec 2020 13:09:43 -0500 Subject: [PATCH 1/3] event: Extract DispatcherBase interface Signed-off-by: Antonio Vicente --- include/envoy/event/dispatcher.h | 109 ++++++++++++++++--------------- 1 file changed, 58 insertions(+), 51 deletions(-) diff --git a/include/envoy/event/dispatcher.h b/include/envoy/event/dispatcher.h index 42048d138f68..413cfa0419ee 100644 --- a/include/envoy/event/dispatcher.h +++ b/include/envoy/event/dispatcher.h @@ -51,13 +51,68 @@ using PostCb = std::function; using PostCbSharedPtr = std::shared_ptr; +/** + * Minimal interface to the disptching loop used to create low-level primitives. See Dispatcher below for the + * full interface. + */ +class DispatcherBase { + public: + virtual ~DispatcherBase() = default; + + /** + * Creates a file event that will signal when a file is readable or writable. On UNIX systems this + * can be used for any file like interface (files, sockets, etc.). + * @param fd supplies the fd to watch. + * @param cb supplies the callback to fire when the file is ready. + * @param trigger specifies whether to edge or level trigger. + * @param events supplies a logical OR of FileReadyType events that the file event should + * initially listen on. + */ + virtual FileEventPtr createFileEvent(os_fd_t fd, FileReadyCb cb, FileTriggerType trigger, + uint32_t events) PURE; + + /** + * Allocates a timer. @see Timer for docs on how to use the timer. + * @param cb supplies the callback to invoke when the timer fires. + */ + virtual Event::TimerPtr createTimer(TimerCb cb) PURE; + + /** + * Allocates a schedulable callback. @see SchedulableCallback for docs on how to use the wrapped + * callback. + * @param cb supplies the callback to invoke when the SchedulableCallback is triggered on the + * event loop. + */ + virtual Event::SchedulableCallbackPtr createSchedulableCallback(std::function cb) PURE; + + /** + * Sets a tracked object, which is currently operating in this Dispatcher. + * This should be cleared with another call to setTrackedObject() when the object is done doing + * work. Calling setTrackedObject(nullptr) results in no object being tracked. + * + * This is optimized for performance, to avoid allocation where we do scoped object tracking. + * + * @return The previously tracked object or nullptr if there was none. + */ + virtual const ScopeTrackedObject* setTrackedObject(const ScopeTrackedObject* object) PURE; + + /** + * Validates that an operation is thread-safe with respect to this dispatcher; i.e. that the + * current thread of execution is on the same thread upon which the dispatcher loop is running. + */ + virtual bool isThreadSafe() const PURE; + + /** + * Returns a recently cached MonotonicTime value. + */ + virtual MonotonicTime approximateMonotonicTime() const PURE; +}; + /** * Abstract event dispatching loop. */ -class Dispatcher { +class Dispatcher : public DispatcherBase { public: - virtual ~Dispatcher() = default; - /** * Returns the name that identifies this dispatcher, such as "worker_2" or "main_thread". * @return const std::string& the name that identifies this dispatcher. @@ -136,18 +191,6 @@ class Dispatcher { createDnsResolver(const std::vector& resolvers, bool use_tcp_for_dns_lookups) PURE; - /** - * Creates a file event that will signal when a file is readable or writable. On UNIX systems this - * can be used for any file like interface (files, sockets, etc.). - * @param fd supplies the fd to watch. - * @param cb supplies the callback to fire when the file is ready. - * @param trigger specifies whether to edge or level trigger. - * @param events supplies a logical OR of FileReadyType events that the file event should - * initially listen on. - */ - virtual FileEventPtr createFileEvent(os_fd_t fd, FileReadyCb cb, FileTriggerType trigger, - uint32_t events) PURE; - /** * @return Filesystem::WatcherPtr a filesystem watcher owned by the caller. */ @@ -173,20 +216,6 @@ class Dispatcher { */ virtual Network::UdpListenerPtr createUdpListener(Network::SocketSharedPtr socket, Network::UdpListenerCallbacks& cb) PURE; - /** - * Allocates a timer. @see Timer for docs on how to use the timer. - * @param cb supplies the callback to invoke when the timer fires. - */ - virtual Event::TimerPtr createTimer(TimerCb cb) PURE; - - /** - * Allocates a schedulable callback. @see SchedulableCallback for docs on how to use the wrapped - * callback. - * @param cb supplies the callback to invoke when the SchedulableCallback is triggered on the - * event loop. - */ - virtual Event::SchedulableCallbackPtr createSchedulableCallback(std::function cb) PURE; - /** * Submits an item for deferred delete. @see DeferredDeletable. */ @@ -236,28 +265,6 @@ class Dispatcher { */ virtual Buffer::WatermarkFactory& getWatermarkFactory() PURE; - /** - * Sets a tracked object, which is currently operating in this Dispatcher. - * This should be cleared with another call to setTrackedObject() when the object is done doing - * work. Calling setTrackedObject(nullptr) results in no object being tracked. - * - * This is optimized for performance, to avoid allocation where we do scoped object tracking. - * - * @return The previously tracked object or nullptr if there was none. - */ - virtual const ScopeTrackedObject* setTrackedObject(const ScopeTrackedObject* object) PURE; - - /** - * Validates that an operation is thread-safe with respect to this dispatcher; i.e. that the - * current thread of execution is on the same thread upon which the dispatcher loop is running. - */ - virtual bool isThreadSafe() const PURE; - - /** - * Returns a recently cached MonotonicTime value. - */ - virtual MonotonicTime approximateMonotonicTime() const PURE; - /** * Updates approximate monotonic time to current value. */ From faee824727b6b4240d29bb4336a7c4690c3e47bb Mon Sep 17 00:00:00 2001 From: Antonio Vicente Date: Wed, 16 Dec 2020 15:06:13 -0500 Subject: [PATCH 2/3] fix format Signed-off-by: Antonio Vicente --- include/envoy/event/dispatcher.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/envoy/event/dispatcher.h b/include/envoy/event/dispatcher.h index 413cfa0419ee..4a8e6be7976e 100644 --- a/include/envoy/event/dispatcher.h +++ b/include/envoy/event/dispatcher.h @@ -52,11 +52,11 @@ using PostCb = std::function; using PostCbSharedPtr = std::shared_ptr; /** - * Minimal interface to the disptching loop used to create low-level primitives. See Dispatcher below for the - * full interface. + * Minimal interface to the disptching loop used to create low-level primitives. See Dispatcher + * below for the full interface. */ class DispatcherBase { - public: +public: virtual ~DispatcherBase() = default; /** From d03d0bf9bf81d883b650fceb1cf49a8ad0781381 Mon Sep 17 00:00:00 2001 From: Antonio Vicente Date: Wed, 16 Dec 2020 18:34:39 -0500 Subject: [PATCH 3/3] fix spelling Signed-off-by: Antonio Vicente --- include/envoy/event/dispatcher.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/envoy/event/dispatcher.h b/include/envoy/event/dispatcher.h index 4a8e6be7976e..599617e87d28 100644 --- a/include/envoy/event/dispatcher.h +++ b/include/envoy/event/dispatcher.h @@ -52,7 +52,7 @@ using PostCb = std::function; using PostCbSharedPtr = std::shared_ptr; /** - * Minimal interface to the disptching loop used to create low-level primitives. See Dispatcher + * Minimal interface to the dispatching loop used to create low-level primitives. See Dispatcher * below for the full interface. */ class DispatcherBase {