diff options
| author | Nat Goodspeed <nat@lindenlab.com> | 2017-11-29 14:47:09 -0500 |
|---|---|---|
| committer | Nat Goodspeed <nat@lindenlab.com> | 2017-11-29 14:47:09 -0500 |
| commit | e3a2c5e3217ae74a0277f2e6d4e1e708fe398a1c (patch) | |
| tree | f912ed486a465f5cc0aee5c73c9cb70c195e8c4d /indra/llcommon/llthread.h | |
| parent | 1693ccba58eef676df1f91e50627545ac35bb819 (diff) | |
| parent | bf98e092e53ed228b3cb50fe816058c5a7817329 (diff) | |
DRTVWR-418: Merge from latest viewer-release
Diffstat (limited to 'indra/llcommon/llthread.h')
| -rw-r--r-- | indra/llcommon/llthread.h | 166 |
1 files changed, 84 insertions, 82 deletions
diff --git a/indra/llcommon/llthread.h b/indra/llcommon/llthread.h index 6f9ec10fd3..dda7fa8ffb 100644 --- a/indra/llcommon/llthread.h +++ b/indra/llcommon/llthread.h @@ -38,118 +38,120 @@ LL_COMMON_API void assert_main_thread(); namespace LLTrace { - class ThreadRecorder; + class ThreadRecorder; } class LL_COMMON_API LLThread { private: - friend class LLMutex; - static U32 sIDIter; + friend class LLMutex; + static U32 sIDIter; public: - typedef enum e_thread_status - { - STOPPED = 0, // The thread is not running. Not started, or has exited its run function - RUNNING = 1, // The thread is currently running - QUITTING= 2 // Someone wants this thread to quit - } EThreadStatus; + typedef enum e_thread_status + { + STOPPED = 0, // The thread is not running. Not started, or has exited its run function + RUNNING = 1, // The thread is currently running + QUITTING= 2, // Someone wants this thread to quit + CRASHED = -1 // An uncaught exception was thrown by the thread + } EThreadStatus; - LLThread(const std::string& name, apr_pool_t *poolp = NULL); - virtual ~LLThread(); // Warning! You almost NEVER want to destroy a thread unless it's in the STOPPED state. - virtual void shutdown(); // stops the thread - - bool isQuitting() const { return (QUITTING == mStatus); } - bool isStopped() const { return (STOPPED == mStatus); } - - static U32 currentID(); // Return ID of current thread - static void yield(); // Static because it can be called by the main thread, which doesn't have an LLThread data structure. - + LLThread(const std::string& name, apr_pool_t *poolp = NULL); + virtual ~LLThread(); // Warning! You almost NEVER want to destroy a thread unless it's in the STOPPED state. + virtual void shutdown(); // stops the thread + + bool isQuitting() const { return (QUITTING == mStatus); } + bool isStopped() const { return (STOPPED == mStatus) || (CRASHED == mStatus); } + bool isCrashed() const { return (CRASHED == mStatus); } + + static U32 currentID(); // Return ID of current thread + static void yield(); // Static because it can be called by the main thread, which doesn't have an LLThread data structure. + public: - // PAUSE / RESUME functionality. See source code for important usage notes. - // Called from MAIN THREAD. - void pause(); - void unpause(); - bool isPaused() { return isStopped() || mPaused == TRUE; } - - // Cause the thread to wake up and check its condition - void wake(); + // PAUSE / RESUME functionality. See source code for important usage notes. + // Called from MAIN THREAD. + void pause(); + void unpause(); + bool isPaused() { return isStopped() || mPaused == TRUE; } + + // Cause the thread to wake up and check its condition + void wake(); - // Same as above, but to be used when the condition is already locked. - void wakeLocked(); + // Same as above, but to be used when the condition is already locked. + void wakeLocked(); - // Called from run() (CHILD THREAD). Pause the thread if requested until unpaused. - void checkPause(); + // Called from run() (CHILD THREAD). Pause the thread if requested until unpaused. + void checkPause(); - // this kicks off the apr thread - void start(void); + // this kicks off the apr thread + void start(void); - apr_pool_t *getAPRPool() { return mAPRPoolp; } - LLVolatileAPRPool* getLocalAPRFilePool() { return mLocalAPRFilePoolp ; } + apr_pool_t *getAPRPool() { return mAPRPoolp; } + LLVolatileAPRPool* getLocalAPRFilePool() { return mLocalAPRFilePoolp ; } - U32 getID() const { return mID; } + U32 getID() const { return mID; } - // Called by threads *not* created via LLThread to register some - // internal state used by LLMutex. You must call this once early - // in the running thread to prevent collisions with the main thread. - static void registerThreadID(); - + // Called by threads *not* created via LLThread to register some + // internal state used by LLMutex. You must call this once early + // in the running thread to prevent collisions with the main thread. + static void registerThreadID(); + private: - BOOL mPaused; - - // static function passed to APR thread creation routine - static void *APR_THREAD_FUNC staticRun(struct apr_thread_t *apr_threadp, void *datap); + BOOL mPaused; + + // static function passed to APR thread creation routine + static void *APR_THREAD_FUNC staticRun(struct apr_thread_t *apr_threadp, void *datap); protected: - std::string mName; - class LLCondition* mRunCondition; - LLMutex* mDataLock; + std::string mName; + class LLCondition* mRunCondition; + LLMutex* mDataLock; - apr_thread_t *mAPRThreadp; - apr_pool_t *mAPRPoolp; - BOOL mIsLocalPool; - EThreadStatus mStatus; - U32 mID; - LLTrace::ThreadRecorder* mRecorder; + apr_thread_t *mAPRThreadp; + apr_pool_t *mAPRPoolp; + BOOL mIsLocalPool; + EThreadStatus mStatus; + U32 mID; + LLTrace::ThreadRecorder* mRecorder; - //a local apr_pool for APRFile operations in this thread. If it exists, LLAPRFile::sAPRFilePoolp should not be used. - //Note: this pool is used by APRFile ONLY, do NOT use it for any other purposes. - // otherwise it will cause severe memory leaking!!! --bao - LLVolatileAPRPool *mLocalAPRFilePoolp ; + //a local apr_pool for APRFile operations in this thread. If it exists, LLAPRFile::sAPRFilePoolp should not be used. + //Note: this pool is used by APRFile ONLY, do NOT use it for any other purposes. + // otherwise it will cause severe memory leaking!!! --bao + LLVolatileAPRPool *mLocalAPRFilePoolp ; - void setQuitting(); - - // virtual function overridden by subclass -- this will be called when the thread runs - virtual void run(void) = 0; - - // virtual predicate function -- returns true if the thread should wake up, false if it should sleep. - virtual bool runCondition(void); + void setQuitting(); + + // virtual function overridden by subclass -- this will be called when the thread runs + virtual void run(void) = 0; + + // virtual predicate function -- returns true if the thread should wake up, false if it should sleep. + virtual bool runCondition(void); - // Lock/Unlock Run Condition -- use around modification of any variable used in runCondition() - inline void lockData(); - inline void unlockData(); - - // This is the predicate that decides whether the thread should sleep. - // It should only be called with mDataLock locked, since the virtual runCondition() function may need to access - // data structures that are thread-unsafe. - bool shouldSleep(void) { return (mStatus == RUNNING) && (isPaused() || (!runCondition())); } + // Lock/Unlock Run Condition -- use around modification of any variable used in runCondition() + inline void lockData(); + inline void unlockData(); + + // This is the predicate that decides whether the thread should sleep. + // It should only be called with mDataLock locked, since the virtual runCondition() function may need to access + // data structures that are thread-unsafe. + bool shouldSleep(void) { return (mStatus == RUNNING) && (isPaused() || (!runCondition())); } - // To avoid spurious signals (and the associated context switches) when the condition may or may not have changed, you can do the following: - // mDataLock->lock(); - // if(!shouldSleep()) - // mRunCondition->signal(); - // mDataLock->unlock(); + // To avoid spurious signals (and the associated context switches) when the condition may or may not have changed, you can do the following: + // mDataLock->lock(); + // if(!shouldSleep()) + // mRunCondition->signal(); + // mDataLock->unlock(); }; void LLThread::lockData() { - mDataLock->lock(); + mDataLock->lock(); } void LLThread::unlockData() { - mDataLock->unlock(); + mDataLock->unlock(); } @@ -160,9 +162,9 @@ void LLThread::unlockData() class LL_COMMON_API LLResponder : public LLThreadSafeRefCount { protected: - virtual ~LLResponder(); + virtual ~LLResponder(); public: - virtual void completed(bool success) = 0; + virtual void completed(bool success) = 0; }; //============================================================================ |
