win32/ComWorker: fold class COMWorkerThread into class COMWorker
This commit is contained in:
@@ -21,7 +21,9 @@
|
|||||||
#include "Com.hxx"
|
#include "Com.hxx"
|
||||||
#include "thread/Name.hxx"
|
#include "thread/Name.hxx"
|
||||||
|
|
||||||
void COMWorker::COMWorkerThread::Work() noexcept {
|
void
|
||||||
|
COMWorker::Work() noexcept
|
||||||
|
{
|
||||||
SetThreadName("COM Worker");
|
SetThreadName("COM Worker");
|
||||||
COM com{true};
|
COM com{true};
|
||||||
while (true) {
|
while (true) {
|
||||||
|
@@ -30,27 +30,11 @@
|
|||||||
|
|
||||||
// Worker thread for all COM operation
|
// Worker thread for all COM operation
|
||||||
class COMWorker {
|
class COMWorker {
|
||||||
private:
|
Thread thread{BIND_THIS_METHOD(Work)};
|
||||||
class COMWorkerThread : public Thread {
|
|
||||||
public:
|
|
||||||
COMWorkerThread() : 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<void()> &function) {
|
|
||||||
spsc_buffer.push(function);
|
|
||||||
event.Set();
|
|
||||||
}
|
|
||||||
|
|
||||||
boost::lockfree::spsc_queue<std::function<void()>> spsc_buffer{32};
|
boost::lockfree::spsc_queue<std::function<void()>> spsc_buffer{32};
|
||||||
std::atomic_flag running_flag = true;
|
std::atomic_flag running_flag = true;
|
||||||
WinEvent event{};
|
WinEvent event{};
|
||||||
};
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
COMWorker() {
|
COMWorker() {
|
||||||
@@ -58,7 +42,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
~COMWorker() noexcept {
|
~COMWorker() noexcept {
|
||||||
thread.Finish();
|
Finish();
|
||||||
thread.Join();
|
thread.Join();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -70,7 +54,7 @@ public:
|
|||||||
using R = std::invoke_result_t<std::decay_t<Function>>;
|
using R = std::invoke_result_t<std::decay_t<Function>>;
|
||||||
auto promise = std::make_shared<Promise<R>>();
|
auto promise = std::make_shared<Promise<R>>();
|
||||||
auto future = promise->get_future();
|
auto future = promise->get_future();
|
||||||
thread.Push([function = std::forward<Function>(function),
|
Push([function = std::forward<Function>(function),
|
||||||
promise = std::move(promise)]() mutable {
|
promise = std::move(promise)]() mutable {
|
||||||
try {
|
try {
|
||||||
if constexpr (std::is_void_v<R>) {
|
if constexpr (std::is_void_v<R>) {
|
||||||
@@ -87,7 +71,17 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
COMWorkerThread thread;
|
void Finish() noexcept {
|
||||||
|
running_flag.clear();
|
||||||
|
event.Set();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Push(const std::function<void()> &function) {
|
||||||
|
spsc_buffer.push(function);
|
||||||
|
event.Set();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Work() noexcept;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Reference in New Issue
Block a user