From: Milian Wolff Date: Mon, 13 Feb 2017 23:31:08 +0000 (+0100) Subject: Ensure the brushes are properly initialized in a thread-safe way X-Git-Tag: submit/tizen/20180620.112952^2~109^2~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=843271e43dfa04233c00146fd53414f73c2b3b16;p=sdk%2Ftools%2Fheaptrack.git Ensure the brushes are properly initialized in a thread-safe way Fixes a crash under some circumstances, when multiple graphs are build in parallel - something that needs to be investigated separately. --- diff --git a/src/analyze/gui/flamegraph.cpp b/src/analyze/gui/flamegraph.cpp index 67b32cb..8f5f526 100644 --- a/src/analyze/gui/flamegraph.cpp +++ b/src/analyze/gui/flamegraph.cpp @@ -218,12 +218,13 @@ QBrush brush() // intern the brushes, to reuse them across items which can be thousands // otherwise we'd end up with dozens of allocations and higher memory // consumption - static QVector brushes; - if (brushes.isEmpty()) { + static const QVector brushes = []() -> QVector { + QVector brushes; std::generate_n(std::back_inserter(brushes), 100, []() { return QColor(0, 190 + 50 * qreal(rand()) / RAND_MAX, 210 * qreal(rand()) / RAND_MAX, 125); }); - } + return brushes; + }(); return brushes.at(rand() % brushes.size()); }