actually get the code compiling

This commit is contained in:
Nicole Mazzuca 2019-07-10 15:42:13 -07:00
parent 43493b56df
commit 3b6d6b3465
2 changed files with 28 additions and 23 deletions

View File

@ -1,10 +1,15 @@
#pragma once
#include <condition_variable>
#include <memory>
#include <queue>
namespace vcpkg {
template <class Action, class ThreadLocalData>
struct WorkQueue;
namespace detail {
// for SFINAE purposes, keep out of the class
template <class Action, class ThreadLocalData>
auto call_action(
Action& action,
@ -29,8 +34,8 @@ namespace vcpkg {
template <class Action, class ThreadLocalData>
struct WorkQueue {
template <class F>
explicit WorkQueue(const F& initializer) noexcept {
state = State::Joining;
explicit WorkQueue(const F& tld_init) noexcept {
m_state = State::Running;
std::size_t num_threads = std::thread::hardware_concurrency();
if (num_threads == 0) {
@ -39,7 +44,7 @@ namespace vcpkg {
m_threads.reserve(num_threads);
for (std::size_t i = 0; i < num_threads; ++i) {
m_threads.emplace_back(this, initializer);
m_threads.push_back(std::thread(Worker{this, tld_init()}));
}
}
@ -93,10 +98,10 @@ namespace vcpkg {
auto lck = std::unique_lock<std::mutex>(m_mutex);
auto first = begin(rng);
auto last = end(rng);
const auto first = begin(rng);
const auto last = end(rng);
m_actions.reserve(m_actions.size() + (end - begin));
m_actions.reserve(m_actions.size() + (last - first));
std::move(first, last, std::back_insert_iterator(rng));
}
@ -112,10 +117,10 @@ namespace vcpkg {
auto lck = std::unique_lock<std::mutex>(m_mutex);
auto first = begin(rng);
auto last = end(rng);
const auto first = begin(rng);
const auto last = end(rng);
m_actions.reserve(m_actions.size() + (end - begin));
m_actions.reserve(m_actions.size() + (last - first));
std::copy(first, last, std::back_insert_iterator(rng));
}
@ -124,18 +129,15 @@ namespace vcpkg {
}
private:
friend struct WorkQueueWorker {
struct Worker {
const WorkQueue* work_queue;
ThreadLocalData tld;
template <class F>
WorkQueueWorker(const WorkQueue* work_queue, const F& initializer)
: work_queue(work_queue), tld(initializer())
{ }
void operator()() {
// unlocked when waiting, or when in the `call_action` block
// locked otherwise
auto lck = std::unique_lock<std::mutex>(work_queue->m_mutex);
for (;;) {
auto lck = std::unique_lock<std::mutex>(work_queue->m_mutex);
++work_queue->running_workers;
const auto state = work_queue->m_state;
@ -157,10 +159,12 @@ namespace vcpkg {
return;
}
Action action = work_queue->m_actions.pop_back();
lck.unlock();
Action action = std::move(work_queue->m_actions.back());
work_queue->m_actions.pop_back();
lck.unlock();
detail::call_action(action, *work_queue, tld);
lck.lock();
}
}
};
@ -176,7 +180,7 @@ namespace vcpkg {
mutable State m_state;
mutable std::uint16_t running_workers;
mutable std::vector<Action> m_actions;
mutable std::condition_variable condition_variable;
mutable std::condition_variable m_cv;
std::vector<std::thread> m_threads;
};

View File

@ -1,7 +1,6 @@
#include "pch.h"
#include <vcpkg/base/files.h>
#include <vcpkg/base/rng.h>
#include <vcpkg/base/system.debug.h>
#include <vcpkg/base/system.h>
#include <vcpkg/base/system.print.h>
@ -57,7 +56,9 @@ namespace fs {
file_status decltype(symlink_status)::operator()(const path& p) const noexcept {
std::error_code ec;
auto result = symlink_status(p, ec);
if (ec) vcpkg::Checks::exit_with_message(VCPKG_LINE_INFO, "error getting status of path %s: %s", p, ec.message());
if (ec) vcpkg::Checks::exit_with_message(VCPKG_LINE_INFO, "error getting status of path %s: %s", p.string(), ec.message());
return result;
}
}
@ -393,11 +394,11 @@ namespace vcpkg::Files
std::mutex ec_mutex;
auto queue = remove::queue([&] {
index += 1 << 32;
index += static_cast<std::uint64_t>(1) << 32;
return remove::tld{path, index, files_deleted, ec_mutex, ec};
});
index += 1 << 32;
index += static_cast<std::uint64_t>(1) << 32;
auto main_tld = remove::tld{path, index, files_deleted, ec_mutex, ec};
for (const auto& entry : fs::stdfs::directory_iterator(path)) {
remove{}(entry, main_tld, queue);