From 6dc4a6072414362c79ffc83066fe8f4d82241fda Mon Sep 17 00:00:00 2001 From: Aleric Inglewood Date: Sat, 26 Jan 2013 18:53:57 +0100 Subject: [PATCH] Changes to LLThread * Call a virtual terminated() that by default sets mStatus to STOPPED, instead of setting it to STOPPED directly, allowing to override the behavior of a LLThread derived class when the thread is about the exit. * Make setQuitting() public, so it can also be used to hint to a thread that it should stop at its earliest convience. --- indra/llcommon/llthread.cpp | 2 +- indra/llcommon/llthread.h | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/indra/llcommon/llthread.cpp b/indra/llcommon/llthread.cpp index ac97d37de..4d58a59f3 100644 --- a/indra/llcommon/llthread.cpp +++ b/indra/llcommon/llthread.cpp @@ -109,7 +109,7 @@ void *APR_THREAD_FUNC LLThread::staticRun(apr_thread_t *apr_threadp, void *datap --sRunning; // We're done with the run function, this thread is done executing now. - threadp->mStatus = STOPPED; + threadp->terminated(); // Only now print this info [doing that before setting mStatus // to STOPPED makes it much more likely that another thread runs diff --git a/indra/llcommon/llthread.h b/indra/llcommon/llthread.h index 549a090ec..c2daa22fb 100644 --- a/indra/llcommon/llthread.h +++ b/indra/llcommon/llthread.h @@ -128,6 +128,9 @@ public: // this kicks off the apr thread void start(void); + // Can be used to tell the thread we're not interested anymore and it should abort. + void setQuitting(); + // Return thread-local data for the current thread. static LLThreadLocalData& tldata(void) { return LLThreadLocalData::tldata(); } @@ -147,11 +150,12 @@ protected: friend void LLThreadLocalData::create(LLThread* threadp); LLThreadLocalData* mThreadLocalData; - void setQuitting(); - // virtual function overridden by subclass -- this will be called when the thread runs virtual void run(void) = 0; + // This class is completely done (called from THREAD!). + virtual void terminated(void) { mStatus = STOPPED; } + // virtual predicate function -- returns true if the thread should wake up, false if it should sleep. virtual bool runCondition(void);