summaryrefslogtreecommitdiffstats
path: root/src/gui/painting/qbrush.cpp
diff options
context:
space:
mode:
authorThiago Macieira <thiago@kde.org>2011-07-20 16:06:58 +0200
committerQt by Nokia <qt-info@nokia.com>2011-07-21 08:54:00 +0200
commit6d3c0643020aaf002b985a16a66f3c289daea4f0 (patch)
tree875c76adf08242cd8ed4dd7678509b3d085dc51e /src/gui/painting/qbrush.cpp
parentde587d736a1fd661c3fddeebefce02e436a2c7a5 (diff)
Get rid of the evilness of Q_GLOBAL_STATIC_WITH_INITIALIZER
That macro is a nightmare. It leads to writing code that is thread-unsafe or other problems. So rewrite the code that used this macro to use special-purpose classes with constructors. This commit does not introduce new errors. The FIXME in qicon.cpp (qtIconCache()) was a condition already present. It does fix the race conditions that were present in qbrush.cpp nullBrushInstance() and qfontengine.cpp qt_grayPalette(). Specialising QGlobalStatic is also evil. Change-Id: I039311f6a5ac9ea4ad7b310b870a2adf888da7e5 Merge-request: 10 Reviewed-by: Olivier Goffart <olivier.goffart@nokia.com> Reviewed-on: http://codereview.qt.nokia.com/1895 Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Diffstat (limited to 'src/gui/painting/qbrush.cpp')
-rw-r--r--src/gui/painting/qbrush.cpp46
1 files changed, 20 insertions, 26 deletions
diff --git a/src/gui/painting/qbrush.cpp b/src/gui/painting/qbrush.cpp
index 8599cb1d75..97ea4dbc15 100644
--- a/src/gui/painting/qbrush.cpp
+++ b/src/gui/painting/qbrush.cpp
@@ -112,6 +112,7 @@ QPixmap qt_pixmapForBrush(int brushStyle, bool invert)
return pm;
}
+static void qt_cleanup_brush_pattern_image_cache();
class QBrushPatternImageCache
{
public:
@@ -123,6 +124,7 @@ public:
void init()
{
+ qAddPostRoutine(qt_cleanup_brush_pattern_image_cache);
for (int style = Qt::Dense1Pattern; style <= Qt::DiagCrossPattern; ++style) {
int i = style - Qt::Dense1Pattern;
m_images[i][0] = QImage(qt_patternForBrush(style, 0), 8, 8, 1, QImage::Format_MonoLSB);
@@ -153,11 +155,7 @@ private:
bool m_initialized;
};
-static void qt_cleanup_brush_pattern_image_cache();
-Q_GLOBAL_STATIC_WITH_INITIALIZER(QBrushPatternImageCache, qt_brushPatternImageCache,
- {
- qAddPostRoutine(qt_cleanup_brush_pattern_image_cache);
- })
+Q_GLOBAL_STATIC(QBrushPatternImageCache, qt_brushPatternImageCache)
static void qt_cleanup_brush_pattern_image_cache()
{
@@ -339,33 +337,29 @@ struct QBrushDataPointerDeleter
\sa Qt::BrushStyle, QPainter, QColor
*/
-#ifndef QT_NO_THREAD
-// Special deleter that only deletes if the ref-count goes to zero
-template <>
-class QGlobalStaticDeleter<QBrushData>
+class QNullBrushData
{
public:
- QGlobalStatic<QBrushData> &globalStatic;
- QGlobalStaticDeleter(QGlobalStatic<QBrushData> &_globalStatic)
- : globalStatic(_globalStatic)
- { }
-
- inline ~QGlobalStaticDeleter()
+ QBrushData *brush;
+ QNullBrushData() : brush(new QBrushData)
+ {
+ brush->ref = 1;
+ brush->style = Qt::BrushStyle(0);
+ brush->color = Qt::black;
+ }
+ ~QNullBrushData()
{
- if (!globalStatic.pointer->ref.deref())
- delete globalStatic.pointer;
- globalStatic.pointer = 0;
- globalStatic.destroyed = true;
+ if (!brush->ref.deref())
+ delete brush;
+ brush = 0;
}
};
-#endif
-Q_GLOBAL_STATIC_WITH_INITIALIZER(QBrushData, nullBrushInstance,
- {
- x->ref = 1;
- x->style = Qt::BrushStyle(0);
- x->color = Qt::black;
- })
+Q_GLOBAL_STATIC(QNullBrushData, nullBrushInstance_holder)
+static QBrushData *nullBrushInstance()
+{
+ return nullBrushInstance_holder()->brush;
+}
static bool qbrush_check_type(Qt::BrushStyle style) {
switch (style) {