mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-23 07:15:35 +08:00
Lifetime management of value cache singletons
Hook in to the `destroyed` signal of the `qApp` to destroy the caches. This ensures any associated workers are quit before application terminates and kills all the threads.
This commit is contained in:
@@ -19,8 +19,10 @@ namespace BlackMisc
|
||||
|
||||
CSettingsCache *CSettingsCache::instance()
|
||||
{
|
||||
static CSettingsCache cache;
|
||||
return &cache;
|
||||
static std::unique_ptr<CSettingsCache> cache(new CSettingsCache);
|
||||
static auto dummy = (connect(qApp, &QObject::destroyed, cache.get(), [] { cache.reset(); }), nullptr);
|
||||
Q_UNUSED(dummy) // declared as static to get thread-safe initialization
|
||||
return cache.get();
|
||||
}
|
||||
|
||||
const QString &CSettingsCache::persistentStore()
|
||||
|
||||
Reference in New Issue
Block a user