27 #ifndef SBREQUESTTHREADQUEUE_H_
28 #define SBREQUESTTHREADQUEUE_H_
36 #include <nsAutoLock.h>
37 #include <nsAutoPtr.h>
43 #include <nsIClassInfo.h>
44 #include <nsIRunnable.h>
45 #include <nsIThread.h>
79 typedef std::list<sbRequestItem *> RequestItems;
96 return mRequestItems.begin();
104 return mRequestItems.begin();
112 return mRequestItems.end();
120 return mRequestItems.end();
129 return mRequestItems.size();
136 return mCountableItems;
163 return mRequestItems.empty();
172 NS_ASSERTION(aRequestItem,
173 "sbRequestThreadQueue::Batch::insert passed null");
174 NS_IF_ADDREF(aRequestItem);
175 return mRequestItems.insert(aIter, aRequestItem);
183 std::sort(mRequestItems.begin(), mRequestItems.end(), aComparer);
195 while (aIndex-- > 0 && iter != end) ++iter;
208 RequestItems mRequestItems;
209 PRUint32 mCountableItems;
210 PRUint32 mRequestType;
212 void RecalcBatchStats();
306 NS_ENSURE_TRUE(
mLock,
false);
307 nsAutoLock lock(
mLock);
406 nsAutoLock lock(
mLock);
408 "CompleteRequests called while no requests pending");
429 typedef std::deque<sbRequestItem *> RequestQueue;
436 RequestQueue mRequestQueue;
441 nsCOMPtr<nsIThread> mThread;
446 nsCOMPtr<nsIRunnable> mReqAddedEvent;
451 PRInt32 mCurrentBatchId;
458 nsCOMPtr<nsIRunnable> mShutdownAction;
465 nsresult FindDuplicateRequest(
sbRequestItem * aItem,
bool &aIsDuplicate);
470 nsresult ProcessRequest();
476 nsresult ThreadShutdownAction(
int);
481 nsAutoRefCnt mRefCnt;
489 nsAutoLock lock(
mLock);
492 return isHandlingRequests;
501 virtual nsresult OnThreadStart() {
return NS_OK; };
506 virtual nsresult OnThreadStop() {
return NS_OK; }
519 aIsDuplicate =
false;
528 virtual nsresult ProcessBatch(Batch & aBatch) = 0;
534 virtual nsresult CleanupBatch(Batch & aBatch)
PRMonitor * GetStopWaitMonitor() const
PRUint32 CountableItems() const
iterator insert(iterator aIter, sbRequestItem *aRequestItem)
sbRequestItem * operator[](int aIndex) const
RequestItems::size_type size_type
virtual void CompleteRequests()
bool IsRequestAbortActive() const
RequestItems::reference reference
void erase(iterator aIter)
const_iterator end() const
RequestItems::const_iterator const_iterator
virtual ~sbRequestThreadQueue()
bool CheckAndResetRequestAbort()
nsresult PopBatch(Batch &aBatch)
nsresult ClearRequestsNoLock(Batch &aRequests)
PRMonitor * mStopWaitMonitor
friend class sbRTQIsBatchable
PRUint32 RequestType() const
nsresult CancelRequests()
nsresult PushRequest(sbRequestItem *aRequestItem)
RequestItems::const_reference const_reference
const_iterator begin() const
NS_IMETHOD_(nsrefcnt) AddRef(void)
bool IsHandlingRequests() const
void push_back(sbRequestItem *aItem)
RequestItems::iterator iterator