From 2241aff419d1ccacc5c4807caf342dc1c86ceae4 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Fri, 11 Apr 2014 14:41:18 -0500 Subject: if we have a flood of EDS events coming in, wait a longer interval before requerying the EDS engine --- src/engine-eds.cpp | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/engine-eds.cpp b/src/engine-eds.cpp index c557857..c20731d 100644 --- a/src/engine-eds.cpp +++ b/src/engine-eds.cpp @@ -25,6 +25,7 @@ #include #include // std::sort() +#include // time() #include #include @@ -144,16 +145,29 @@ private: { auto self = static_cast(gself); self->m_rebuild_tag = 0; + self->m_rebuild_deadline = 0; self->set_dirty_now(); return G_SOURCE_REMOVE; } void set_dirty_soon() { - static const int ARBITRARY_BATCH_MSEC = 200; + static constexpr int MIN_BATCH_SEC = 1; + static constexpr int MAX_BATCH_SEC = 60; + static_assert(MIN_BATCH_SEC <= MAX_BATCH_SEC, "bad boundaries"); - if (m_rebuild_tag == 0) - m_rebuild_tag = g_timeout_add(ARBITRARY_BATCH_MSEC, set_dirty_now_static, this); + const auto now = time(nullptr); + + if (m_rebuild_deadline == 0) // first pass + { + m_rebuild_deadline = now + MAX_BATCH_SEC; + m_rebuild_tag = g_timeout_add_seconds(MIN_BATCH_SEC, set_dirty_now_static, this); + } + else if (now < m_rebuild_deadline) + { + g_source_remove (m_rebuild_tag); + m_rebuild_tag = g_timeout_add_seconds(MIN_BATCH_SEC, set_dirty_now_static, this); + } } static void on_source_registry_ready(GObject* /*source*/, GAsyncResult* res, gpointer gself) @@ -496,6 +510,7 @@ private: GCancellable* m_cancellable = nullptr; ESourceRegistry* m_source_registry = nullptr; guint m_rebuild_tag = 0; + time_t m_rebuild_deadline = 0; }; /*** -- cgit v1.2.3