From 8a8d725b438bc8162bea50a175b9a9fa2cc620bd Mon Sep 17 00:00:00 2001 From: nicole mazzuca Date: Thu, 9 Jul 2020 16:04:59 -0700 Subject: [PATCH] [vcpkg] Remove unnecessary work queue (#12350) this work queue implementation was added at some point, and is no longer used anywhere. Delete it as not used; if we need it again, we can grab it from the history --- toolsrc/include/vcpkg/base/work_queue.h | 140 ------------------------ toolsrc/src/vcpkg/base/files.cpp | 1 - 2 files changed, 141 deletions(-) delete mode 100644 toolsrc/include/vcpkg/base/work_queue.h diff --git a/toolsrc/include/vcpkg/base/work_queue.h b/toolsrc/include/vcpkg/base/work_queue.h deleted file mode 100644 index ba622361ab6..00000000000 --- a/toolsrc/include/vcpkg/base/work_queue.h +++ /dev/null @@ -1,140 +0,0 @@ -#pragma once - -#include -#include -#include - -#include - -namespace vcpkg -{ - template - struct WorkQueue - { - WorkQueue(LineInfo li) : m_line_info(li) { } - WorkQueue(const WorkQueue&) = delete; - - ~WorkQueue() - { - auto lck = std::unique_lock(m_mutex, std::try_to_lock); - /* - if we don't own the lock, there isn't much we can do - it is likely a spurious failure - */ - if (lck && m_running_workers != 0) - { - Checks::exit_with_message( - m_line_info, "Internal error -- outstanding workers (%u) at destruct point", m_running_workers); - } - } - - template - void run_and_join(unsigned num_threads, const F& tld_init) noexcept - { - if (m_actions.empty()) return; - - std::vector threads; - threads.reserve(num_threads); - for (unsigned i = 0; i < num_threads; ++i) - { - threads.emplace_back(Worker{this, tld_init()}); - } - - for (auto& thrd : threads) - { - thrd.join(); - } - } - - // useful in the case of errors - // doesn't stop any existing running tasks - // returns immediately, so that one can call this in a task - void cancel() const - { - { - auto lck = std::lock_guard(m_mutex); - m_cancelled = true; - m_actions.clear(); - } - m_cv.notify_all(); - } - - void enqueue_action(Action a) const - { - { - auto lck = std::lock_guard(m_mutex); - if (m_cancelled) return; - - m_actions.push_back(std::move(a)); - } - m_cv.notify_one(); - } - - private: - template - struct Worker - { - const WorkQueue* work_queue; - ThreadLocalData tld; - - void operator()() - { - auto lck = std::unique_lock(work_queue->m_mutex); - for (;;) - { - const auto& w = *work_queue; - work_queue->m_cv.wait(lck, [&w] { - if (w.m_cancelled) - return true; - else if (!w.m_actions.empty()) - return true; - else if (w.m_running_workers == 0) - return true; - else - return false; - }); - - if (work_queue->m_cancelled || work_queue->m_actions.empty()) - { - /* - if we've been cancelled, or if the work queue is empty - and there are no other workers, we want to return - immediately; we don't check for the latter condition - since if we're at this point, then either the queue - is not empty, or there are no other workers, or both. - We can't have an empty queue, and other workers, or - we would still be in the wait. - */ - break; - } - - ++work_queue->m_running_workers; - - auto action = std::move(work_queue->m_actions.back()); - work_queue->m_actions.pop_back(); - - lck.unlock(); - work_queue->m_cv.notify_one(); - std::move(action)(tld, *work_queue); - lck.lock(); - - const auto after = --work_queue->m_running_workers; - if (work_queue->m_actions.empty() && after == 0) - { - work_queue->m_cv.notify_all(); - return; - } - } - } - }; - - mutable std::mutex m_mutex{}; - // these are all under m_mutex - mutable bool m_cancelled = false; - mutable std::vector m_actions{}; - mutable std::condition_variable m_cv{}; - mutable unsigned long m_running_workers = 0; - - LineInfo m_line_info; - }; -} diff --git a/toolsrc/src/vcpkg/base/files.cpp b/toolsrc/src/vcpkg/base/files.cpp index f119edace82..52421bd5544 100644 --- a/toolsrc/src/vcpkg/base/files.cpp +++ b/toolsrc/src/vcpkg/base/files.cpp @@ -6,7 +6,6 @@ #include #include #include -#include #if !defined(_WIN32) #include