aboutsummaryrefslogtreecommitdiff
path: root/toolsrc/include
diff options
context:
space:
mode:
authorNicole Mazzuca <t-nimaz@microsoft.com>2019-07-15 18:51:03 -0700
committerNicole Mazzuca <t-nimaz@microsoft.com>2019-07-15 18:51:03 -0700
commit65d34c5e55ef30a6572dfb3b79d212196fbadc0d (patch)
tree87cf2bf14e22ab68cc622eb7f8bd9e030cac106b /toolsrc/include
parent02c977186e890e4090d91c171b42d20729e668af (diff)
downloadvcpkg-65d34c5e55ef30a6572dfb3b79d212196fbadc0d.tar.gz
vcpkg-65d34c5e55ef30a6572dfb3b79d212196fbadc0d.zip
wheeeee more fixes
Diffstat (limited to 'toolsrc/include')
-rw-r--r--toolsrc/include/vcpkg/base/strings.h8
-rw-r--r--toolsrc/include/vcpkg/base/work_queue.h89
2 files changed, 31 insertions, 66 deletions
diff --git a/toolsrc/include/vcpkg/base/strings.h b/toolsrc/include/vcpkg/base/strings.h
index a1906790f..aa4c4d690 100644
--- a/toolsrc/include/vcpkg/base/strings.h
+++ b/toolsrc/include/vcpkg/base/strings.h
@@ -185,8 +185,8 @@ namespace vcpkg::Strings
bool contains(StringView haystack, StringView needle);
- // base 64 encoding with URL and filesafe alphabet (base64url)
- // based on IETF RFC 4648
- // ignores padding, since one implicitly knows the length from the size of x
- std::string b64url_encode(std::uint64_t x) noexcept;
+ // base 32 encoding, since base64 encoding requires lowercase letters,
+ // which are not distinct from uppercase letters on macOS or Windows filesystems.
+ // follows RFC 4648
+ std::string b32_encode(std::uint64_t x) noexcept;
}
diff --git a/toolsrc/include/vcpkg/base/work_queue.h b/toolsrc/include/vcpkg/base/work_queue.h
index d6666770b..69ca387f3 100644
--- a/toolsrc/include/vcpkg/base/work_queue.h
+++ b/toolsrc/include/vcpkg/base/work_queue.h
@@ -36,7 +36,7 @@ namespace vcpkg
{
m_line_info = li;
- m_unjoined_workers = num_threads;
+ set_unjoined_workers(num_threads);
m_threads.reserve(num_threads);
for (std::size_t i = 0; i < num_threads; ++i)
{
@@ -93,20 +93,16 @@ namespace vcpkg
}
}
- for (;;)
+ while (unjoined_workers())
{
- auto lck = std::unique_lock<std::mutex>(m_mutex);
- if (!m_unjoined_workers)
- break;
-
- else if (!m_running_workers)
+ if (!running_workers())
{
- lck.unlock();
- m_cv.notify_all();
- }
+ m_cv.notify_one();
+
+ }
}
- // all threads have returned -- now, it's time to join them
+ // wait for all threads to join
for (auto& thrd : m_threads)
{
thrd.join();
@@ -143,50 +139,6 @@ namespace vcpkg
m_cv.notify_one();
}
- template<class Rng>
- void enqueue_all_actions_by_move(Rng&& rng) const
- {
- {
- using std::begin;
- using std::end;
-
- auto lck = std::unique_lock<std::mutex>(m_mutex);
-
- const auto first = begin(rng);
- const auto last = end(rng);
-
- m_actions.reserve(m_actions.size() + (last - first));
-
- std::move(first, last, std::back_inserter(rng));
-
- if (m_state == State::BeforeRun) return;
- }
-
- m_cv.notify_all();
- }
-
- template<class Rng>
- void enqueue_all_actions(Rng&& rng) const
- {
- {
- using std::begin;
- using std::end;
-
- auto lck = std::unique_lock<std::mutex>(m_mutex);
-
- const auto first = begin(rng);
- const auto last = end(rng);
-
- m_actions.reserve(m_actions.size() + (last - first));
-
- std::copy(first, last, std::back_inserter(rng));
-
- if (m_state == State::BeforeRun) return;
- }
-
- m_cv.notify_all();
- }
-
private:
struct Worker
{
@@ -201,6 +153,7 @@ namespace vcpkg
work_queue->m_cv.wait(lck, [&] { return work_queue->m_state != State::BeforeRun; });
+ work_queue->increment_running_workers();
for (;;)
{
const auto state = work_queue->m_state;
@@ -212,15 +165,15 @@ namespace vcpkg
if (work_queue->m_actions.empty())
{
- if (state == State::Running || work_queue->m_running_workers > 1)
+ if (state == State::Running || work_queue->running_workers() > 1)
{
- --work_queue->m_running_workers;
+ work_queue->decrement_running_workers();
work_queue->m_cv.wait(lck);
- ++work_queue->m_running_workers;
+ work_queue->increment_running_workers();
continue;
}
- // the queue isn't running, and we are the only worker
+ // the queue is joining, and we are the only worker running
// no more work!
break;
}
@@ -229,11 +182,13 @@ namespace vcpkg
work_queue->m_actions.pop_back();
lck.unlock();
+ work_queue->m_cv.notify_one();
detail::call_moved_action(action, *work_queue, tld);
lck.lock();
}
- --work_queue->m_unjoined_workers;
+ work_queue->decrement_running_workers();
+ work_queue->decrement_unjoined_workers();
}
};
@@ -255,11 +210,21 @@ namespace vcpkg
mutable std::mutex m_mutex{};
// these are all under m_mutex
mutable State m_state = State::BeforeRun;
- mutable std::uint16_t m_running_workers = 0;
- mutable std::uint16_t m_unjoined_workers = 0; // num_threads
mutable std::vector<Action> m_actions{};
mutable std::condition_variable m_cv{};
+ mutable std::atomic<std::uint32_t> m_workers;
+ // = unjoined_workers << 16 | running_workers
+
+ void set_unjoined_workers(std::uint16_t threads) { m_workers = std::uint32_t(threads) << 16; }
+ void decrement_unjoined_workers() const { m_workers -= 1 << 16; }
+
+ std::uint16_t unjoined_workers() const { return std::uint16_t(m_workers >> 16); }
+
+ void increment_running_workers() const { ++m_workers; }
+ void decrement_running_workers() const { --m_workers; }
+ std::uint16_t running_workers() const { return std::uint16_t(m_workers); }
+
std::vector<std::thread> m_threads{};
LineInfo m_line_info;
};