win32/ComWorker: use std::queue/Mutex/Cond instead of boost::lockfree::spsc_queue/WinEvent
This commit is contained in:
parent
80b1f49af7
commit
debac0dfd4
@ -28,15 +28,18 @@ COMWorker::Work() noexcept
|
|||||||
{
|
{
|
||||||
SetThreadName("COM Worker");
|
SetThreadName("COM Worker");
|
||||||
COM com;
|
COM com;
|
||||||
while (true) {
|
|
||||||
if (!running_flag.test_and_set()) {
|
std::unique_lock lock{mutex};
|
||||||
return;
|
while (running_flag) {
|
||||||
}
|
while (!queue.empty()) {
|
||||||
while (!spsc_buffer.empty()) {
|
auto function = std::move(queue.front());
|
||||||
std::function<void()> function;
|
queue.pop();
|
||||||
spsc_buffer.pop(function);
|
|
||||||
|
lock.unlock();
|
||||||
function();
|
function();
|
||||||
|
lock.lock();
|
||||||
}
|
}
|
||||||
event.Wait(200);
|
|
||||||
|
cond.wait(lock);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,19 +20,23 @@
|
|||||||
#ifndef MPD_WIN32_COM_WORKER_HXX
|
#ifndef MPD_WIN32_COM_WORKER_HXX
|
||||||
#define MPD_WIN32_COM_WORKER_HXX
|
#define MPD_WIN32_COM_WORKER_HXX
|
||||||
|
|
||||||
#include "WinEvent.hxx"
|
#include "thread/Cond.hxx"
|
||||||
#include "thread/Future.hxx"
|
#include "thread/Future.hxx"
|
||||||
|
#include "thread/Mutex.hxx"
|
||||||
#include "thread/Thread.hxx"
|
#include "thread/Thread.hxx"
|
||||||
|
|
||||||
#include <boost/lockfree/spsc_queue.hpp>
|
#include <functional>
|
||||||
|
#include <queue>
|
||||||
|
|
||||||
// Worker thread for all COM operation
|
// Worker thread for all COM operation
|
||||||
class COMWorker {
|
class COMWorker {
|
||||||
Thread thread{BIND_THIS_METHOD(Work)};
|
Mutex mutex;
|
||||||
|
Cond cond;
|
||||||
|
|
||||||
boost::lockfree::spsc_queue<std::function<void()>> spsc_buffer{32};
|
std::queue<std::function<void()>> queue;
|
||||||
std::atomic_flag running_flag = true;
|
bool running_flag = true;
|
||||||
WinEvent event{};
|
|
||||||
|
Thread thread{BIND_THIS_METHOD(Work)};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
COMWorker() {
|
COMWorker() {
|
||||||
@ -70,13 +74,15 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
void Finish() noexcept {
|
void Finish() noexcept {
|
||||||
running_flag.clear();
|
const std::scoped_lock lock{mutex};
|
||||||
event.Set();
|
running_flag = false;
|
||||||
|
cond.notify_one();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Push(const std::function<void()> &function) {
|
void Push(const std::function<void()> &function) {
|
||||||
spsc_buffer.push(function);
|
const std::scoped_lock lock{mutex};
|
||||||
event.Set();
|
queue.push(function);
|
||||||
|
cond.notify_one();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Work() noexcept;
|
void Work() noexcept;
|
||||||
|
Loading…
Reference in New Issue
Block a user