QBasicMutex is a POD and can be used as a static global object.
in qpicture.cpp factoryLoader is used only once, and under the mutex, so
there is no need for Q_GLOBAL_STATIC for it, it can be a function static
in qhostinfo_unix.cpp the code seemed wrong while compiled with
namespace and QT_NO_GETADDRINFO. I also could get rid of one include
because it was included earlier.
Change-Id: I3c700203c3e067266c20733f4bda8031446dbb86
Reviewed-by: Bradley T. Hughes <bradley.hughes@nokia.com>
};
-Q_GLOBAL_STATIC(QMutex, processManagerGlobalMutex)
-
static QProcessManager *processManagerInstance = 0;
static QProcessManager *processManager()
{
// The constructor of QProcessManager should be called only once
// so we cannot use Q_GLOBAL_STATIC directly for QProcessManager
- QMutex *mutex = processManagerGlobalMutex();
- QMutexLocker locker(mutex);
+ static QBasicMutex processManagerGlobalMutex;
+ QMutexLocker locker(&processManagerGlobalMutex);
if (!processManagerInstance)
QProcessPrivate::initializeProcessManager();
#endif
}
-#ifdef Q_OS_MAC
-Q_GLOBAL_STATIC(QMutex, cfbundleMutex);
-#endif
-
void QProcessPrivate::startProcess()
{
Q_Q(QProcess);
{
// CFBundle is not reentrant, since CFBundleCreate might return a reference
// to a cached bundle object. Protect the bundle calls with a mutex lock.
- QMutexLocker lock(cfbundleMutex());
+ static QBasicMutex cfbundleMutex;
+ QMutexLocker lock(&cfbundleMutex);
QCFType<CFBundleRef> bundle = CFBundleCreate(0, url);
url = CFBundleCopyExecutableURL(bundle);
}
Q_GLOBAL_STATIC(ConfFileCache, unusedCacheFunc)
Q_GLOBAL_STATIC(PathHash, pathHashFunc)
Q_GLOBAL_STATIC(CustomFormatVector, customFormatVectorFunc)
-Q_GLOBAL_STATIC(QMutex, globalMutex)
+
+static QBasicMutex settingsGlobalMutex;
+
static QSettings::Format globalDefaultFormat = QSettings::NativeFormat;
#ifndef Q_OS_WIN
ConfFileCache *unusedCache = unusedCacheFunc();
QConfFile *confFile = 0;
- QMutexLocker locker(globalMutex());
+ QMutexLocker locker(&settingsGlobalMutex);
if (!(confFile = usedHash->value(absPath))) {
if ((confFile = unusedCache->take(absPath)))
void QConfFile::clearCache()
{
- QMutexLocker locker(globalMutex());
+ QMutexLocker locker(&settingsGlobalMutex);
unusedCacheFunc()->clear();
}
#endif
if (format > QSettings::IniFormat) {
- QMutexLocker locker(globalMutex());
+ QMutexLocker locker(&settingsGlobalMutex);
const CustomFormatVector *customFormatVector = customFormatVectorFunc();
int i = (int)format - (int)QSettings::CustomFormat1;
Q_ASSERT((int)QSettings::NativeFormat == 0);
Q_ASSERT((int)QSettings::IniFormat == 1);
- QMutexLocker locker(globalMutex());
+ QMutexLocker locker(&settingsGlobalMutex);
PathHash *pathHash = pathHashFunc();
if (pathHash->isEmpty())
initDefaultPaths(&locker);
QConfFileSettingsPrivate::~QConfFileSettingsPrivate()
{
- QMutexLocker locker(globalMutex());
+ QMutexLocker locker(&settingsGlobalMutex);
ConfFileHash *usedHash = usedHashFunc();
ConfFileCache *unusedCache = unusedCacheFunc();
*/
void QSettings::setPath(Format format, Scope scope, const QString &path)
{
- QMutexLocker locker(globalMutex());
+ QMutexLocker locker(&settingsGlobalMutex);
PathHash *pathHash = pathHashFunc();
if (pathHash->isEmpty())
initDefaultPaths(&locker);
Q_ASSERT(caseSensitivity == Qt::CaseSensitive);
#endif
- QMutexLocker locker(globalMutex());
+ QMutexLocker locker(&settingsGlobalMutex);
CustomFormatVector *customFormatVector = customFormatVectorFunc();
int index = customFormatVector->size();
if (index == 16) // the QSettings::Format enum has room for 16 custom formats
# define QT_NO_DEBUG_PLUGIN_CHECK
#endif
-Q_GLOBAL_STATIC(QMutex, qt_library_mutex)
+static QBasicMutex qt_library_mutex;
/*!
\class QLibrary
QLibraryPrivate *QLibraryPrivate::findOrCreate(const QString &fileName, const QString &version)
{
- QMutexLocker locker(qt_library_mutex());
+ QMutexLocker locker(&qt_library_mutex);
if (QLibraryPrivate *lib = libraryMap()->value(fileName)) {
lib->libraryRefCount.ref();
return lib;
void QLibraryPrivate::release()
{
- QMutexLocker locker(qt_library_mutex());
+ QMutexLocker locker(&qt_library_mutex);
if (!libraryRefCount.deref())
delete this;
}
# define DEBUG_MSG if(false)qDebug
#endif
-Q_GLOBAL_STATIC(QMutex, mutex)
+static QBasicMutex destructorsMutex;
typedef QVector<void (*)(void *)> DestructorMap;
Q_GLOBAL_STATIC(DestructorMap, destructors)
QThreadStorageData::QThreadStorageData(void (*func)(void *))
{
- QMutexLocker locker(mutex());
+ QMutexLocker locker(&destructorsMutex);
DestructorMap *destr = destructors();
if (!destr) {
/*
QThreadStorageData::~QThreadStorageData()
{
DEBUG_MSG("QThreadStorageData: Released id %d", id);
- QMutexLocker locker(mutex());
+ QMutexLocker locker(&destructorsMutex);
if (destructors())
(*destructors())[id] = 0;
}
value,
data->thread);
- QMutexLocker locker(mutex());
+ QMutexLocker locker(&destructorsMutex);
DestructorMap *destr = destructors();
void (*destructor)(void *) = destr ? destr->value(id) : 0;
locker.unlock();
void QThreadStorageData::finish(void **p)
{
QVector<void *> *tls = reinterpret_cast<QVector<void *> *>(p);
- if (!tls || tls->isEmpty() || !mutex())
+ if (!tls || tls->isEmpty() || !destructors())
return; // nothing to do
DEBUG_MSG("QThreadStorageData: Destroying storage for thread %p", QThread::currentThread());
continue;
}
- QMutexLocker locker(mutex());
+ QMutexLocker locker(&destructorsMutex);
void (*destructor)(void *) = destructors()->value(i);
locker.unlock();
typedef QCache<QRegExpEngineKey, QRegExpEngine> EngineCache;
Q_GLOBAL_STATIC(EngineCache, globalEngineCache)
-Q_GLOBAL_STATIC(QMutex, mutex)
+static QBasicMutex globalEngineCacheMutex;
#endif // QT_NO_REGEXP_OPTIM
static void derefEngine(QRegExpEngine *eng, const QRegExpEngineKey &key)
if (!eng->ref.deref()) {
#if !defined(QT_NO_REGEXP_OPTIM)
if (globalEngineCache()) {
- QMutexLocker locker(mutex());
+ QMutexLocker locker(&globalEngineCacheMutex);
QT_TRY {
globalEngineCache()->insert(key, eng, 4 + key.pattern.length() / 4);
} QT_CATCH(const std::bad_alloc &) {
bool initMatchState = !priv->eng;
#if !defined(QT_NO_REGEXP_OPTIM)
if (!priv->eng && globalEngineCache()) {
- QMutexLocker locker(mutex());
+ QMutexLocker locker(&globalEngineCacheMutex);
priv->eng = globalEngineCache()->take(priv->engineKey);
if (priv->eng != 0)
priv->eng->ref.ref();
typedef QList<QPictureHandler *> QPHList;
Q_GLOBAL_STATIC(QPHList, pictureHandlers)
-#ifndef QT_NO_LIBRARY
-Q_GLOBAL_STATIC(QMutex, mutex)
-Q_GLOBAL_STATIC_WITH_ARGS(QFactoryLoader, factoryLoader,
- (QPictureFormatInterface_iid,
- QLatin1String("/pictureformats")))
-#endif
void qt_init_picture_plugins()
{
#ifndef QT_NO_LIBRARY
- QMutexLocker locker(mutex());
- QFactoryLoader *loader = factoryLoader();
- QStringList keys = loader->keys();
+ static QBasicMutex mutex;
+ QMutexLocker locker(&mutex);
+ static QFactoryLoader loader(QPictureFormatInterface_iid,
+ QStringLiteral("/pictureformats"));
+ QStringList keys = loader.keys();
for (int i = 0; i < keys.count(); ++i)
- if (QPictureFormatInterface *format = qobject_cast<QPictureFormatInterface*>(loader->instance(keys.at(i))))
+ if (QPictureFormatInterface *format = qobject_cast<QPictureFormatInterface*>(loader.instance(keys.at(i))))
format->installIOHandler(keys.at(i));
#endif
}
QWindowList QGuiApplicationPrivate::window_list;
QWindow *QGuiApplicationPrivate::focus_window = 0;
-Q_GLOBAL_STATIC(QMutex, applicationFontMutex)
+static QBasicMutex applicationFontMutex;
QFont *QGuiApplicationPrivate::app_font = 0;
extern void qRegisterGuiVariant();
QFont QGuiApplication::font()
{
- QMutexLocker locker(applicationFontMutex());
+ QMutexLocker locker(&applicationFontMutex);
if (!QGuiApplicationPrivate::app_font)
QGuiApplicationPrivate::app_font =
new QFont(QGuiApplicationPrivate::platformIntegration()->fontDatabase()->defaultFont());
void QGuiApplication::setFont(const QFont &font)
{
- QMutexLocker locker(applicationFontMutex());
+ QMutexLocker locker(&applicationFontMutex);
if (!QGuiApplicationPrivate::app_font)
QGuiApplicationPrivate::app_font = new QFont(font);
else
typedef QList<QTouchDevice *> TouchDevices;
Q_GLOBAL_STATIC(TouchDevices, deviceList)
-Q_GLOBAL_STATIC(QMutex, devicesMutex)
+static QBasicMutex devicesMutex;
static void cleanupDevicesList()
{
- QMutexLocker lock(devicesMutex());
+ QMutexLocker lock(&devicesMutex);
qDeleteAll(*deviceList());
deviceList()->clear();
}
*/
QList<const QTouchDevice *> QTouchDevice::devices()
{
- QMutexLocker lock(devicesMutex());
+ QMutexLocker lock(&devicesMutex);
QList<QTouchDevice *> *devList = deviceList();
QList<const QTouchDevice *> constDevList;
for (int i = 0, count = devList->count(); i != count; ++i)
*/
bool QTouchDevicePrivate::isRegistered(QTouchDevice *dev)
{
- QMutexLocker lock(devicesMutex());
+ QMutexLocker lock(&devicesMutex);
return deviceList()->contains(dev);
}
*/
void QTouchDevicePrivate::registerDevice(QTouchDevice *dev)
{
- QMutexLocker lock(devicesMutex());
+ QMutexLocker lock(&devicesMutex);
if (deviceList()->isEmpty())
qAddPostRoutine(cleanupDevicesList);
deviceList()->append(dev);
QT_BEGIN_NAMESPACE
static QBasicAtomicPointer<QNetworkConfigurationManagerPrivate> connManager_ptr;
-Q_GLOBAL_STATIC(QMutex, connManager_mutex)
static void connManager_cleanup()
{
{
QNetworkConfigurationManagerPrivate *ptr = connManager_ptr.loadAcquire();
if (!ptr) {
- QMutexLocker locker(connManager_mutex());
+ static QBasicMutex connManager_mutex;
+ QMutexLocker locker(&connManager_mutex);
if (!(ptr = connManager_ptr.loadAcquire())) {
ptr = new QNetworkConfigurationManagerPrivate;
#endif
#if defined (QT_NO_GETADDRINFO)
-#include <qmutex.h>
-QT_BEGIN_NAMESPACE
-Q_GLOBAL_STATIC(QMutex, getHostByNameMutex)
-QT_END_NAMESPACE
+static QBasicMutex getHostByNameMutex;
#endif
QT_BEGIN_NAMESPACE
// reentrant on all platforms. For now this is okay since we only
// use one QHostInfoAgent, but if more agents are introduced, locking
// must be provided.
- QMutexLocker locker(::getHostByNameMutex());
+ QMutexLocker locker(&getHostByNameMutex);
hostent *result = gethostbyname(aceHostname.constData());
if (result) {
if (result->h_addrtype == AF_INET) {
#if defined(QT_NO_GETADDRINFO)
// We have to call res_init to be sure that _res was initialized
// So, for systems without getaddrinfo (which is thread-safe), we lock the mutex too
- QMutexLocker locker(::getHostByNameMutex());
+ QMutexLocker locker(&getHostByNameMutex);
#endif
local_res_init();
QString domainName = QUrl::fromAce(local_res->defdname);
#endif
}
-#if defined(Q_OS_WINCE)
-#include <qmutex.h>
-Q_GLOBAL_STATIC(QMutex, qPrivCEMutex)
-#endif
-
QHostInfo QHostInfoAgent::fromName(const QString &hostName)
{
#if defined(Q_OS_WINCE)
- QMutexLocker locker(qPrivCEMutex());
+ static QBasicMutex qPrivCEMutex;
+ QMutexLocker locker(&qPrivCEMutex);
#endif
QWindowsSockInit winSock;