aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/llcommon/llthread.h
diff options
context:
space:
mode:
Diffstat (limited to 'linden/indra/llcommon/llthread.h')
-rw-r--r--linden/indra/llcommon/llthread.h75
1 files changed, 70 insertions, 5 deletions
diff --git a/linden/indra/llcommon/llthread.h b/linden/indra/llcommon/llthread.h
index 2a13d72..cdf1d33 100644
--- a/linden/indra/llcommon/llthread.h
+++ b/linden/indra/llcommon/llthread.h
@@ -30,6 +30,7 @@
30 30
31#include "llapr.h" 31#include "llapr.h"
32#include "llapp.h" 32#include "llapp.h"
33#include "llmemory.h"
33 34
34#include "apr-1/apr_thread_cond.h" 35#include "apr-1/apr_thread_cond.h"
35 36
@@ -49,19 +50,20 @@ public:
49 50
50 LLThread(const std::string& name, apr_pool_t *poolp = NULL); 51 LLThread(const std::string& name, apr_pool_t *poolp = NULL);
51 virtual ~LLThread(); // Warning! You almost NEVER want to destroy a thread unless it's in the STOPPED state. 52 virtual ~LLThread(); // Warning! You almost NEVER want to destroy a thread unless it's in the STOPPED state.
52 53 virtual void shutdown(); // stops the thread
54
53 static void yield(); // Static because it can be called by the main thread, which doesn't have an LLThread data structure. 55 static void yield(); // Static because it can be called by the main thread, which doesn't have an LLThread data structure.
54 56
55 57
56 bool isQuitting() const; 58 bool isQuitting() const { return (QUITTING == mStatus); }
57 bool isStopped() const; 59 bool isStopped() const { return (STOPPED == mStatus); }
58 60
59 // PAUSE / RESUME functionality. See source code for important usage notes. 61 // PAUSE / RESUME functionality. See source code for important usage notes.
60public: 62public:
61 // Called from MAIN THREAD. 63 // Called from MAIN THREAD.
62 void pause(); 64 void pause();
63 void unpause(); 65 void unpause();
64 bool isPaused() { return mPaused ? true : false; } 66 bool isPaused() { return isStopped() || mPaused == TRUE; }
65 67
66 // Cause the thread to wake up and check its condition 68 // Cause the thread to wake up and check its condition
67 void wake(); 69 void wake();
@@ -79,7 +81,7 @@ public:
79 81
80private: 82private:
81 BOOL mPaused; 83 BOOL mPaused;
82 84
83 // static function passed to APR thread creation routine 85 // static function passed to APR thread creation routine
84 static void *APR_THREAD_FUNC staticRun(apr_thread_t *apr_threadp, void *datap); 86 static void *APR_THREAD_FUNC staticRun(apr_thread_t *apr_threadp, void *datap);
85 87
@@ -180,4 +182,67 @@ void LLThread::unlockData()
180 182
181//============================================================================ 183//============================================================================
182 184
185// see llmemory.h for LLPointer<> definition
186
187class LLThreadSafeRefCount
188{
189public:
190 static void initClass(); // creates sMutex
191 static void cleanupClass(); // destroys sMutex
192
193private:
194 static LLMutex* sMutex;
195
196private:
197 LLThreadSafeRefCount(const LLThreadSafeRefCount&); // not implemented
198 LLThreadSafeRefCount&operator=(const LLThreadSafeRefCount&); // not implemented
199
200protected:
201 virtual ~LLThreadSafeRefCount(); // use unref()
202
203public:
204 LLThreadSafeRefCount();
205
206 void ref()
207 {
208 if (sMutex) sMutex->lock();
209 mRef++;
210 if (sMutex) sMutex->unlock();
211 }
212
213 S32 unref()
214 {
215 llassert(mRef >= 1);
216 if (sMutex) sMutex->lock();
217 S32 res = --mRef;
218 if (sMutex) sMutex->unlock();
219 if (0 == res)
220 {
221 delete this;
222 res = 0;
223 }
224 return res;
225 }
226 S32 getNumRefs() const
227 {
228 return mRef;
229 }
230
231private:
232 S32 mRef;
233};
234
235//============================================================================
236
237// Simple responder for self destructing callbacks
238// Pure virtual class
239class LLResponder : public LLThreadSafeRefCount
240{
241public:
242 virtual ~LLResponder();
243 virtual void completed(bool success) = 0;
244};
245
246//============================================================================
247
183#endif // LL_LLTHREAD_H 248#endif // LL_LLTHREAD_H