mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-21 04:45:31 +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:
@@ -101,8 +101,10 @@ namespace BlackMisc
|
|||||||
|
|
||||||
CDataCache *CDataCache::instance()
|
CDataCache *CDataCache::instance()
|
||||||
{
|
{
|
||||||
static CDataCache cache;
|
static std::unique_ptr<CDataCache> cache(new CDataCache);
|
||||||
return &cache;
|
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 &CDataCache::persistentStore()
|
const QString &CDataCache::persistentStore()
|
||||||
|
|||||||
@@ -19,8 +19,10 @@ namespace BlackMisc
|
|||||||
|
|
||||||
CSettingsCache *CSettingsCache::instance()
|
CSettingsCache *CSettingsCache::instance()
|
||||||
{
|
{
|
||||||
static CSettingsCache cache;
|
static std::unique_ptr<CSettingsCache> cache(new CSettingsCache);
|
||||||
return &cache;
|
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()
|
const QString &CSettingsCache::persistentStore()
|
||||||
|
|||||||
Reference in New Issue
Block a user