mark-events
author Benjamin Smedberg <benjamin@smedbergs.us>
Sat, 26 Jul 2008 22:49:39 -0400
changeset 167 a4da40849f5436e629c5732f4368c6c48189637f
parent 66 4161d51d7ccbb4019a5cb4d18a855094024a52db
permissions -rw-r--r--
State as of now

diff --git a/xpcom/threads/nsEventQueue.cpp b/xpcom/threads/nsEventQueue.cpp
--- a/xpcom/threads/nsEventQueue.cpp
+++ b/xpcom/threads/nsEventQueue.cpp
@@ -54,6 +54,7 @@ nsEventQueue::nsEventQueue()
   , mOffsetHead(0)
   , mOffsetTail(0)
 {
+  ASSERT_GCObject(this);
 }
 
 nsEventQueue::~nsEventQueue()
@@ -61,9 +62,6 @@ nsEventQueue::~nsEventQueue()
   // It'd be nice to be able to assert that no one else is holding the monitor,
   // but NSPR doesn't really expose APIs for it.
   NS_ASSERTION(IsEmpty(), "Non-empty event queue being destroyed; events being leaked.");
-
-  if (mHead)
-    FreePage(mHead);
 
   if (mMonitor)
     nsAutoMonitor::DestroyMonitor(mMonitor);
@@ -93,7 +91,6 @@ nsEventQueue::GetEvent(PRBool mayWait, n
       if (mOffsetHead == EVENTS_PER_PAGE) {
         Page *dead = mHead;
         mHead = mHead->mNext;
-        FreePage(dead);
         mOffsetHead = 0;
       }
     }
diff --git a/xpcom/threads/nsEventQueue.h b/xpcom/threads/nsEventQueue.h
--- a/xpcom/threads/nsEventQueue.h
+++ b/xpcom/threads/nsEventQueue.h
@@ -44,6 +44,8 @@
 #include "nsIRunnable.h"
 
 // A threadsafe FIFO event queue...
+// This object should be GC-allocated, but is typically part of a larger
+// class
 class NS_COM nsEventQueue
 {
 public:
@@ -97,18 +99,14 @@ private:
 
   // Page objects are linked together to form a simple deque.
 
-  struct Page; friend struct Page; // VC6!
-  struct Page {
+  struct Page : public MMgc::GCObject {
     struct Page *mNext;
     nsIRunnable *mEvents[EVENTS_PER_PAGE];
   };
 
   static Page *NewPage() {
-    return static_cast<Page *>(calloc(1, sizeof(Page)));
-  }
-
-  static void FreePage(Page *p) {
-    free(p);
+    return new(NS_GetGC(),
+               MMgc::GC::kContainsPointers | MMgc::GC::kZero) Page;
   }
 
   PRMonitor *mMonitor;