diff options
author | commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2013-12-12 14:00:12 +0000 |
---|---|---|
committer | commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2013-12-12 14:00:12 +0000 |
commit | 469a9732c5e75c70e73f51a5e4e0657b0129fdc7 (patch) | |
tree | 566c534c6269c6f15f6eac022c00db376b5f39e3 | |
parent | aa7f218c17bfbb22490f9983478aad11a9725349 (diff) |
Make leak counters thread-safe and turn them on by default for Debug
Make leak counters implemented with SK_DECLARE_INST_COUNT thread-safe.
Enable the leak counting for Debug builds.
Protect the instance counter initialization step (initStep) by
using SkOnce.
Makes SkOnce.h part of the public API, since SkInstCnt is public.
Protect the per-class child list shared variable with a per-class mutex.
Changes the behavior in the way that if the child list has been
"cleaned up", it will still try to create subsequent child lists.
BUG=skia:1219
R=robertphillips@google.com, mtklein@google.com, bungeman@gmail.com, bsalomon@google.com, bungeman@google.com
Author: kkinnunen@nvidia.com
Review URL: https://codereview.chromium.org/99483003
git-svn-id: http://skia.googlecode.com/svn/trunk@12635 2bbb7eff-a529-9590-31e7-b0007b416f81
-rw-r--r-- | gm/colormatrix.cpp | 6 | ||||
-rw-r--r-- | gm/convexpaths.cpp | 6 | ||||
-rw-r--r-- | include/core/SkInstCnt.h | 28 | ||||
-rw-r--r-- | include/core/SkOnce.h (renamed from src/core/SkOnce.h) | 0 | ||||
-rw-r--r-- | include/core/SkPostConfig.h | 4 |
5 files changed, 26 insertions, 18 deletions
diff --git a/gm/colormatrix.cpp b/gm/colormatrix.cpp index 9ab6563040..2f98693da2 100644 --- a/gm/colormatrix.cpp +++ b/gm/colormatrix.cpp @@ -12,9 +12,9 @@ #define WIDTH 500 #define HEIGHT 500 -class SkOnce { +class SkDoOnce { public: - SkOnce() : fOnce(false) {}; + SkDoOnce() : fOnce(false) {}; bool once() const { if (fOnce) { @@ -39,7 +39,7 @@ static void setArray(SkPaint* paint, const SkScalar array[]) { namespace skiagm { class ColorMatrixGM : public GM { - SkOnce fOnce; + SkDoOnce fOnce; void init() { if (fOnce.once()) { fSolidBitmap = this->createSolidBitmap(64, 64); diff --git a/gm/convexpaths.cpp b/gm/convexpaths.cpp index 8eb4cba49d..91afbfeba3 100644 --- a/gm/convexpaths.cpp +++ b/gm/convexpaths.cpp @@ -9,9 +9,9 @@ #include "SkRandom.h" #include "SkTArray.h" -class SkOnce : SkNoncopyable { +class SkDoOnce : SkNoncopyable { public: - SkOnce() { fDidOnce = false; } + SkDoOnce() { fDidOnce = false; } bool needToDo() const { return !fDidOnce; } bool alreadyDone() const { return fDidOnce; } @@ -27,7 +27,7 @@ private: namespace skiagm { class ConvexPathsGM : public GM { - SkOnce fOnce; + SkDoOnce fOnce; public: ConvexPathsGM() { this->setBGColor(0xFF000000); diff --git a/include/core/SkInstCnt.h b/include/core/SkInstCnt.h index e38c42d917..db0ec31274 100644 --- a/include/core/SkInstCnt.h +++ b/include/core/SkInstCnt.h @@ -20,6 +20,7 @@ #include "SkTypes.h" #if SK_ENABLE_INST_COUNT +#include "SkOnce.h" #include "SkTArray.h" #include "SkThread_platform.h" @@ -40,15 +41,15 @@ extern bool gPrintInstCount; public: \ typedef int (*PFCheckInstCnt)(int level, bool cleanUp); \ SkInstanceCountHelper() { \ - static bool gInited; \ - if (!gInited) { \ - initStep \ - GetChildren() = new SkTArray<PFCheckInstCnt>; \ - gInited = true; \ - } \ + SK_DECLARE_STATIC_ONCE(once); \ + SkOnce(&once, init, 0); \ sk_atomic_inc(GetInstanceCountPtr()); \ } \ \ + static void init(int) { \ + initStep \ + } \ + \ SkInstanceCountHelper(const SkInstanceCountHelper&) { \ sk_atomic_inc(GetInstanceCountPtr()); \ } \ @@ -67,6 +68,11 @@ extern bool gPrintInstCount; return gChildren; \ } \ \ + static SkBaseMutex& GetChildrenMutex() { \ + SK_DECLARE_STATIC_MUTEX(childrenMutex); \ + return childrenMutex; \ + } \ + \ } fInstanceCountHelper; \ \ static int32_t GetInstanceCount() { \ @@ -86,7 +92,7 @@ extern bool gPrintInstCount; if (NULL == SkInstanceCountHelper::GetChildren()) { \ return GetInstanceCount(); \ } \ - SkTArray<int (*)(int, bool)>* children = \ + SkTArray<typename SkInstanceCountHelper::PFCheckInstCnt>* children = \ SkInstanceCountHelper::GetChildren(); \ int childCount = children->count(); \ int count = GetInstanceCount(); \ @@ -105,8 +111,12 @@ extern bool gPrintInstCount; } \ \ static void AddInstChild(int (*childCheckInstCnt)(int, bool)) { \ - if (CheckInstanceCount != childCheckInstCnt && \ - NULL != SkInstanceCountHelper::GetChildren()) { \ + if (CheckInstanceCount != childCheckInstCnt) { \ + SkAutoMutexAcquire ama(SkInstanceCountHelper::GetChildrenMutex()); \ + if (NULL == SkInstanceCountHelper::GetChildren()) { \ + SkInstanceCountHelper::GetChildren() = \ + new SkTArray<typename SkInstanceCountHelper::PFCheckInstCnt>; \ + } \ SkInstanceCountHelper::GetChildren()->push_back(childCheckInstCnt); \ } \ } diff --git a/src/core/SkOnce.h b/include/core/SkOnce.h index 89de112442..89de112442 100644 --- a/src/core/SkOnce.h +++ b/include/core/SkOnce.h diff --git a/include/core/SkPostConfig.h b/include/core/SkPostConfig.h index efb119fe4b..d0d7d26e58 100644 --- a/include/core/SkPostConfig.h +++ b/include/core/SkPostConfig.h @@ -126,12 +126,10 @@ * SK_ENABLE_INST_COUNT controlls printing how many reference counted objects * are still held on exit. * Defaults to 1 in DEBUG and 0 in RELEASE. - * FIXME: currently always 0, since it fails if multiple threads run at once - * (see skbug.com/1219 ). */ #ifndef SK_ENABLE_INST_COUNT # ifdef SK_DEBUG -# define SK_ENABLE_INST_COUNT 0 +# define SK_ENABLE_INST_COUNT 1 # else # define SK_ENABLE_INST_COUNT 0 # endif |