forked from qt-creator/qt-creator
Environment: Make systemEnvironment() thread safe
Fixes: QTCREATORBUG-26805 Change-Id: I839995699ffd25579a6a77405331a9802edaf7f1 Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
@@ -4,18 +4,18 @@
|
|||||||
#include "environment.h"
|
#include "environment.h"
|
||||||
|
|
||||||
#include "algorithm.h"
|
#include "algorithm.h"
|
||||||
#include "fileutils.h"
|
|
||||||
#include "qtcassert.h"
|
#include "qtcassert.h"
|
||||||
|
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QProcessEnvironment>
|
#include <QProcessEnvironment>
|
||||||
|
#include <QReadWriteLock>
|
||||||
#include <QSet>
|
#include <QSet>
|
||||||
|
|
||||||
namespace Utils {
|
namespace Utils {
|
||||||
|
|
||||||
|
static QReadWriteLock s_envMutex;
|
||||||
Q_GLOBAL_STATIC_WITH_ARGS(Environment, staticSystemEnvironment,
|
Q_GLOBAL_STATIC_WITH_ARGS(Environment, staticSystemEnvironment,
|
||||||
(QProcessEnvironment::systemEnvironment().toStringList()))
|
(QProcessEnvironment::systemEnvironment().toStringList()))
|
||||||
|
|
||||||
Q_GLOBAL_STATIC(QVector<EnvironmentProvider>, environmentProviders)
|
Q_GLOBAL_STATIC(QVector<EnvironmentProvider>, environmentProviders)
|
||||||
|
|
||||||
NameValueItems Environment::diff(const Environment &other, bool checkAppendPrepend) const
|
NameValueItems Environment::diff(const Environment &other, bool checkAppendPrepend) const
|
||||||
@@ -120,6 +120,7 @@ void Environment::prependOrSetLibrarySearchPaths(const FilePaths &values)
|
|||||||
|
|
||||||
Environment Environment::systemEnvironment()
|
Environment Environment::systemEnvironment()
|
||||||
{
|
{
|
||||||
|
QReadLocker lock(&s_envMutex);
|
||||||
return *staticSystemEnvironment();
|
return *staticSystemEnvironment();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -296,11 +297,13 @@ FilePaths Environment::pathListValue(const QString &varName) const
|
|||||||
|
|
||||||
void Environment::modifySystemEnvironment(const EnvironmentItems &list)
|
void Environment::modifySystemEnvironment(const EnvironmentItems &list)
|
||||||
{
|
{
|
||||||
|
QWriteLocker lock(&s_envMutex);
|
||||||
staticSystemEnvironment->modify(list);
|
staticSystemEnvironment->modify(list);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Environment::setSystemEnvironment(const Environment &environment)
|
void Environment::setSystemEnvironment(const Environment &environment)
|
||||||
{
|
{
|
||||||
|
QWriteLocker lock(&s_envMutex);
|
||||||
*staticSystemEnvironment = environment;
|
*staticSystemEnvironment = environment;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user