From 0f72a2e0eaa0d1f2f5feb717bdcd7351b47a892a Mon Sep 17 00:00:00 2001
From: patrick96
Date: Tue, 21 Sep 2021 20:53:01 +0200
Subject: [PATCH] Remove unused throttle_util
---
include/utils/throttle.hpp | 92 --------------------------------------
src/CMakeLists.txt | 1 -
src/utils/throttle.cpp | 36 ---------------
3 files changed, 129 deletions(-)
delete mode 100644 include/utils/throttle.hpp
delete mode 100644 src/utils/throttle.cpp
diff --git a/include/utils/throttle.hpp b/include/utils/throttle.hpp
deleted file mode 100644
index be207088..00000000
--- a/include/utils/throttle.hpp
+++ /dev/null
@@ -1,92 +0,0 @@
-#pragma once
-
-#include
-#include
-
-#include "common.hpp"
-#include "components/logger.hpp"
-#include "utils/factory.hpp"
-
-POLYBAR_NS
-
-namespace chrono = std::chrono;
-
-namespace throttle_util {
- using timewindow = chrono::duration;
- using timepoint_clock = chrono::high_resolution_clock;
- using timepoint = timepoint_clock::time_point;
- using queue = std::deque;
- using limit = size_t;
-
- namespace strategy {
- struct try_once_or_leave_yolo {
- bool operator()(queue& q, limit l, timewindow);
- };
- struct wait_patiently_by_the_door {
- bool operator()(queue& q, limit l, timewindow);
- };
- }
-
- /**
- * Throttle events within a set window of time
- *
- * Example usage:
- * \code cpp
- * auto t = throttle_util::make_throttler(2, 1s);
- * if (t->passthrough())
- * ...
- * \endcode
- */
- class event_throttler {
- public:
- /**
- * Construct throttler
- */
- explicit event_throttler(int limit, timewindow timewindow) : m_limit(limit), m_timewindow(timewindow) {}
-
- /**
- * Check if event is allowed to pass
- * using specified strategy
- */
- template
- bool passthrough(Strategy wait_strategy) {
- expire_timestamps();
- return wait_strategy(m_queue, m_limit, m_timewindow);
- }
-
- /**
- * Check if event is allowed to pass
- * using default strategy
- */
- bool passthrough() {
- return passthrough(strategy::try_once_or_leave_yolo{});
- }
-
- protected:
- /**
- * Expire old timestamps
- */
- void expire_timestamps() {
- auto now = timepoint_clock::now();
- while (m_queue.size() > 0) {
- if ((now - m_queue.front()) < m_timewindow)
- break;
- m_queue.pop_front();
- }
- }
-
- private:
- queue m_queue{};
- limit m_limit{};
- timewindow m_timewindow{};
- };
-
- using throttle_t = unique_ptr;
-
- template
- throttle_t make_throttler(Args&&... args) {
- return factory_util::unique(forward(args)...);
- }
-}
-
-POLYBAR_NS_END
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 77d30408..7fb03e48 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -115,7 +115,6 @@ if(BUILD_LIBPOLY)
${src_dir}/utils/process.cpp
${src_dir}/utils/socket.cpp
${src_dir}/utils/string.cpp
- ${src_dir}/utils/throttle.cpp
${src_dir}/x11/atoms.cpp
${src_dir}/x11/background_manager.cpp
diff --git a/src/utils/throttle.cpp b/src/utils/throttle.cpp
deleted file mode 100644
index d1eaf508..00000000
--- a/src/utils/throttle.cpp
+++ /dev/null
@@ -1,36 +0,0 @@
-#include
-
-#include "utils/throttle.hpp"
-
-POLYBAR_NS
-
-namespace throttle_util {
- namespace strategy {
- /**
- * Only pass events when there are slots available
- */
- bool try_once_or_leave_yolo::operator()(queue& q, limit l, timewindow /*unused*/) {
- if (q.size() >= l) {
- return false;
- }
- q.emplace_back(timepoint_clock::now());
- return true;
- }
-
- /**
- * If no slots are available, wait the required
- * amount of time for a slot to become available
- * then let the event pass
- */
- bool wait_patiently_by_the_door::operator()(queue& q, limit l, timewindow /*unused*/) {
- auto now = timepoint_clock::now();
- q.emplace_back(now);
- if (q.size() >= l) {
- std::this_thread::sleep_for(now - q.front());
- }
- return true;
- }
- }
-}
-
-POLYBAR_NS_END