diff --git a/kdecore/io/kdebug.cpp b/kdecore/io/kdebug.cpp index 9840b421..5c645353 100644 --- a/kdecore/io/kdebug.cpp +++ b/kdecore/io/kdebug.cpp @@ -212,6 +212,23 @@ struct KDebugPrivate ~KDebugPrivate() { delete config; + + if (m_indentString) { + delete m_indentString; + m_indentString = 0; + } + if (syslogwriter) { + delete syslogwriter; + syslogwriter = 0; + } + if (filewriter) { + delete filewriter; + filewriter = 0; + } + if (messageboxwriter) { + delete messageboxwriter; + messageboxwriter = 0; + } } void loadAreaNames() @@ -402,18 +419,18 @@ struct KDebugPrivate QDebug setupFileWriter(const QString &fileName) { - if (!filewriter.hasLocalData()) - filewriter.setLocalData(new KFileDebugStream); - filewriter.localData()->setFileName(fileName); - QDebug result(filewriter.localData()); + if (!filewriter) + filewriter = new KFileDebugStream(); + filewriter->setFileName(fileName); + QDebug result(filewriter); return result; } QDebug setupMessageBoxWriter(QtMsgType type, const QByteArray &areaName) { - if (!messageboxwriter.hasLocalData()) - messageboxwriter.setLocalData(new KMessageBoxDebugStream); - QDebug result(messageboxwriter.localData()); + if (!messageboxwriter) + messageboxwriter = new KMessageBoxDebugStream(); + QDebug result(messageboxwriter); QByteArray header; switch (type) { @@ -434,15 +451,15 @@ struct KDebugPrivate header += areaName; header += ')'; - messageboxwriter.localData()->setCaption(QString::fromLatin1(header)); + messageboxwriter->setCaption(QString::fromLatin1(header)); return result; } QDebug setupSyslogWriter(QtMsgType type) { - if (!syslogwriter.hasLocalData()) - syslogwriter.setLocalData(new KSyslogDebugStream); - QDebug result(syslogwriter.localData()); + if (!syslogwriter) + syslogwriter = new KSyslogDebugStream(); + QDebug result(syslogwriter); int level = 0; switch (type) { @@ -460,7 +477,7 @@ struct KDebugPrivate level = LOG_ERR; break; } - syslogwriter.localData()->setPriority(level); + syslogwriter->setPriority(level); return result; } @@ -516,8 +533,8 @@ struct KDebugPrivate s << areaName.constData(); } - if (m_indentString.hasLocalData()) { - s << m_indentString.localData()->toLatin1().constData(); + if (m_indentString) { + s << m_indentString->toLatin1().constData(); } if (printFileLine) { @@ -652,13 +669,18 @@ struct KDebugPrivate int m_nullOutputYesNoCache[8]; KNoDebugStream devnull; - QThreadStorage m_indentString; - QThreadStorage syslogwriter; - QThreadStorage filewriter; - QThreadStorage messageboxwriter; + static thread_local QString* m_indentString; + static thread_local KSyslogDebugStream* syslogwriter; + static thread_local KFileDebugStream* filewriter; + static thread_local KMessageBoxDebugStream* messageboxwriter; KLineEndStrippingDebugStream lineendstrippingwriter; }; +thread_local QString* KDebugPrivate::m_indentString = 0; +thread_local KSyslogDebugStream* KDebugPrivate::syslogwriter = 0; +thread_local KFileDebugStream* KDebugPrivate::filewriter = 0; +thread_local KMessageBoxDebugStream* KDebugPrivate::messageboxwriter = 0; + K_GLOBAL_STATIC(KDebugPrivate, kDebug_data) #ifdef HAVE_BACKTRACE @@ -850,11 +872,10 @@ KDebug::Block::Block(const char* label, int area) kDebug(area) << "BEGIN:" << label; // The indent string is per thread - QThreadStorage & indentString = kDebug_data->m_indentString; - if (!indentString.hasLocalData()) { - indentString.setLocalData(new QString); + if (!kDebug_data->m_indentString) { + kDebug_data->m_indentString = new QString(); } - *(indentString.localData()) += QLatin1String(" "); + kDebug_data->m_indentString->append(QLatin1String(" ")); } } @@ -862,8 +883,7 @@ KDebug::Block::~Block() { if (d) { const double duration = m_startTime.elapsed() / 1000.0; - QThreadStorage & indentString = kDebug_data->m_indentString; - indentString.localData()->chop(2); + kDebug_data->m_indentString->chop(2); // Print timing information, and a special message (DELAY) if the method took longer than 5s if (duration < 5.0) { diff --git a/kdecore/sycoca/ksycoca.cpp b/kdecore/sycoca/ksycoca.cpp index a6d7f831..828e8a10 100644 --- a/kdecore/sycoca/ksycoca.cpp +++ b/kdecore/sycoca/ksycoca.cpp @@ -102,23 +102,30 @@ class KSycocaSingleton { public: KSycocaSingleton() { } - ~KSycocaSingleton() { } + ~KSycocaSingleton() + { + if (m_threadSycocas) { + delete m_threadSycocas; + m_threadSycocas = 0; + } + } bool hasSycoca() const { - return m_threadSycocas.hasLocalData(); + return (m_threadSycocas != 0); } KSycoca* sycoca() { - if (!m_threadSycocas.hasLocalData()) - m_threadSycocas.setLocalData(new KSycoca); - return m_threadSycocas.localData(); + if (!m_threadSycocas) + m_threadSycocas = new KSycoca(); + return m_threadSycocas; } void setSycoca(KSycoca* s) { - m_threadSycocas.setLocalData(s); + m_threadSycocas = s; } private: - QThreadStorage m_threadSycocas; + static thread_local KSycoca* m_threadSycocas; }; +thread_local KSycoca* KSycocaSingleton::m_threadSycocas = 0; K_GLOBAL_STATIC(KSycocaSingleton, ksycocaInstance) diff --git a/plasma/private/storage.cpp b/plasma/private/storage.cpp index 94fc3c58..d017a3a8 100644 --- a/plasma/private/storage.cpp +++ b/plasma/private/storage.cpp @@ -28,7 +28,6 @@ #include #include #include -#include //KDE #include diff --git a/solid/solid/devicemanager.cpp b/solid/solid/devicemanager.cpp index 7ebcb1a7..c5da24dc 100644 --- a/solid/solid/devicemanager.cpp +++ b/solid/solid/devicemanager.cpp @@ -32,6 +32,8 @@ Q_GLOBAL_STATIC(Solid::DeviceManagerStorage, globalDeviceStorage) +thread_local Solid::DeviceManagerPrivate* Solid::DeviceManagerStorage::m_storage = 0; + Solid::DeviceManagerPrivate::DeviceManagerPrivate() : m_nullDevice(new DevicePrivate(QString())) { @@ -269,22 +271,30 @@ Solid::DeviceManagerStorage::DeviceManagerStorage() } +Solid::DeviceManagerStorage::~DeviceManagerStorage() +{ + if (m_storage) { + delete m_storage; + m_storage = 0; + } +} + QList Solid::DeviceManagerStorage::managerBackends() { ensureManagerCreated(); - return m_storage.localData()->managerBackends(); + return m_storage->managerBackends(); } Solid::DeviceNotifier *Solid::DeviceManagerStorage::notifier() { ensureManagerCreated(); - return m_storage.localData(); + return m_storage; } void Solid::DeviceManagerStorage::ensureManagerCreated() { - if (!m_storage.hasLocalData()) { - m_storage.setLocalData(new DeviceManagerPrivate()); + if (!m_storage) { + m_storage = new DeviceManagerPrivate(); } } diff --git a/solid/solid/devicemanager_p.h b/solid/solid/devicemanager_p.h index 1f0dde23..b1327801 100644 --- a/solid/solid/devicemanager_p.h +++ b/solid/solid/devicemanager_p.h @@ -28,7 +28,6 @@ #include #include #include -#include namespace Solid { @@ -65,6 +64,7 @@ namespace Solid { public: DeviceManagerStorage(); + ~DeviceManagerStorage(); QList managerBackends(); DeviceNotifier *notifier(); @@ -72,7 +72,7 @@ namespace Solid private: void ensureManagerCreated(); - QThreadStorage m_storage; + static thread_local DeviceManagerPrivate* m_storage; }; } diff --git a/solid/solid/predicateparse.cpp b/solid/solid/predicateparse.cpp index cce88596..8a19c38c 100644 --- a/solid/solid/predicateparse.cpp +++ b/solid/solid/predicateparse.cpp @@ -31,7 +31,6 @@ void PredicateParse_mainParse(const char *_code); #include #include -#include namespace Solid { @@ -51,12 +50,12 @@ struct ParsingData } } -Q_GLOBAL_STATIC(QThreadStorage, s_parsingData) +thread_local Solid::PredicateParse::ParsingData *s_parsingData = 0; Solid::Predicate Solid::Predicate::fromString(const QString &predicate) { Solid::PredicateParse::ParsingData *data = new Solid::PredicateParse::ParsingData(); - s_parsingData()->setLocalData(data); + s_parsingData = data; data->buffer = predicate.toLatin1(); PredicateParse_mainParse(data->buffer.constData()); Predicate result; @@ -65,26 +64,27 @@ Solid::Predicate Solid::Predicate::fromString(const QString &predicate) result = Predicate(*data->result); delete data->result; } - s_parsingData()->setLocalData(0); + delete s_parsingData; + s_parsingData = 0;; return result; } void PredicateParse_setResult(void *result) { - Solid::PredicateParse::ParsingData *data = s_parsingData()->localData(); + Solid::PredicateParse::ParsingData *data = s_parsingData; data->result = (Solid::Predicate *) result; } void PredicateParse_errorDetected(const char* s) { qWarning("ERROR from solid predicate parser: %s", s); - s_parsingData()->localData()->result = 0; + s_parsingData->result = 0; } void PredicateParse_destroy(void *pred) { - Solid::PredicateParse::ParsingData *data = s_parsingData()->localData(); + Solid::PredicateParse::ParsingData *data = s_parsingData; Solid::Predicate *p = (Solid::Predicate *) pred; if (p != data->result) { delete p; @@ -138,7 +138,7 @@ void *PredicateParse_newAnd(void *pred1, void *pred2) { Solid::Predicate *result = new Solid::Predicate(); - Solid::PredicateParse::ParsingData *data = s_parsingData()->localData(); + Solid::PredicateParse::ParsingData *data = s_parsingData; Solid::Predicate *p1 = (Solid::Predicate *)pred1; Solid::Predicate *p2 = (Solid::Predicate *)pred2; @@ -159,7 +159,7 @@ void *PredicateParse_newOr(void *pred1, void *pred2) { Solid::Predicate *result = new Solid::Predicate(); - Solid::PredicateParse::ParsingData *data = s_parsingData()->localData(); + Solid::PredicateParse::ParsingData *data = s_parsingData; Solid::Predicate *p1 = (Solid::Predicate *)pred1; Solid::Predicate *p2 = (Solid::Predicate *)pred2; @@ -239,5 +239,5 @@ void *PredicateParse_appendStringListValue(char *name, void *list) void PredicateLexer_unknownToken(const char* text) { qWarning("ERROR from solid predicate parser: unrecognized token '%s' in predicate '%s'\n", - text, s_parsingData()->localData()->buffer.constData()); + text, s_parsingData->buffer.constData()); }