From 090d79e13bb7fad8a7463577bb8b0b3f5d7919d7 Mon Sep 17 00:00:00 2001 From: Zygo Blaxell Date: Mon, 15 Jan 2018 23:07:12 -0500 Subject: [PATCH] crucible: remove unused TimeQueue and WorkQueue classes WorkQueue is superceded by Task. TimeQueue will be replaced by something based on Tasks. Signed-off-by: Zygo Blaxell --- include/crucible/timequeue.h | 188 ---------------------------------- include/crucible/workqueue.h | 192 ----------------------------------- src/bees.h | 2 - 3 files changed, 382 deletions(-) delete mode 100644 include/crucible/timequeue.h delete mode 100644 include/crucible/workqueue.h diff --git a/include/crucible/timequeue.h b/include/crucible/timequeue.h deleted file mode 100644 index 098ec54..0000000 --- a/include/crucible/timequeue.h +++ /dev/null @@ -1,188 +0,0 @@ -#ifndef CRUCIBLE_TIMEQUEUE_H -#define CRUCIBLE_TIMEQUEUE_H - -#include -#include - -#include -#include -#include -#include -#include -#include - -namespace crucible { - using namespace std; - - template - class TimeQueue { - - public: - using Timestamp = chrono::high_resolution_clock::time_point; - - private: - struct Item { - Timestamp m_time; - unsigned long m_id; - Task m_task; - - bool operator<(const Item &that) const { - if (m_time < that.m_time) return true; - if (that.m_time < m_time) return false; - return m_id < that.m_id; - } - static unsigned s_id; - - Item(const Timestamp &time, const Task& task) : - m_time(time), - m_id(++s_id), - m_task(task) - { - } - - }; - - set m_set; - mutable mutex m_mutex; - condition_variable m_cond_full, m_cond_empty; - size_t m_max_queue_depth; - - public: - ~TimeQueue(); - TimeQueue(size_t max_queue_depth = numeric_limits::max()); - - void push(const Task &task, double delay = 0); - void push_nowait(const Task &task, double delay = 0); - Task pop(); - bool pop_nowait(Task &t); - double when() const; - - size_t size() const; - bool empty() const; - - list peek(size_t count) const; - }; - - template unsigned TimeQueue::Item::s_id = 0; - - template - TimeQueue::~TimeQueue() - { - if (!m_set.empty()) { - cerr << "ERROR: " << m_set.size() << " locked items still in TimeQueue at destruction" << endl; - } - } - - template - void - TimeQueue::push(const Task &task, double delay) - { - Timestamp time = chrono::high_resolution_clock::now() + - chrono::duration_cast(chrono::duration(delay)); - unique_lock lock(m_mutex); - while (m_set.size() > m_max_queue_depth) { - m_cond_full.wait(lock); - } - m_set.insert(Item(time, task)); - m_cond_empty.notify_all(); - } - - template - void - TimeQueue::push_nowait(const Task &task, double delay) - { - Timestamp time = chrono::high_resolution_clock::now() + - chrono::duration_cast(chrono::duration(delay)); - unique_lock lock(m_mutex); - m_set.insert(Item(time, task)); - m_cond_empty.notify_all(); - } - - template - Task - TimeQueue::pop() - { - unique_lock lock(m_mutex); - while (1) { - while (m_set.empty()) { - m_cond_empty.wait(lock); - } - Timestamp now = chrono::high_resolution_clock::now(); - if (now > m_set.begin()->m_time) { - Task rv = m_set.begin()->m_task; - m_set.erase(m_set.begin()); - m_cond_full.notify_all(); - return rv; - } - m_cond_empty.wait_until(lock, m_set.begin()->m_time); - } - } - - template - bool - TimeQueue::pop_nowait(Task &t) - { - unique_lock lock(m_mutex); - if (m_set.empty()) { - return false; - } - Timestamp now = chrono::high_resolution_clock::now(); - if (now <= m_set.begin()->m_time) { - return false; - } - t = m_set.begin()->m_task; - m_set.erase(m_set.begin()); - m_cond_full.notify_all(); - return true; - } - - template - double - TimeQueue::when() const - { - unique_lock lock(m_mutex); - if (m_set.empty()) { - return numeric_limits::infinity(); - } - return chrono::duration(m_set.begin()->m_time - chrono::high_resolution_clock::now()).count(); - } - - template - size_t - TimeQueue::size() const - { - unique_lock lock(m_mutex); - return m_set.size(); - } - - template - bool - TimeQueue::empty() const - { - unique_lock lock(m_mutex); - return m_set.empty(); - } - - template - list - TimeQueue::peek(size_t count) const - { - unique_lock lock(m_mutex); - list rv; - auto it = m_set.begin(); - while (count-- && it != m_set.end()) { - rv.push_back(it->m_task); - ++it; - } - return rv; - } - - template - TimeQueue::TimeQueue(size_t max_depth) : - m_max_queue_depth(max_depth) - { - } - -} - -#endif // CRUCIBLE_TIMEQUEUE_H diff --git a/include/crucible/workqueue.h b/include/crucible/workqueue.h deleted file mode 100644 index bf3732f..0000000 --- a/include/crucible/workqueue.h +++ /dev/null @@ -1,192 +0,0 @@ -#ifndef CRUCIBLE_WORKQUEUE_H -#define CRUCIBLE_WORKQUEUE_H - -#include - -#include -#include -#include -#include -#include -#include - -namespace crucible { - using namespace std; - - template - class WorkQueue { - - public: - using set_type = set; - using key_type = Task; - - private: - - set_type m_set; - mutable mutex m_mutex; - condition_variable m_cond_full, m_cond_empty; - size_t m_max_queue_depth; - - public: - ~WorkQueue(); - template WorkQueue(size_t max_queue_depth, Args... args); - template WorkQueue(Args... args); - - void push(const key_type &name); - void push_wait(const key_type &name, size_t limit); - void push_nowait(const key_type &name); - - key_type pop(); - bool pop_nowait(key_type &rv); - key_type peek(); - - size_t size() const; - bool empty(); - set_type copy(); - list peek(size_t count) const; - - }; - - template - WorkQueue::~WorkQueue() - { - if (!m_set.empty()) { - cerr << "ERROR: " << m_set.size() << " locked items still in WorkQueue " << this << " at destruction" << endl; - } - } - - template - void - WorkQueue::push(const key_type &name) - { - unique_lock lock(m_mutex); - while (!m_set.count(name) && m_set.size() > m_max_queue_depth) { - m_cond_full.wait(lock); - } - m_set.insert(name); - m_cond_empty.notify_all(); - } - - template - void - WorkQueue::push_wait(const key_type &name, size_t limit) - { - unique_lock lock(m_mutex); - while (!m_set.count(name) && m_set.size() >= limit) { - m_cond_full.wait(lock); - } - m_set.insert(name); - m_cond_empty.notify_all(); - } - - template - void - WorkQueue::push_nowait(const key_type &name) - { - unique_lock lock(m_mutex); - m_set.insert(name); - m_cond_empty.notify_all(); - } - - template - typename WorkQueue::key_type - WorkQueue::pop() - { - unique_lock lock(m_mutex); - while (m_set.empty()) { - m_cond_empty.wait(lock); - } - key_type rv = *m_set.begin(); - m_set.erase(m_set.begin()); - m_cond_full.notify_all(); - return rv; - } - - template - bool - WorkQueue::pop_nowait(key_type &rv) - { - unique_lock lock(m_mutex); - if (m_set.empty()) { - return false; - } - rv = *m_set.begin(); - m_set.erase(m_set.begin()); - m_cond_full.notify_all(); - return true; - } - - template - typename WorkQueue::key_type - WorkQueue::peek() - { - unique_lock lock(m_mutex); - if (m_set.empty()) { - return key_type(); - } else { - // Make copy with lock held - auto rv = *m_set.begin(); - return rv; - } - } - - template - size_t - WorkQueue::size() const - { - unique_lock lock(m_mutex); - return m_set.size(); - } - - template - bool - WorkQueue::empty() - { - unique_lock lock(m_mutex); - return m_set.empty(); - } - - template - typename WorkQueue::set_type - WorkQueue::copy() - { - unique_lock lock(m_mutex); - auto rv = m_set; - return rv; - } - - template - list - WorkQueue::peek(size_t count) const - { - unique_lock lock(m_mutex); - list rv; - for (auto i : m_set) { - if (count--) { - rv.push_back(i); - } else { - break; - } - } - return rv; - } - - template - template - WorkQueue::WorkQueue(Args... args) : - m_set(args...), - m_max_queue_depth(numeric_limits::max()) - { - } - - template - template - WorkQueue::WorkQueue(size_t max_depth, Args... args) : - m_set(args...), - m_max_queue_depth(max_depth) - { - } - -} - -#endif // CRUCIBLE_WORKQUEUE_H diff --git a/src/bees.h b/src/bees.h index 53ed33c..cdbc34e 100644 --- a/src/bees.h +++ b/src/bees.h @@ -9,8 +9,6 @@ #include "crucible/fs.h" #include "crucible/lockset.h" #include "crucible/time.h" -#include "crucible/timequeue.h" -#include "crucible/workqueue.h" #include #include