Skip to content

Commit

Permalink
Don't optional by making JThread movable.
Browse files Browse the repository at this point in the history
  • Loading branch information
BillyONeal committed Feb 15, 2024
1 parent 6620a63 commit a5ea305
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions include/vcpkg/base/parallel-algorithms.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
#if defined(_WIN32)
#include <vcpkg/base/system-headers.h>
#else // ^^^ _WIN32 / !_WIN32 vvv
#include <vcpkg/base/optional.h>

#include <system_error>
#include <thread>
#include <type_traits>
Expand Down Expand Up @@ -113,6 +111,8 @@ namespace vcpkg

JThread(const JThread&) = delete;
JThread& operator=(const JThread&) = delete;
JThread(JThread&&) = default;
JThread& operator=(JThread&&) = default;

private:
std::thread m_thread;
Expand All @@ -135,12 +135,14 @@ namespace vcpkg
WorkCallbackContext<F> context{work, work_count};
auto max_threads = std::min(work_count, static_cast<size_t>(get_concurrency()));
max_threads = std::min(max_threads, (SIZE_MAX - work_count) + 1u); // to avoid overflow in fetch_add
std::vector<Optional<JThread>> bg_threads(max_threads - 1);
for (auto&& bg_thread : bg_threads)
auto bg_thread_count = max_threads - 1;
std::vector<JThread> bg_threads;
bg_threads.reserve(bg_thread_count);
for (size_t i = 0; i < bg_thread_count; ++i)
{
try
{
bg_thread.emplace([&]() { context.run(); });
bg_threads.emplace_back([&]() { context.run(); });
}
catch (const std::system_error&)
{
Expand Down

0 comments on commit a5ea305

Please sign in to comment.