Phase C: replace YtDlpManager's hand-rolled pool with Void ThreadPool
YtDlpManager carried a bespoke worker pool — a jthread vector, a packaged_task queue, and a mutex/condition_variable/stop-flag loop. Swap all of it for a single Void::Concurrency::ThreadPool (held by unique_ptr so setThreadPoolSize can recreate it): - startThreadPool() constructs the pool at the (auto-adjusted) size; stopThreadPool() resets it (the destructor drains and joins). - executeAsync() submits to the pool under mutex_ (mutually exclusive with start/stop), with a synchronous fallback if called before start. - workerThread() and the taskQueue_/taskCv_/taskMutex_/stopThreads_ members are gone. Behaviorally equivalent (bounded yt-dlp concurrency, same std::future results) with far less concurrency code to own. Build green. The init-time "update yt-dlp in background" detached thread is left as-is: it's a one-shot fired before the pool exists. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
1 parent
5775c522eb
commit
da708fa9bb
2 files changed
+17
-61
No files matched your search
@@ -3,13 +3,13 @@
|
||||
#include "NetworkClient.hpp"
|
||||
#include <TrackTypes.hpp>
|
||||
#include <Types.hpp>
|
||||
#include <Void/Async/ThreadPool.hpp>
|
||||
#include <YouTubeTypes.hpp>
|
||||
#include <atomic>
|
||||
#include <condition_variable>
|
||||
#include <filesystem>
|
||||
#include <future>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <queue>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
@@ -105,7 +105,6 @@ namespace Echoion::Core
|
||||
// Thread pool for async operations
|
||||
void startThreadPool();
|
||||
void stopThreadPool();
|
||||
void workerThread();
|
||||
|
||||
std::shared_ptr<NetworkClient> networkClient_;
|
||||
std::filesystem::path executablePath_;
|
||||
@@ -120,13 +119,10 @@ namespace Echoion::Core
|
||||
std::optional<Api::ProxyConfig> proxyConfig_;
|
||||
mutable std::mutex proxyMutex_;
|
||||
|
||||
// Thread pool for async operations
|
||||
// Thread pool for async operations (Void worker pool; recreated
|
||||
// on resize). Guarded by mutex_ for start/stop/submit.
|
||||
size_t threadPoolSize_ = 4;
|
||||
std::vector<std::jthread> threadPool_;
|
||||
std::queue<std::packaged_task<YtDlpResult()>> taskQueue_;
|
||||
std::mutex taskMutex_;
|
||||
std::condition_variable taskCv_;
|
||||
std::atomic<bool> stopThreads_{false};
|
||||
std::unique_ptr<Void::Concurrency::ThreadPool> pool_;
|
||||
|
||||
// yt-dlp download URLs
|
||||
static constexpr std::string_view YTDLP_VERSION_URL =
|
||||
|
||||
Reference in new issue
Block a user