diff --git a/xpcom/threads/nsEventQueue.cpp b/xpcom/threads/nsEventQueue.cpp index 6ba238d1e9a7..4c68e5156414 100644 --- a/xpcom/threads/nsEventQueue.cpp +++ b/xpcom/threads/nsEventQueue.cpp @@ -80,48 +80,40 @@ nsEventQueue::GetEvent(bool mayWait, nsIRunnable **result) return true; } -bool +void nsEventQueue::PutEvent(nsIRunnable *runnable) { // Avoid calling AddRef+Release while holding our monitor. nsRefPtr event(runnable); - bool rv = true; - { - if (ChaosMode::isActive()) { - // With probability 0.5, yield so other threads have a chance to - // dispatch events to this queue first. - if (ChaosMode::randomUint32LessThan(2)) { - PR_Sleep(PR_INTERVAL_NO_WAIT); - } - } - ReentrantMonitorAutoEnter mon(mReentrantMonitor); - - if (!mHead) { - mHead = NewPage(); - if (!mHead) { - rv = false; - } else { - mTail = mHead; - mOffsetHead = 0; - mOffsetTail = 0; - } - } else if (mOffsetTail == EVENTS_PER_PAGE) { - Page *page = NewPage(); - if (!page) { - rv = false; - } else { - mTail->mNext = page; - mTail = page; - mOffsetTail = 0; - } - } - if (rv) { - event.swap(mTail->mEvents[mOffsetTail]); - ++mOffsetTail; - LOG(("EVENTQ(%p): notify\n", this)); - mon.NotifyAll(); + if (ChaosMode::isActive()) { + // With probability 0.5, yield so other threads have a chance to + // dispatch events to this queue first. + if (ChaosMode::randomUint32LessThan(2)) { + PR_Sleep(PR_INTERVAL_NO_WAIT); } } - return rv; + + ReentrantMonitorAutoEnter mon(mReentrantMonitor); + + if (!mHead) { + mHead = NewPage(); + MOZ_ASSERT(mHead); + + mTail = mHead; + mOffsetHead = 0; + mOffsetTail = 0; + } else if (mOffsetTail == EVENTS_PER_PAGE) { + Page *page = NewPage(); + MOZ_ASSERT(page); + + mTail->mNext = page; + mTail = page; + mOffsetTail = 0; + } + + event.swap(mTail->mEvents[mOffsetTail]); + ++mOffsetTail; + LOG(("EVENTQ(%p): notify\n", this)); + mon.NotifyAll(); } diff --git a/xpcom/threads/nsEventQueue.h b/xpcom/threads/nsEventQueue.h index f261a1bb83bf..5a9bf5adf4a3 100644 --- a/xpcom/threads/nsEventQueue.h +++ b/xpcom/threads/nsEventQueue.h @@ -20,11 +20,10 @@ public: nsEventQueue(); ~nsEventQueue(); - // This method adds a new event to the pending event queue. The event object - // is AddRef'd if this method succeeds. This method returns true if the - // event was stored in the event queue, and it returns false if it could - // not allocate sufficient memory. - bool PutEvent(nsIRunnable *event); + // This method adds a new event to the pending event queue. The queue holds + // a strong reference to the event after this method returns. This method + // cannot fail. + void PutEvent(nsIRunnable *event); // This method gets an event from the event queue. If mayWait is true, then // the method will block the calling thread until an event is available. If @@ -44,11 +43,6 @@ public: return GetEvent(false, runnable); } - // This method waits for and returns the next pending event. - bool WaitPendingEvent(nsIRunnable **runnable) { - return GetEvent(true, runnable); - } - // Expose the event queue's monitor for "power users" ReentrantMonitor& GetReentrantMonitor() { return mReentrantMonitor; @@ -73,7 +67,7 @@ private: "sizeof(Page) should be a power of two to avoid heap slop."); static Page *NewPage() { - return static_cast(calloc(1, sizeof(Page))); + return static_cast(moz_xcalloc(1, sizeof(Page))); } static void FreePage(Page *p) { diff --git a/xpcom/threads/nsThread.cpp b/xpcom/threads/nsThread.cpp index b577727a3d83..c01d6fb69cb0 100644 --- a/xpcom/threads/nsThread.cpp +++ b/xpcom/threads/nsThread.cpp @@ -432,8 +432,7 @@ nsThread::PutEvent(nsIRunnable *event, nsNestedEventTarget *target) NS_WARNING("An event was posted to a thread that will never run it (rejected)"); return NS_ERROR_UNEXPECTED; } - if (!queue->PutEvent(event)) - return NS_ERROR_OUT_OF_MEMORY; + queue->PutEvent(event); } nsCOMPtr obs = GetObserver(); diff --git a/xpcom/threads/nsThread.h b/xpcom/threads/nsThread.h index 714fef38ec65..0c3c839a1d50 100644 --- a/xpcom/threads/nsThread.h +++ b/xpcom/threads/nsThread.h @@ -97,8 +97,8 @@ protected: return mQueue.GetEvent(mayWait, event); } - bool PutEvent(nsIRunnable *event) { - return mQueue.PutEvent(event); + void PutEvent(nsIRunnable *event) { + mQueue.PutEvent(event); } bool HasPendingEvent() {