From 02dee1652be7868d588fefa8b8e672be40088bdb Mon Sep 17 00:00:00 2001 From: Jacek Antonelli Date: Mon, 8 Feb 2010 17:25:48 -0600 Subject: Ported some thread changes from Snowglobe. --- linden/indra/llcommon/llqueuedthread.cpp | 49 +++++++++++++++++--------------- linden/indra/llcommon/llqueuedthread.h | 3 ++ linden/indra/llcommon/llworkerthread.cpp | 1 + linden/indra/llcommon/llworkerthread.h | 1 + 4 files changed, 31 insertions(+), 23 deletions(-) (limited to 'linden') diff --git a/linden/indra/llcommon/llqueuedthread.cpp b/linden/indra/llcommon/llqueuedthread.cpp index cd53e70..aa62da8 100644 --- a/linden/indra/llcommon/llqueuedthread.cpp +++ b/linden/indra/llcommon/llqueuedthread.cpp @@ -450,26 +450,12 @@ S32 LLQueuedThread::processNextRequest() } } - S32 res; S32 pending = getPending(); - if (pending == 0) - { - if (isQuitting()) - { - res = -1; // exit thread - } - else - { - res = 0; - } - } - else - { - res = pending; - } - return res; + + return pending; } +// virtual bool LLQueuedThread::runCondition() { // mRunCondition must be locked here @@ -479,35 +465,52 @@ bool LLQueuedThread::runCondition() return true; } +// virtual void LLQueuedThread::run() { + // call checPause() immediately so we don't try to do anything before the class is fully constructed + checkPause(); + startThread(); + while (1) { // this will block on the condition until runCondition() returns true, the thread is unpaused, or the thread leaves the RUNNING state. checkPause(); if(isQuitting()) + { + endThread(); break; - - //llinfos << "QUEUED THREAD RUNNING, queue size = " << mRequestQueue.size() << llendl; + } mIdleThread = FALSE; + threadedUpdate(); + int res = processNextRequest(); if (res == 0) { mIdleThread = TRUE; + ms_sleep(1); + } + //LLThread::yield(); // thread should yield after each request + } + llinfos << "LLQueuedThread " << mName << " EXITING." << llendl; } - if (res < 0) // finished working and want to exit +// virtual +void LLQueuedThread::startThread() { - break; } - //LLThread::yield(); // thread should yield after each request +// virtual +void LLQueuedThread::endThread() +{ } - llinfos << "QUEUED THREAD " << mName << " EXITING." << llendl; +// virtual +void LLQueuedThread::threadedUpdate() +{ } //============================================================================ diff --git a/linden/indra/llcommon/llqueuedthread.h b/linden/indra/llcommon/llqueuedthread.h index 3ba43e1..aa7c6e4 100644 --- a/linden/indra/llcommon/llqueuedthread.h +++ b/linden/indra/llcommon/llqueuedthread.h @@ -165,6 +165,9 @@ private: virtual bool runCondition(void); virtual void run(void); + virtual void startThread(void); + virtual void endThread(void); + virtual void threadedUpdate(void); protected: handle_t generateHandle(); diff --git a/linden/indra/llcommon/llworkerthread.cpp b/linden/indra/llcommon/llworkerthread.cpp index 68d32db..8195e1c 100644 --- a/linden/indra/llcommon/llworkerthread.cpp +++ b/linden/indra/llcommon/llworkerthread.cpp @@ -196,6 +196,7 @@ LLWorkerClass::~LLWorkerClass() { llassert_always(!(mWorkFlags & WCF_WORKING)); llassert_always(mWorkFlags & WCF_DELETE_REQUESTED); + llassert_always(!mMutex.isLocked()); if (mRequestHandle != LLWorkerThread::nullHandle()) { LLWorkerThread::WorkRequest* workreq = (LLWorkerThread::WorkRequest*)mWorkerThread->getRequest(mRequestHandle); diff --git a/linden/indra/llcommon/llworkerthread.h b/linden/indra/llcommon/llworkerthread.h index 19407f4..708d812 100644 --- a/linden/indra/llcommon/llworkerthread.h +++ b/linden/indra/llcommon/llworkerthread.h @@ -52,6 +52,7 @@ class LLWorkerClass; class LLWorkerThread : public LLQueuedThread { + friend class LLWorkerClass; public: class WorkRequest : public LLQueuedThread::QueuedRequest { -- cgit v1.1