diff options
author | Tim Jenssen <tim.jenssen@digia.com> | 2014-08-05 14:00:21 +0200 |
---|---|---|
committer | Thomas Hartmann <Thomas.Hartmann@digia.com> | 2014-08-05 14:27:02 +0200 |
commit | 0370fa214a53cf03d3c3c7216e4cff57a69dd8dd (patch) | |
tree | 9de54468ba495326a469eb741cdd00468a2d0ff5 /share | |
parent | b2ac3fd90ccfc21cf4c5bce353d8e08208961eeb (diff) |
QmlDesigner: Use Q_GLOBAL_STATIC_WITH_ARGS for the global hash
To be sure that the shared memories are removed at process exit.
And fix that createSharedMemory reuse possible already existing shared
memories now. ("take" -> "[]")
Change-Id: Idcc99ba42b862b862d5403ecf3b781a27fdf757f
Reviewed-by: Thomas Hartmann <Thomas.Hartmann@digia.com>
Diffstat (limited to 'share')
-rw-r--r-- | share/qtcreator/qml/qmlpuppet/commands/valueschangedcommand.cpp | 10 | ||||
-rw-r--r-- | share/qtcreator/qml/qmlpuppet/container/imagecontainer.cpp | 12 |
2 files changed, 14 insertions, 8 deletions
diff --git a/share/qtcreator/qml/qmlpuppet/commands/valueschangedcommand.cpp b/share/qtcreator/qml/qmlpuppet/commands/valueschangedcommand.cpp index a995ab36fb..c6383cd0ae 100644 --- a/share/qtcreator/qml/qmlpuppet/commands/valueschangedcommand.cpp +++ b/share/qtcreator/qml/qmlpuppet/commands/valueschangedcommand.cpp @@ -37,7 +37,9 @@ namespace QmlDesigner { -static QCache<qint32, SharedMemory> globalSharedMemoryCache(10000); +// using cache as a container which deletes sharedmemory pointers at process exit +typedef QCache<qint32, SharedMemory> GlobalSharedMemoryContainer; +Q_GLOBAL_STATIC_WITH_ARGS(GlobalSharedMemoryContainer, globalSharedMemoryContainer, (10000)) ValuesChangedCommand::ValuesChangedCommand() : m_keyNumber(0) @@ -63,7 +65,7 @@ quint32 ValuesChangedCommand::keyNumber() const void ValuesChangedCommand::removeSharedMemorys(const QVector<qint32> &keyNumberVector) { foreach (qint32 keyNumber, keyNumberVector) { - SharedMemory *sharedMemory = globalSharedMemoryCache.take(keyNumber); + SharedMemory *sharedMemory = globalSharedMemoryContainer()->take(keyNumber); delete sharedMemory; } } @@ -82,8 +84,10 @@ static SharedMemory *createSharedMemory(qint32 key, int byteCount) bool sharedMemoryIsCreated = sharedMemory->create(byteCount); if (sharedMemoryIsCreated) { - globalSharedMemoryCache.insert(key, sharedMemory); + globalSharedMemoryContainer()->insert(key, sharedMemory); return sharedMemory; + } else { + delete sharedMemory; } return 0; diff --git a/share/qtcreator/qml/qmlpuppet/container/imagecontainer.cpp b/share/qtcreator/qml/qmlpuppet/container/imagecontainer.cpp index 031602e75c..87505ca458 100644 --- a/share/qtcreator/qml/qmlpuppet/container/imagecontainer.cpp +++ b/share/qtcreator/qml/qmlpuppet/container/imagecontainer.cpp @@ -42,7 +42,9 @@ namespace QmlDesigner { -static QCache<qint32, SharedMemory> globalSharedMemoryCache(10000); +// using cache as a container which deletes sharedmemory pointers at process exit +typedef QCache<qint32, SharedMemory> GlobalSharedMemoryContainer; +Q_GLOBAL_STATIC_WITH_ARGS(GlobalSharedMemoryContainer, globalSharedMemoryContainer, (10000)) ImageContainer::ImageContainer() : m_instanceId(-1), @@ -82,7 +84,7 @@ void ImageContainer::setImage(const QImage &image) void ImageContainer::removeSharedMemorys(const QVector<qint32> &keyNumberVector) { foreach (qint32 keyNumber, keyNumberVector) { - SharedMemory *sharedMemory = globalSharedMemoryCache.take(keyNumber); + SharedMemory *sharedMemory = globalSharedMemoryContainer()->take(keyNumber); delete sharedMemory; } } @@ -91,13 +93,13 @@ static const QLatin1String imageKeyTemplateString("Image-%1"); static SharedMemory *createSharedMemory(qint32 key, int byteCount) { - SharedMemory *sharedMemory = globalSharedMemoryCache.take(key); + SharedMemory *sharedMemory = (*globalSharedMemoryContainer())[key]; if (sharedMemory == 0) { sharedMemory = new SharedMemory(QString(imageKeyTemplateString).arg(key)); bool sharedMemoryIsCreated = sharedMemory->create(byteCount); if (sharedMemoryIsCreated) { - globalSharedMemoryCache.insert(key, sharedMemory); + globalSharedMemoryContainer()->insert(key, sharedMemory); } else { delete sharedMemory; sharedMemory = 0; @@ -118,7 +120,7 @@ static SharedMemory *createSharedMemory(qint32 key, int byteCount) } if (!sharedMemory->isAttached()) { - globalSharedMemoryCache.remove(key); + globalSharedMemoryContainer()->remove(key); delete sharedMemory; sharedMemory = 0; } |