From 48bdd09f6458b93605fd5700a6e0fe9b8ccd22aa Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Sun, 7 Mar 2021 18:21:56 +0100 Subject: [PATCH] win32/ComWorker: fold class COMWorkerThread into class COMWorker --- src/win32/ComWorker.cxx | 4 +++- src/win32/ComWorker.hxx | 40 +++++++++++++++++----------------------- 2 files changed, 20 insertions(+), 24 deletions(-) diff --git a/src/win32/ComWorker.cxx b/src/win32/ComWorker.cxx index 01f67a5f9..5de211071 100644 --- a/src/win32/ComWorker.cxx +++ b/src/win32/ComWorker.cxx @@ -21,7 +21,9 @@ #include "Com.hxx" #include "thread/Name.hxx" -void COMWorker::COMWorkerThread::Work() noexcept { +void +COMWorker::Work() noexcept +{ SetThreadName("COM Worker"); COM com{true}; while (true) { diff --git a/src/win32/ComWorker.hxx b/src/win32/ComWorker.hxx index 3fa0db44a..d4c410652 100644 --- a/src/win32/ComWorker.hxx +++ b/src/win32/ComWorker.hxx @@ -30,27 +30,11 @@ // Worker thread for all COM operation class COMWorker { -private: - class COMWorkerThread : public Thread { - public: - COMWorkerThread() : Thread{BIND_THIS_METHOD(Work)} {} + Thread thread{BIND_THIS_METHOD(Work)}; - private: - friend class COMWorker; - void Work() noexcept; - void Finish() noexcept { - running_flag.clear(); - event.Set(); - } - void Push(const std::function &function) { - spsc_buffer.push(function); - event.Set(); - } - - boost::lockfree::spsc_queue> spsc_buffer{32}; - std::atomic_flag running_flag = true; - WinEvent event{}; - }; + boost::lockfree::spsc_queue> spsc_buffer{32}; + std::atomic_flag running_flag = true; + WinEvent event{}; public: COMWorker() { @@ -58,7 +42,7 @@ public: } ~COMWorker() noexcept { - thread.Finish(); + Finish(); thread.Join(); } @@ -70,7 +54,7 @@ public: using R = std::invoke_result_t>; auto promise = std::make_shared>(); auto future = promise->get_future(); - thread.Push([function = std::forward(function), + Push([function = std::forward(function), promise = std::move(promise)]() mutable { try { if constexpr (std::is_void_v) { @@ -87,7 +71,17 @@ public: } private: - COMWorkerThread thread; + void Finish() noexcept { + running_flag.clear(); + event.Set(); + } + + void Push(const std::function &function) { + spsc_buffer.push(function); + event.Set(); + } + + void Work() noexcept; }; #endif