summaryrefslogtreecommitdiff
path: root/plugin/src/Caelestia/Services/service.cpp
diff options
context:
space:
mode:
author2 * r + 2 * t <61896496+soramanew@users.noreply.github.com>2025-09-16 23:58:44 +1000
committer2 * r + 2 * t <61896496+soramanew@users.noreply.github.com>2025-09-16 23:58:44 +1000
commit1984458565462f0f7d54266021e7f1977bc4b302 (patch)
treecfa2c7cbd6630acc8caf4b8740d7446abd2f0cd3 /plugin/src/Caelestia/Services/service.cpp
parentutilities/toggles: add dnd (diff)
downloadcaelestia-shell-1984458565462f0f7d54266021e7f1977bc4b302.tar.gz
caelestia-shell-1984458565462f0f7d54266021e7f1977bc4b302.tar.bz2
caelestia-shell-1984458565462f0f7d54266021e7f1977bc4b302.zip
plugin: fix crashes
Fixes #629
Diffstat (limited to 'plugin/src/Caelestia/Services/service.cpp')
-rw-r--r--plugin/src/Caelestia/Services/service.cpp52
1 files changed, 10 insertions, 42 deletions
diff --git a/plugin/src/Caelestia/Services/service.cpp b/plugin/src/Caelestia/Services/service.cpp
index bc919c9..e63b990 100644
--- a/plugin/src/Caelestia/Services/service.cpp
+++ b/plugin/src/Caelestia/Services/service.cpp
@@ -10,60 +10,28 @@ Service::Service(QObject* parent)
, m_refCount(0) {}
int Service::refCount() const {
- QMutexLocker locker(&m_mutex);
return m_refCount;
}
void Service::ref() {
- bool needsStart = false;
-
- {
- QMutexLocker locker(&m_mutex);
- if (m_refCount == 0) {
- needsStart = true;
- }
- m_refCount++;
+ if (m_refCount == 0) {
+ start();
}
- emit refCountChanged();
- if (needsStart) {
- const QPointer<Service> self(this);
- QMetaObject::invokeMethod(
- this,
- [self]() {
- if (self) {
- self->start();
- }
- },
- Qt::QueuedConnection);
- }
+ m_refCount++;
+ emit refCountChanged();
}
void Service::unref() {
- bool needsStop = false;
-
- {
- QMutexLocker locker(&m_mutex);
- if (m_refCount == 0) {
- return;
- }
- m_refCount--;
- if (m_refCount == 0) {
- needsStop = true;
- }
+ if (m_refCount == 0) {
+ return;
}
+
+ m_refCount--;
emit refCountChanged();
- if (needsStop) {
- const QPointer<Service> self(this);
- QMetaObject::invokeMethod(
- this,
- [self]() {
- if (self) {
- self->stop();
- }
- },
- Qt::QueuedConnection);
+ if (m_refCount == 0) {
+ stop();
}
}