diff options
Diffstat (limited to 'plugin/src/Caelestia/Services/service.cpp')
| -rw-r--r-- | plugin/src/Caelestia/Services/service.cpp | 52 |
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(); } } |