diff options
| author | 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com> | 2025-09-08 21:10:30 +1000 |
|---|---|---|
| committer | 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com> | 2025-09-08 21:10:30 +1000 |
| commit | d0fdbefbfb60994ad8d6cf3b7129dcdd556c1924 (patch) | |
| tree | 5319ea868c554d470ab3c74d7ba4a28442fbeaff /plugin/src/Caelestia/service.cpp | |
| parent | dev: export cmake compile commands (diff) | |
| download | caelestia-shell-d0fdbefbfb60994ad8d6cf3b7129dcdd556c1924.tar.gz caelestia-shell-d0fdbefbfb60994ad8d6cf3b7129dcdd556c1924.tar.bz2 caelestia-shell-d0fdbefbfb60994ad8d6cf3b7129dcdd556c1924.zip | |
plugin/ap: fix collector
Actually read from speakers not mic
Diffstat (limited to 'plugin/src/Caelestia/service.cpp')
| -rw-r--r-- | plugin/src/Caelestia/service.cpp | 41 |
1 files changed, 29 insertions, 12 deletions
diff --git a/plugin/src/Caelestia/service.cpp b/plugin/src/Caelestia/service.cpp index 9c13421..5d5232b 100644 --- a/plugin/src/Caelestia/service.cpp +++ b/plugin/src/Caelestia/service.cpp @@ -1,6 +1,7 @@ #include "service.hpp" #include <QDebug> +#include <QMutexLocker> #include <QObject> namespace caelestia { @@ -9,30 +10,46 @@ Service::Service(QObject* parent) : QObject(parent) , m_refCount(0) {} -int Service::refCount() const { +int Service::refCount() { + QMutexLocker locker(&m_mutex); return m_refCount; } void Service::ref() { - if (m_refCount == 0) { - start(); - } + bool needsStart = false; - m_refCount++; + { + QMutexLocker locker(&m_mutex); + if (m_refCount == 0) { + needsStart = true; + } + m_refCount++; + } emit refCountChanged(); + + if (needsStart) { + QMetaObject::invokeMethod(this, &Service::start, Qt::QueuedConnection); + } } void Service::unref() { - if (m_refCount == 0) { - qWarning() << "ServiceRef::unref: attempted to unref service with no active refs"; - return; - } + bool needsStop = false; - m_refCount--; + { + QMutexLocker locker(&m_mutex); + if (m_refCount == 0) { + qWarning() << "ServiceRef::unref: attempted to unref service with no active refs"; + return; + } + m_refCount--; + if (m_refCount == 0) { + needsStop = true; + } + } emit refCountChanged(); - if (m_refCount == 0) { - stop(); + if (needsStop) { + QMetaObject::invokeMethod(this, &Service::stop, Qt::QueuedConnection); } } |