Rename SkTDLinkedList to SkTInternalLinked list, add some methods useful for forthcom...
authorbsalomon@google.com <bsalomon@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>
Mon, 3 Dec 2012 14:54:59 +0000 (14:54 +0000)
committerbsalomon@google.com <bsalomon@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>
Mon, 3 Dec 2012 14:54:59 +0000 (14:54 +0000)
Review URL: https://codereview.appspot.com/6858101

git-svn-id: http://skia.googlecode.com/svn/trunk@6643 2bbb7eff-a529-9590-31e7-b0007b416f81

gyp/core.gypi
include/core/SkTDLinkedList.h [deleted file]
include/core/SkTInternalLList.h [new file with mode: 0644]
include/gpu/GrResource.h
include/utils/SkThreadPool.h
src/gpu/GrGpu.h
src/gpu/GrResourceCache.h
tests/TDLinkedListTest.cpp

index 6251ce6554ab8d684ce30753ee4c891176735ed3..960af338a959ff690d3caf650f12e6142f41e18b 100644 (file)
         '<(skia_include_path)/core/SkTDArray.h',
         '<(skia_include_path)/core/SkTDStack.h',
         '<(skia_include_path)/core/SkTDict.h',
-        '<(skia_include_path)/core/SkTDLinkedList.h',
+        '<(skia_include_path)/core/SkTInternalLList.h',
         '<(skia_include_path)/core/SkTRegistry.h',
         '<(skia_include_path)/core/SkTScopedPtr.h',
         '<(skia_include_path)/core/SkTSearch.h',
diff --git a/include/core/SkTDLinkedList.h b/include/core/SkTDLinkedList.h
deleted file mode 100644 (file)
index 9247812..0000000
+++ /dev/null
@@ -1,179 +0,0 @@
-/*
- * Copyright 2012 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#ifndef SkTDLinkedList_DEFINED
-#define SkTDLinkedList_DEFINED
-
-#include "SkTypes.h"
-
-/**
- * Helper class to automatically initialize the doubly linked list
- * created pointers.
- */
-template <typename T> class SkPtrWrapper {
-  public:
-      SkPtrWrapper() : fPtr(NULL) {}
-      SkPtrWrapper& operator =(T* ptr) { fPtr = ptr; return *this; }
-      operator T*() const { return fPtr; }
-      T* operator->() { return fPtr; }
-  private:
-      T* fPtr;
-};
-
-
-/**
- * This macro creates the member variables required by
- * the SkTDLinkedList class. It should be placed in the private section
- * of any class that will be stored in a double linked list.
- */
-#define SK_DEFINE_DLINKEDLIST_INTERFACE(ClassName)              \
-    friend class SkTDLinkedList<ClassName>;                     \
-    /* back pointer to the owning list - for debugging */       \
-    SkDEBUGCODE(SkPtrWrapper<SkTDLinkedList<ClassName> > fList;)\
-    SkPtrWrapper<ClassName> fPrev;                              \
-    SkPtrWrapper<ClassName> fNext;
-
-/**
- * This class implements a templated internal doubly linked list data structure.
- */
-template <class T> class SkTDLinkedList : public SkNoncopyable {
-public:
-    SkTDLinkedList()
-        : fHead(NULL)
-        , fTail(NULL) {
-    }
-
-    void remove(T* entry) {
-        SkASSERT(NULL != fHead && NULL != fTail);
-        SkASSERT(this->isInList(entry));
-
-        T* prev = entry->fPrev;
-        T* next = entry->fNext;
-
-        if (NULL != prev) {
-            prev->fNext = next;
-        } else {
-            fHead = next;
-        }
-        if (NULL != next) {
-            next->fPrev = prev;
-        } else {
-            fTail = prev;
-        }
-
-        entry->fPrev = NULL;
-        entry->fNext = NULL;
-
-#ifdef SK_DEBUG
-        entry->fList = NULL;
-#endif
-    }
-
-    void addToHead(T* entry) {
-        SkASSERT(NULL == entry->fPrev && NULL == entry->fNext);
-        SkASSERT(NULL == entry->fList);
-
-        entry->fPrev = NULL;
-        entry->fNext = fHead;
-        if (NULL != fHead) {
-            fHead->fPrev = entry;
-        }
-        fHead = entry;
-        if (NULL == fTail) {
-            fTail = entry;
-        }
-
-#ifdef SK_DEBUG
-        entry->fList = this;
-#endif
-    }
-
-    bool isEmpty() const {
-        return NULL == fHead && NULL == fTail;
-    }
-
-    T* head() { return fHead; }
-    T* tail() { return fTail; }
-
-    class Iter {
-    public:
-        enum IterStart {
-            kHead_IterStart,
-            kTail_IterStart
-        };
-
-        Iter() : fCur(NULL) {}
-
-        T* init(SkTDLinkedList& list, IterStart startLoc) {
-            if (kHead_IterStart == startLoc) {
-                fCur = list.fHead;
-            } else {
-                SkASSERT(kTail_IterStart == startLoc);
-                fCur = list.fTail;
-            }
-
-            return fCur;
-        }
-
-        /**
-         * Return the next/previous element in the list or NULL if at the end.
-         */
-        T* next() {
-            if (NULL == fCur) {
-                return NULL;
-            }
-
-            fCur = fCur->fNext;
-            return fCur;
-        }
-
-        T* prev() {
-            if (NULL == fCur) {
-                return NULL;
-            }
-
-            fCur = fCur->fPrev;
-            return fCur;
-        }
-
-    private:
-        T* fCur;
-    };
-
-#ifdef SK_DEBUG
-    void validate() const {
-        GrAssert(!fHead == !fTail);
-    }
-
-    /**
-     * Debugging-only method that uses the list back pointer to check if
-     * 'entry' is indeed in 'this' list.
-     */
-    bool isInList(const T* entry) const {
-        return entry->fList == this;
-    }
-
-    /**
-     * Debugging-only method that laboriously counts the list entries.
-     */
-    int countEntries() const {
-        int count = 0;
-        for (T* entry = fHead; NULL != entry; entry = entry->fNext) {
-            ++count;
-        }
-        return count;
-    }
-#endif // SK_DEBUG
-
-private:
-    T* fHead;
-    T* fTail;
-
-    typedef SkNoncopyable INHERITED;
-};
-
-#endif // SkTDLinkedList_DEFINED
diff --git a/include/core/SkTInternalLList.h b/include/core/SkTInternalLList.h
new file mode 100644 (file)
index 0000000..32245b5
--- /dev/null
@@ -0,0 +1,200 @@
+/*
+ * Copyright 2012 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef SkTInternalLList_DEFINED
+#define SkTInternalLList_DEFINED
+
+#include "SkTypes.h"
+
+/**
+ * Helper class to automatically initialize the doubly linked list created pointers.
+ */
+template <typename T> class SkPtrWrapper {
+  public:
+      SkPtrWrapper() : fPtr(NULL) {}
+      SkPtrWrapper& operator =(T* ptr) { fPtr = ptr; return *this; }
+      operator T*() const { return fPtr; }
+      T* operator->() { return fPtr; }
+  private:
+      T* fPtr;
+};
+
+
+/**
+ * This macro creates the member variables required by the SkTInternalLList class. It should be
+ * placed in the private section of any class that will be stored in a double linked list.
+ */
+#define SK_DECLARE_INTERNAL_LLIST_INTERFACE(ClassName)              \
+    friend class SkTInternalLList<ClassName>;                       \
+    /* back pointer to the owning list - for debugging */           \
+    SkDEBUGCODE(SkPtrWrapper<SkTInternalLList<ClassName> > fList;)  \
+    SkPtrWrapper<ClassName> fPrev;                                  \
+    SkPtrWrapper<ClassName> fNext
+
+/**
+ * This class implements a templated internal doubly linked list data structure.
+ */
+template <class T> class SkTInternalLList : public SkNoncopyable {
+public:
+    SkTInternalLList()
+        : fHead(NULL)
+        , fTail(NULL) {
+    }
+
+    void remove(T* entry) {
+        SkASSERT(NULL != fHead && NULL != fTail);
+        SkASSERT(this->isInList(entry));
+
+        T* prev = entry->fPrev;
+        T* next = entry->fNext;
+
+        if (NULL != prev) {
+            prev->fNext = next;
+        } else {
+            fHead = next;
+        }
+        if (NULL != next) {
+            next->fPrev = prev;
+        } else {
+            fTail = prev;
+        }
+
+        entry->fPrev = NULL;
+        entry->fNext = NULL;
+
+#ifdef SK_DEBUG
+        entry->fList = NULL;
+#endif
+    }
+
+    void addToHead(T* entry) {
+        SkASSERT(NULL == entry->fPrev && NULL == entry->fNext);
+        SkASSERT(NULL == entry->fList);
+
+        entry->fPrev = NULL;
+        entry->fNext = fHead;
+        if (NULL != fHead) {
+            fHead->fPrev = entry;
+        }
+        fHead = entry;
+        if (NULL == fTail) {
+            fTail = entry;
+        }
+
+#ifdef SK_DEBUG
+        entry->fList = this;
+#endif
+    }
+
+    void addToTail(T* entry) {
+        SkASSERT(NULL == entry->fPrev && NULL == entry->fNext);
+        SkASSERT(NULL == entry->fList);
+
+        entry->fPrev = fTail;
+        entry->fNext = NULL;
+        if (NULL != fTail) {
+            fTail->fNext = entry;
+        }
+        fTail = entry;
+        if (NULL == fHead) {
+            fHead = entry;
+        }
+
+#ifdef SK_DEBUG
+        entry->fList = this;
+#endif
+    }
+
+    bool isEmpty() const {
+        return NULL == fHead && NULL == fTail;
+    }
+
+    T* head() { return fHead; }
+    T* tail() { return fTail; }
+
+    class Iter {
+    public:
+        enum IterStart {
+            kHead_IterStart,
+            kTail_IterStart
+        };
+
+        Iter() : fCurr(NULL) {}
+        Iter(const Iter& iter) : fCurr(iter.fCurr) {}
+        Iter& operator= (const Iter& iter) { fCurr = iter.fCurr; return *this; }
+
+        T* init(const SkTInternalLList& list, IterStart startLoc) {
+            if (kHead_IterStart == startLoc) {
+                fCurr = list.fHead;
+            } else {
+                SkASSERT(kTail_IterStart == startLoc);
+                fCurr = list.fTail;
+            }
+
+            return fCurr;
+        }
+
+        T* get() { return fCurr; }
+
+        /**
+         * Return the next/previous element in the list or NULL if at the end.
+         */
+        T* next() {
+            if (NULL == fCurr) {
+                return NULL;
+            }
+
+            fCurr = fCurr->fNext;
+            return fCurr;
+        }
+
+        T* prev() {
+            if (NULL == fCurr) {
+                return NULL;
+            }
+
+            fCurr = fCurr->fPrev;
+            return fCurr;
+        }
+
+    private:
+        T* fCurr;
+    };
+
+#ifdef SK_DEBUG
+    void validate() const {
+        SkASSERT(!fHead == !fTail);
+    }
+
+    /**
+     * Debugging-only method that uses the list back pointer to check if 'entry' is indeed in 'this'
+     * list.
+     */
+    bool isInList(const T* entry) const {
+        return entry->fList == this;
+    }
+
+    /**
+     * Debugging-only method that laboriously counts the list entries.
+     */
+    int countEntries() const {
+        int count = 0;
+        for (T* entry = fHead; NULL != entry; entry = entry->fNext) {
+            ++count;
+        }
+        return count;
+    }
+#endif // SK_DEBUG
+
+private:
+    T* fHead;
+    T* fTail;
+
+    typedef SkNoncopyable INHERITED;
+};
+
+#endif
index aeab180226f53905fc6dcf23c796876a9bd3e4d5..3c306f88c6503240f2938a3e8a9b54f91a05d106 100644 (file)
@@ -12,7 +12,7 @@
 
 #include "GrRefCnt.h"
 
-#include "SkTDLinkedList.h"
+#include "SkTInternalLList.h"
 
 class GrGpu;
 class GrContext;
@@ -93,8 +93,8 @@ private:
                             // release() on all such resources in its
                             // destructor.
 
-    // we're a dlinklist
-    SK_DEFINE_DLINKEDLIST_INTERFACE(GrResource);
+    // We're in an internal doubly linked list
+    SK_DECLARE_INTERNAL_LLIST_INTERFACE(GrResource);
 
     GrResourceEntry* fCacheEntry;  // NULL if not in cache
 
index a96f87b27550596bede1c59c112b6561f88ee5ae..cc45fc2cd53f9f2317c7301ad25bd9b181bb0fbb 100644 (file)
@@ -10,7 +10,7 @@
 
 #include "SkCondVar.h"
 #include "SkTDArray.h"
-#include "SkTDLinkedList.h"
+#include "SkTInternalLList.h"
 
 class SkRunnable;
 class SkThread;
@@ -36,13 +36,13 @@ public:
         SkRunnable* fRunnable;
 
     private:
-        SK_DEFINE_DLINKEDLIST_INTERFACE(LinkedRunnable)
+        SK_DECLARE_INTERNAL_LLIST_INTERFACE(LinkedRunnable);
     };
 
-    SkTDLinkedList<LinkedRunnable> fQueue;
-    SkCondVar                      fReady;
-    SkTDArray<SkThread*>           fThreads;
-    bool                           fDone;
+    SkTInternalLList<LinkedRunnable>    fQueue;
+    SkCondVar                           fReady;
+    SkTDArray<SkThread*>                fThreads;
+    bool                            fDone;
 
     static void Loop(void*);  // Static because we pass in this.
 };
index a4ed0ed5e766c0598216fe16009e3477b6fb276e..f9fd779ca7b9cc36b17cf6fc4ad21eba6e9194ae 100644 (file)
@@ -553,7 +553,7 @@ private:
 
     bool                        fContextIsDirty;
 
-    typedef SkTDLinkedList<GrResource> ResourceList;
+    typedef SkTInternalLList<GrResource> ResourceList;
     ResourceList                fResourceList;
 
     // Given a rt, find or create a stencil buffer and attach it
index c56edf6a5d0863df20f8d78721e8208a0de6b988..2541930efddf9b56f82a3651a485d7a77244386b 100644 (file)
@@ -14,7 +14,7 @@
 #include "GrConfig.h"
 #include "GrTypes.h"
 #include "GrTHashCache.h"
-#include "SkTDLinkedList.h"
+#include "SkTInternalLList.h"
 
 class GrResource;
 
@@ -159,8 +159,8 @@ private:
     GrResourceKey    fKey;
     GrResource*      fResource;
 
-    // we're a dlinklist
-    SK_DEFINE_DLINKEDLIST_INTERFACE(GrResourceEntry);
+    // we're a linked list
+    SK_DECLARE_INTERNAL_LLIST_INTERFACE(GrResourceEntry);
 
     friend class GrResourceCache;
     friend class GrDLinkedList;
@@ -312,8 +312,8 @@ private:
     class Key;
     GrTHashTable<GrResourceEntry, Key, 8> fCache;
 
-    // manage the dlink list
-    typedef SkTDLinkedList<GrResourceEntry> EntryList;
+    // We're an internal doubly linked list
+    typedef SkTInternalLList<GrResourceEntry> EntryList;
     EntryList    fList;
 
 #if GR_DEBUG
@@ -342,7 +342,7 @@ private:
     bool fPurging;
 
 #if GR_DEBUG
-    static size_t countBytes(const SkTDLinkedList<GrResourceEntry>& list);
+    static size_t countBytes(const SkTInternalLList<GrResourceEntry>& list);
 #endif
 };
 
index 8df39b892744f05521fd3d657fdfb5c356c89d87..b4ea0b7100c23aa9c855fd8a6e6cdeb0be2cf3ca 100644 (file)
@@ -6,7 +6,7 @@
  */
 
 #include "Test.h"
-#include "SkTDLinkedList.h"
+#include "SkTInternalLList.h"
 
 class ListElement {
 public:
@@ -16,10 +16,10 @@ public:
     int fID;
 
 private:
-    SK_DEFINE_DLINKEDLIST_INTERFACE(ListElement);
+    SK_DECLARE_INTERNAL_LLIST_INTERFACE(ListElement);
 };
 
-static void CheckList(const SkTDLinkedList<ListElement>& list,
+static void CheckList(const SkTInternalLList<ListElement>& list,
                       skiatest::Reporter* reporter,
                       bool empty,
                       int numElements,
@@ -37,7 +37,7 @@ static void CheckList(const SkTDLinkedList<ListElement>& list,
 }
 
 static void TestTDLinkedList(skiatest::Reporter* reporter) {
-    SkTDLinkedList<ListElement> list;
+    SkTInternalLList<ListElement> list;
     ListElement elements[4] = {
         ListElement(0),
         ListElement(1),
@@ -59,14 +59,15 @@ static void TestTDLinkedList(skiatest::Reporter* reporter) {
     CheckList(list, reporter, false, 4, true, true, true, true, elements);
 
     // test out iterators
-    SkTDLinkedList<ListElement>::Iter iter;
+    typedef SkTInternalLList<ListElement>::Iter Iter;
+    Iter iter;
 
-    ListElement* cur = iter.init(list, SkTDLinkedList<ListElement>::Iter::kHead_IterStart);
+    ListElement* cur = iter.init(list, Iter::kHead_IterStart);
     for (int i = 0; NULL != cur; ++i, cur = iter.next()) {
         REPORTER_ASSERT(reporter, cur->fID == 3-i);
     }
 
-    cur = iter.init(list, SkTDLinkedList<ListElement>::Iter::kTail_IterStart);
+    cur = iter.init(list, Iter::kTail_IterStart);
     for (int i = 0; NULL != cur; ++i, cur = iter.prev()) {
         REPORTER_ASSERT(reporter, cur->fID == i);
     }