mirror of
https://bitbucket.org/smil3y/kdelibs.git
synced 2025-02-23 18:32:49 +00:00
generic: replace QThreadStorage with thread_local where possible
Signed-off-by: Ivailo Monev <xakepa10@laimg.moc>
This commit is contained in:
parent
4cc545f43b
commit
896476b53a
6 changed files with 84 additions and 48 deletions
|
@ -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<QString*> m_indentString;
|
||||
QThreadStorage<KSyslogDebugStream*> syslogwriter;
|
||||
QThreadStorage<KFileDebugStream*> filewriter;
|
||||
QThreadStorage<KMessageBoxDebugStream*> 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<QString*> & 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<QString*> & 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) {
|
||||
|
|
|
@ -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<KSycoca*> m_threadSycocas;
|
||||
static thread_local KSycoca* m_threadSycocas;
|
||||
};
|
||||
thread_local KSycoca* KSycocaSingleton::m_threadSycocas = 0;
|
||||
|
||||
K_GLOBAL_STATIC(KSycocaSingleton, ksycocaInstance)
|
||||
|
||||
|
|
|
@ -28,7 +28,6 @@
|
|||
#include <QSqlField>
|
||||
#include <QSqlQuery>
|
||||
#include <QSqlRecord>
|
||||
#include <QThreadStorage>
|
||||
|
||||
//KDE
|
||||
#include <kdebug.h>
|
||||
|
|
|
@ -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<QObject*> 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();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -28,7 +28,6 @@
|
|||
#include <QtCore/QMap>
|
||||
#include <QtCore/qsharedpointer.h>
|
||||
#include <QtCore/QSharedData>
|
||||
#include <QtCore/QThreadStorage>
|
||||
|
||||
namespace Solid
|
||||
{
|
||||
|
@ -65,6 +64,7 @@ namespace Solid
|
|||
{
|
||||
public:
|
||||
DeviceManagerStorage();
|
||||
~DeviceManagerStorage();
|
||||
|
||||
QList<QObject*> managerBackends();
|
||||
DeviceNotifier *notifier();
|
||||
|
@ -72,7 +72,7 @@ namespace Solid
|
|||
private:
|
||||
void ensureManagerCreated();
|
||||
|
||||
QThreadStorage<DeviceManagerPrivate*> m_storage;
|
||||
static thread_local DeviceManagerPrivate* m_storage;
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -31,7 +31,6 @@ void PredicateParse_mainParse(const char *_code);
|
|||
#include <stdlib.h>
|
||||
|
||||
#include <QtCore/QStringList>
|
||||
#include <QtCore/QThreadStorage>
|
||||
|
||||
namespace Solid
|
||||
{
|
||||
|
@ -51,12 +50,12 @@ struct ParsingData
|
|||
}
|
||||
}
|
||||
|
||||
Q_GLOBAL_STATIC(QThreadStorage<Solid::PredicateParse::ParsingData *>, 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());
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue