diff options
author | Jacek Antonelli | 2008-08-15 23:44:50 -0500 |
---|---|---|
committer | Jacek Antonelli | 2008-08-15 23:44:50 -0500 |
commit | 89fe5dab825a62a0e3fd8d248cbc91c65eb2a426 (patch) | |
tree | bcff14b7888d04a2fec799c59369f6095224bd08 /linden/indra/llcommon/llthread.h | |
parent | Second Life viewer sources 1.13.3.2 (diff) | |
download | meta-impy-89fe5dab825a62a0e3fd8d248cbc91c65eb2a426.zip meta-impy-89fe5dab825a62a0e3fd8d248cbc91c65eb2a426.tar.gz meta-impy-89fe5dab825a62a0e3fd8d248cbc91c65eb2a426.tar.bz2 meta-impy-89fe5dab825a62a0e3fd8d248cbc91c65eb2a426.tar.xz |
Second Life viewer sources 1.14.0.0
Diffstat (limited to 'linden/indra/llcommon/llthread.h')
-rw-r--r-- | linden/indra/llcommon/llthread.h | 75 |
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. |
60 | public: | 62 | public: |
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 | ||
80 | private: | 82 | private: |
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 | |||
187 | class LLThreadSafeRefCount | ||
188 | { | ||
189 | public: | ||
190 | static void initClass(); // creates sMutex | ||
191 | static void cleanupClass(); // destroys sMutex | ||
192 | |||
193 | private: | ||
194 | static LLMutex* sMutex; | ||
195 | |||
196 | private: | ||
197 | LLThreadSafeRefCount(const LLThreadSafeRefCount&); // not implemented | ||
198 | LLThreadSafeRefCount&operator=(const LLThreadSafeRefCount&); // not implemented | ||
199 | |||
200 | protected: | ||
201 | virtual ~LLThreadSafeRefCount(); // use unref() | ||
202 | |||
203 | public: | ||
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 | |||
231 | private: | ||
232 | S32 mRef; | ||
233 | }; | ||
234 | |||
235 | //============================================================================ | ||
236 | |||
237 | // Simple responder for self destructing callbacks | ||
238 | // Pure virtual class | ||
239 | class LLResponder : public LLThreadSafeRefCount | ||
240 | { | ||
241 | public: | ||
242 | virtual ~LLResponder(); | ||
243 | virtual void completed(bool success) = 0; | ||
244 | }; | ||
245 | |||
246 | //============================================================================ | ||
247 | |||
183 | #endif // LL_LLTHREAD_H | 248 | #endif // LL_LLTHREAD_H |