Commit 0370fa21 authored by Tim Jenssen's avatar Tim Jenssen Committed by Thomas Hartmann

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: default avatarThomas Hartmann <Thomas.Hartmann@digia.com>
parent b2ac3fd9
......@@ -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;
......
......@@ -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;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment