Reverting r12635 (Make leak counters thread-safe - https://codereview.chromium.org...
authorrobertphillips@google.com <robertphillips@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>
Thu, 12 Dec 2013 14:24:20 +0000 (14:24 +0000)
committerrobertphillips@google.com <robertphillips@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>
Thu, 12 Dec 2013 14:24:20 +0000 (14:24 +0000)
git-svn-id: http://skia.googlecode.com/svn/trunk@12637 2bbb7eff-a529-9590-31e7-b0007b416f81

gm/colormatrix.cpp
gm/convexpaths.cpp
include/core/SkInstCnt.h
include/core/SkPostConfig.h
src/core/SkOnce.h [moved from include/core/SkOnce.h with 100% similarity]

index 2f98693..9ab6563 100644 (file)
@@ -12,9 +12,9 @@
 #define WIDTH 500
 #define HEIGHT 500
 
-class SkDoOnce {
+class SkOnce {
 public:
-    SkDoOnce() : fOnce(false) {};
+    SkOnce() : 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 {
-    SkDoOnce fOnce;
+    SkOnce fOnce;
     void init() {
         if (fOnce.once()) {
             fSolidBitmap = this->createSolidBitmap(64, 64);
index 91afbfe..8eb4cba 100644 (file)
@@ -9,9 +9,9 @@
 #include "SkRandom.h"
 #include "SkTArray.h"
 
-class SkDoOnce : SkNoncopyable {
+class SkOnce : SkNoncopyable {
 public:
-    SkDoOnce() { fDidOnce = false; }
+    SkOnce() { fDidOnce = false; }
 
     bool needToDo() const { return !fDidOnce; }
     bool alreadyDone() const { return fDidOnce; }
@@ -27,7 +27,7 @@ private:
 namespace skiagm {
 
 class ConvexPathsGM : public GM {
-    SkDoOnce fOnce;
+    SkOnce fOnce;
 public:
     ConvexPathsGM() {
         this->setBGColor(0xFF000000);
index db0ec31..e38c42d 100644 (file)
@@ -20,7 +20,6 @@
 #include "SkTypes.h"
 
 #if SK_ENABLE_INST_COUNT
-#include "SkOnce.h"
 #include "SkTArray.h"
 #include "SkThread_platform.h"
 
@@ -41,15 +40,15 @@ extern bool gPrintInstCount;
     public:                                                                 \
         typedef int (*PFCheckInstCnt)(int level, bool cleanUp);             \
         SkInstanceCountHelper() {                                           \
-            SK_DECLARE_STATIC_ONCE(once);                                   \
-            SkOnce(&once, init, 0);                                         \
+            static bool gInited;                                            \
+            if (!gInited) {                                                 \
+                initStep                                                    \
+                GetChildren() = new SkTArray<PFCheckInstCnt>;               \
+                gInited = true;                                             \
+            }                                                               \
             sk_atomic_inc(GetInstanceCountPtr());                           \
         }                                                                   \
                                                                             \
-        static void init(int) {                                             \
-            initStep                                                        \
-        }                                                                   \
-                                                                            \
         SkInstanceCountHelper(const SkInstanceCountHelper&) {               \
             sk_atomic_inc(GetInstanceCountPtr());                           \
         }                                                                   \
@@ -68,11 +67,6 @@ extern bool gPrintInstCount;
             return gChildren;                                               \
         }                                                                   \
                                                                             \
-        static SkBaseMutex& GetChildrenMutex() {                            \
-            SK_DECLARE_STATIC_MUTEX(childrenMutex);                         \
-            return childrenMutex;                                           \
-        }                                                                   \
-                                                                            \
     } fInstanceCountHelper;                                                 \
                                                                             \
     static int32_t GetInstanceCount() {                                     \
@@ -92,7 +86,7 @@ extern bool gPrintInstCount;
         if (NULL == SkInstanceCountHelper::GetChildren()) {                 \
             return GetInstanceCount();                                      \
         }                                                                   \
-        SkTArray<typename SkInstanceCountHelper::PFCheckInstCnt>* children = \
+        SkTArray<int (*)(int, bool)>* children =                            \
             SkInstanceCountHelper::GetChildren();                           \
         int childCount = children->count();                                 \
         int count = GetInstanceCount();                                     \
@@ -111,12 +105,8 @@ extern bool gPrintInstCount;
     }                                                                       \
                                                                             \
     static void AddInstChild(int (*childCheckInstCnt)(int, bool)) {         \
-        if (CheckInstanceCount != childCheckInstCnt) {                      \
-            SkAutoMutexAcquire ama(SkInstanceCountHelper::GetChildrenMutex()); \
-            if (NULL == SkInstanceCountHelper::GetChildren()) {             \
-                SkInstanceCountHelper::GetChildren() =                      \
-                    new SkTArray<typename SkInstanceCountHelper::PFCheckInstCnt>; \
-            }                                                               \
+        if (CheckInstanceCount != childCheckInstCnt &&                      \
+            NULL != SkInstanceCountHelper::GetChildren()) {                 \
             SkInstanceCountHelper::GetChildren()->push_back(childCheckInstCnt); \
         }                                                                   \
     }
index d0d7d26..efb119f 100644 (file)
  * 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 1
+#    define SK_ENABLE_INST_COUNT 0
 #  else
 #    define SK_ENABLE_INST_COUNT 0
 #  endif
similarity index 100%
rename from include/core/SkOnce.h
rename to src/core/SkOnce.h