summaryrefslogtreecommitdiff
path: root/indra/llcommon/llthread.h
diff options
context:
space:
mode:
authorSteven Bennetts <steve@lindenlab.com>2007-03-02 21:25:50 +0000
committerSteven Bennetts <steve@lindenlab.com>2007-03-02 21:25:50 +0000
commit4dabd9c0472deb49573fdafef2fa413e59703f19 (patch)
tree06c680d6a2047e03838d6548bccd26c7baf9d652 /indra/llcommon/llthread.h
parentd4462963c6ba5db2088723bbedc7b60f1184c594 (diff)
merge release@58699 beta-1-14-0@58707 -> release
Diffstat (limited to 'indra/llcommon/llthread.h')
-rw-r--r--indra/llcommon/llthread.h75
1 files changed, 70 insertions, 5 deletions
diff --git a/indra/llcommon/llthread.h b/indra/llcommon/llthread.h
index f6f6bd210a..ce5daa938c 100644
--- a/indra/llcommon/llthread.h
+++ b/indra/llcommon/llthread.h
@@ -11,6 +11,7 @@
#include "llapr.h"
#include "llapp.h"
+#include "llmemory.h"
#include "apr-1/apr_thread_cond.h"
@@ -30,19 +31,20 @@ public:
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
+
static void yield(); // Static because it can be called by the main thread, which doesn't have an LLThread data structure.
- bool isQuitting() const;
- bool isStopped() const;
+ bool isQuitting() const { return (QUITTING == mStatus); }
+ bool isStopped() const { return (STOPPED == mStatus); }
// PAUSE / RESUME functionality. See source code for important usage notes.
public:
// Called from MAIN THREAD.
void pause();
void unpause();
- bool isPaused() { return mPaused ? true : false; }
+ bool isPaused() { return isStopped() || mPaused == TRUE; }
// Cause the thread to wake up and check its condition
void wake();
@@ -60,7 +62,7 @@ public:
private:
BOOL mPaused;
-
+
// static function passed to APR thread creation routine
static void *APR_THREAD_FUNC staticRun(apr_thread_t *apr_threadp, void *datap);
@@ -161,4 +163,67 @@ void LLThread::unlockData()
//============================================================================
+// see llmemory.h for LLPointer<> definition
+
+class LLThreadSafeRefCount
+{
+public:
+ static void initClass(); // creates sMutex
+ static void cleanupClass(); // destroys sMutex
+
+private:
+ static LLMutex* sMutex;
+
+private:
+ LLThreadSafeRefCount(const LLThreadSafeRefCount&); // not implemented
+ LLThreadSafeRefCount&operator=(const LLThreadSafeRefCount&); // not implemented
+
+protected:
+ virtual ~LLThreadSafeRefCount(); // use unref()
+
+public:
+ LLThreadSafeRefCount();
+
+ void ref()
+ {
+ if (sMutex) sMutex->lock();
+ mRef++;
+ if (sMutex) sMutex->unlock();
+ }
+
+ S32 unref()
+ {
+ llassert(mRef >= 1);
+ if (sMutex) sMutex->lock();
+ S32 res = --mRef;
+ if (sMutex) sMutex->unlock();
+ if (0 == res)
+ {
+ delete this;
+ res = 0;
+ }
+ return res;
+ }
+ S32 getNumRefs() const
+ {
+ return mRef;
+ }
+
+private:
+ S32 mRef;
+};
+
+//============================================================================
+
+// Simple responder for self destructing callbacks
+// Pure virtual class
+class LLResponder : public LLThreadSafeRefCount
+{
+public:
+ virtual ~LLResponder();
+ virtual void completed(bool success) = 0;
+};
+
+//============================================================================
+
#endif // LL_LLTHREAD_H