summaryrefslogtreecommitdiff
path: root/indra/llcommon
diff options
context:
space:
mode:
Diffstat (limited to 'indra/llcommon')
-rw-r--r--indra/llcommon/llapp.cpp8
-rw-r--r--indra/llcommon/llapp.h1
-rw-r--r--indra/llcommon/lldictionary.h3
-rw-r--r--indra/llcommon/llpointer.h145
-rw-r--r--indra/llcommon/llrefcount.cpp4
-rw-r--r--indra/llcommon/llrefcount.h46
-rw-r--r--indra/llcommon/threadpool.cpp12
-rw-r--r--indra/llcommon/threadpool.h3
8 files changed, 110 insertions, 112 deletions
diff --git a/indra/llcommon/llapp.cpp b/indra/llcommon/llapp.cpp
index b99166991f..90d0c28eb1 100644
--- a/indra/llcommon/llapp.cpp
+++ b/indra/llcommon/llapp.cpp
@@ -104,7 +104,6 @@ BOOL LLApp::sLogInSignal = FALSE;
// Keeps track of application status
LLScalarCond<LLApp::EAppStatus> LLApp::sStatus{LLApp::APP_STATUS_STOPPED};
LLAppErrorHandler LLApp::sErrorHandler = NULL;
-BOOL LLApp::sErrorThreadRunning = FALSE;
LLApp::LLApp()
@@ -787,13 +786,8 @@ void default_unix_signal_handler(int signum, siginfo_t *info, void *)
return;
}
- // Flag status to ERROR, so thread_error does its work.
+ // Flag status to ERROR
LLApp::setError();
- // Block in the signal handler until somebody says that we're done.
- while (LLApp::sErrorThreadRunning && !LLApp::isStopped())
- {
- ms_sleep(10);
- }
if (LLApp::sLogInSignal)
{
diff --git a/indra/llcommon/llapp.h b/indra/llcommon/llapp.h
index c832c8b142..a892bfeb1e 100644
--- a/indra/llcommon/llapp.h
+++ b/indra/llcommon/llapp.h
@@ -291,7 +291,6 @@ protected:
static void setStatus(EAppStatus status); // Use this to change the application status.
static LLScalarCond<EAppStatus> sStatus; // Reflects current application status
- static BOOL sErrorThreadRunning; // Set while the error thread is running
static BOOL sDisableCrashlogger; // Let the OS handle crashes for us.
std::wstring mCrashReportPipeStr; //Name of pipe to use for crash reporting.
diff --git a/indra/llcommon/lldictionary.h b/indra/llcommon/lldictionary.h
index 5800ec5e5d..3e86767d7e 100644
--- a/indra/llcommon/lldictionary.h
+++ b/indra/llcommon/lldictionary.h
@@ -87,11 +87,10 @@ protected:
}
void addEntry(Index index, Entry *entry)
{
- if (lookup(index))
+ if (!insert(value_type(index, entry)).second)
{
LL_ERRS() << "Dictionary entry already added (attempted to add duplicate entry)" << LL_ENDL;
}
- (*this)[index] = entry;
}
};
diff --git a/indra/llcommon/llpointer.h b/indra/llcommon/llpointer.h
index 9a6453ea48..96ccfb481e 100644
--- a/indra/llcommon/llpointer.h
+++ b/indra/llcommon/llpointer.h
@@ -46,33 +46,32 @@
template <class Type> class LLPointer
{
public:
-
- LLPointer() :
+ LLPointer() :
mPointer(NULL)
{
}
- LLPointer(Type* ptr) :
+ LLPointer(Type* ptr) :
mPointer(ptr)
{
ref();
}
- LLPointer(const LLPointer<Type>& ptr) :
+ LLPointer(const LLPointer<Type>& ptr) :
mPointer(ptr.mPointer)
{
ref();
}
- // support conversion up the type hierarchy. See Item 45 in Effective C++, 3rd Ed.
+ // Support conversion up the type hierarchy. See Item 45 in Effective C++, 3rd Ed.
template<typename Subclass>
- LLPointer(const LLPointer<Subclass>& ptr) :
+ LLPointer(const LLPointer<Subclass>& ptr) :
mPointer(ptr.get())
{
ref();
}
- ~LLPointer()
+ ~LLPointer()
{
unref();
}
@@ -83,39 +82,39 @@ public:
const Type& operator*() const { return *mPointer; }
Type& operator*() { return *mPointer; }
- operator BOOL() const { return (mPointer != NULL); }
- operator bool() const { return (mPointer != NULL); }
+ operator BOOL() const { return (mPointer != NULL); }
+ operator bool() const { return (mPointer != NULL); }
bool operator!() const { return (mPointer == NULL); }
bool isNull() const { return (mPointer == NULL); }
bool notNull() const { return (mPointer != NULL); }
- operator Type*() const { return mPointer; }
- bool operator !=(Type* ptr) const { return (mPointer != ptr); }
- bool operator ==(Type* ptr) const { return (mPointer == ptr); }
- bool operator ==(const LLPointer<Type>& ptr) const { return (mPointer == ptr.mPointer); }
- bool operator < (const LLPointer<Type>& ptr) const { return (mPointer < ptr.mPointer); }
- bool operator > (const LLPointer<Type>& ptr) const { return (mPointer > ptr.mPointer); }
+ operator Type*() const { return mPointer; }
+ bool operator !=(Type* ptr) const { return (mPointer != ptr); }
+ bool operator ==(Type* ptr) const { return (mPointer == ptr); }
+ bool operator ==(const LLPointer<Type>& ptr) const { return (mPointer == ptr.mPointer); }
+ bool operator < (const LLPointer<Type>& ptr) const { return (mPointer < ptr.mPointer); }
+ bool operator > (const LLPointer<Type>& ptr) const { return (mPointer > ptr.mPointer); }
- LLPointer<Type>& operator =(Type* ptr)
- {
+ LLPointer<Type>& operator =(Type* ptr)
+ {
assign(ptr);
- return *this;
+ return *this;
}
- LLPointer<Type>& operator =(const LLPointer<Type>& ptr)
- {
+ LLPointer<Type>& operator =(const LLPointer<Type>& ptr)
+ {
assign(ptr);
- return *this;
+ return *this;
}
// support assignment up the type hierarchy. See Item 45 in Effective C++, 3rd Ed.
template<typename Subclass>
- LLPointer<Type>& operator =(const LLPointer<Subclass>& ptr)
- {
+ LLPointer<Type>& operator =(const LLPointer<Subclass>& ptr)
+ {
assign(ptr.get());
- return *this;
+ return *this;
}
-
+
// Just exchange the pointers, which will not change the reference counts.
static void swap(LLPointer<Type>& a, LLPointer<Type>& b)
{
@@ -129,16 +128,6 @@ protected:
void ref();
void unref();
#else
-
- void assign(const LLPointer<Type>& ptr)
- {
- if( mPointer != ptr.mPointer )
- {
- unref();
- mPointer = ptr.mPointer;
- ref();
- }
- }
void ref()
{
if (mPointer)
@@ -161,7 +150,18 @@ protected:
}
}
}
-#endif
+#endif // LL_LIBRARY_INCLUDE
+
+ void assign(const LLPointer<Type>& ptr)
+ {
+ if (mPointer != ptr.mPointer)
+ {
+ unref();
+ mPointer = ptr.mPointer;
+ ref();
+ }
+ }
+
protected:
Type* mPointer;
};
@@ -169,18 +169,18 @@ protected:
template <class Type> class LLConstPointer
{
public:
- LLConstPointer() :
+ LLConstPointer() :
mPointer(NULL)
{
}
- LLConstPointer(const Type* ptr) :
+ LLConstPointer(const Type* ptr) :
mPointer(ptr)
{
ref();
}
- LLConstPointer(const LLConstPointer<Type>& ptr) :
+ LLConstPointer(const LLConstPointer<Type>& ptr) :
mPointer(ptr.mPointer)
{
ref();
@@ -188,7 +188,7 @@ public:
// support conversion up the type hierarchy. See Item 45 in Effective C++, 3rd Ed.
template<typename Subclass>
- LLConstPointer(const LLConstPointer<Subclass>& ptr) :
+ LLConstPointer(const LLConstPointer<Subclass>& ptr) :
mPointer(ptr.get())
{
ref();
@@ -203,55 +203,55 @@ public:
const Type* operator->() const { return mPointer; }
const Type& operator*() const { return *mPointer; }
- operator BOOL() const { return (mPointer != NULL); }
- operator bool() const { return (mPointer != NULL); }
+ operator BOOL() const { return (mPointer != NULL); }
+ operator bool() const { return (mPointer != NULL); }
bool operator!() const { return (mPointer == NULL); }
bool isNull() const { return (mPointer == NULL); }
bool notNull() const { return (mPointer != NULL); }
- operator const Type*() const { return mPointer; }
- bool operator !=(const Type* ptr) const { return (mPointer != ptr); }
- bool operator ==(const Type* ptr) const { return (mPointer == ptr); }
- bool operator ==(const LLConstPointer<Type>& ptr) const { return (mPointer == ptr.mPointer); }
- bool operator < (const LLConstPointer<Type>& ptr) const { return (mPointer < ptr.mPointer); }
- bool operator > (const LLConstPointer<Type>& ptr) const { return (mPointer > ptr.mPointer); }
+ operator const Type*() const { return mPointer; }
+ bool operator !=(const Type* ptr) const { return (mPointer != ptr); }
+ bool operator ==(const Type* ptr) const { return (mPointer == ptr); }
+ bool operator ==(const LLConstPointer<Type>& ptr) const { return (mPointer == ptr.mPointer); }
+ bool operator < (const LLConstPointer<Type>& ptr) const { return (mPointer < ptr.mPointer); }
+ bool operator > (const LLConstPointer<Type>& ptr) const { return (mPointer > ptr.mPointer); }
- LLConstPointer<Type>& operator =(const Type* ptr)
+ LLConstPointer<Type>& operator =(const Type* ptr)
{
if( mPointer != ptr )
{
- unref();
- mPointer = ptr;
+ unref();
+ mPointer = ptr;
ref();
}
- return *this;
+ return *this;
}
- LLConstPointer<Type>& operator =(const LLConstPointer<Type>& ptr)
- {
+ LLConstPointer<Type>& operator =(const LLConstPointer<Type>& ptr)
+ {
if( mPointer != ptr.mPointer )
{
- unref();
+ unref();
mPointer = ptr.mPointer;
ref();
}
- return *this;
+ return *this;
}
// support assignment up the type hierarchy. See Item 45 in Effective C++, 3rd Ed.
template<typename Subclass>
- LLConstPointer<Type>& operator =(const LLConstPointer<Subclass>& ptr)
- {
+ LLConstPointer<Type>& operator =(const LLConstPointer<Subclass>& ptr)
+ {
if( mPointer != ptr.get() )
{
- unref();
+ unref();
mPointer = ptr.get();
ref();
}
- return *this;
+ return *this;
}
-
+
// Just exchange the pointers, which will not change the reference counts.
static void swap(LLConstPointer<Type>& a, LLConstPointer<Type>& b)
{
@@ -262,11 +262,11 @@ public:
protected:
#ifdef LL_LIBRARY_INCLUDE
- void ref();
+ void ref();
void unref();
-#else
- void ref()
- {
+#else // LL_LIBRARY_INCLUDE
+ void ref()
+ {
if (mPointer)
{
mPointer->ref();
@@ -277,9 +277,9 @@ protected:
{
if (mPointer)
{
- const Type *tempp = mPointer;
+ const Type *temp = mPointer;
mPointer = NULL;
- tempp->unref();
+ temp->unref();
if (mPointer != NULL)
{
LL_WARNS() << "Unreference did assignment to non-NULL because of destructor" << LL_ENDL;
@@ -287,7 +287,8 @@ protected:
}
}
}
-#endif
+#endif // LL_LIBRARY_INCLUDE
+
protected:
const Type* mPointer;
};
@@ -297,13 +298,13 @@ class LLCopyOnWritePointer : public LLPointer<Type>
{
public:
typedef LLCopyOnWritePointer<Type> self_t;
- typedef LLPointer<Type> pointer_t;
-
- LLCopyOnWritePointer()
+ typedef LLPointer<Type> pointer_t;
+
+ LLCopyOnWritePointer()
: mStayUnique(false)
{}
- LLCopyOnWritePointer(Type* ptr)
+ LLCopyOnWritePointer(Type* ptr)
: LLPointer<Type>(ptr),
mStayUnique(false)
{}
diff --git a/indra/llcommon/llrefcount.cpp b/indra/llcommon/llrefcount.cpp
index 6852b5536a..3da94e7a8d 100644
--- a/indra/llcommon/llrefcount.cpp
+++ b/indra/llcommon/llrefcount.cpp
@@ -30,7 +30,7 @@
#include "llerror.h"
// maximum reference count before sounding memory leak alarm
-const S32 gMaxRefCount = S32_MAX;
+const S32 gMaxRefCount = LL_REFCOUNT_FREE;
LLRefCount::LLRefCount(const LLRefCount& other)
: mRef(0)
@@ -49,7 +49,7 @@ LLRefCount::LLRefCount() :
}
LLRefCount::~LLRefCount()
-{
+{
if (mRef != LL_REFCOUNT_FREE && mRef != 0)
{
LL_ERRS() << "deleting non-zero reference" << LL_ENDL;
diff --git a/indra/llcommon/llrefcount.h b/indra/llcommon/llrefcount.h
index 2080da1565..15e7175fc8 100644
--- a/indra/llcommon/llrefcount.h
+++ b/indra/llcommon/llrefcount.h
@@ -51,24 +51,20 @@ protected:
public:
LLRefCount();
- inline void validateRefCount() const
- {
- llassert(mRef > 0); // ref count below 0, likely corrupted
- llassert(mRef < gMaxRefCount); // ref count excessive, likely memory leak
- }
-
inline void ref() const
- {
- mRef++;
- validateRefCount();
- }
+ {
+ llassert(mRef != LL_REFCOUNT_FREE); // object is deleted
+ mRef++;
+ llassert(mRef < gMaxRefCount); // ref count excessive, likely memory leak
+ }
inline S32 unref() const
{
- validateRefCount();
+ llassert(mRef != LL_REFCOUNT_FREE); // object is deleted
+ llassert(mRef > 0); // ref count below 1, likely corrupted
if (0 == --mRef)
{
- mRef = LL_REFCOUNT_FREE; // set to nonsense yet recognizable value to aid in debugging
+ mRef = LL_REFCOUNT_FREE; // set to nonsense yet recognizable value to aid in debugging
delete this;
return 0;
}
@@ -82,8 +78,8 @@ public:
return mRef;
}
-private:
- mutable S32 mRef;
+private:
+ mutable S32 mRef;
};
@@ -106,7 +102,7 @@ protected:
public:
LLThreadSafeRefCount();
LLThreadSafeRefCount(const LLThreadSafeRefCount&);
- LLThreadSafeRefCount& operator=(const LLThreadSafeRefCount& ref)
+ LLThreadSafeRefCount& operator=(const LLThreadSafeRefCount& ref)
{
mRef = 0;
return *this;
@@ -114,8 +110,8 @@ public:
void ref()
{
- mRef++;
- }
+ mRef++;
+ }
void unref()
{
@@ -136,36 +132,36 @@ public:
return currentVal;
}
-private:
- LLAtomicS32 mRef;
+private:
+ LLAtomicS32 mRef;
};
/**
* intrusive pointer support for LLThreadSafeRefCount
* this allows you to use boost::intrusive_ptr with any LLThreadSafeRefCount-derived type
*/
-inline void intrusive_ptr_add_ref(LLThreadSafeRefCount* p)
+inline void intrusive_ptr_add_ref(LLThreadSafeRefCount* p)
{
p->ref();
}
-inline void intrusive_ptr_release(LLThreadSafeRefCount* p)
+inline void intrusive_ptr_release(LLThreadSafeRefCount* p)
{
- p->unref();
+ p->unref();
}
/**
* intrusive pointer support
* this allows you to use boost::intrusive_ptr with any LLRefCount-derived type
*/
-inline void intrusive_ptr_add_ref(LLRefCount* p)
+inline void intrusive_ptr_add_ref(LLRefCount* p)
{
p->ref();
}
-inline void intrusive_ptr_release(LLRefCount* p)
+inline void intrusive_ptr_release(LLRefCount* p)
{
- p->unref();
+ p->unref();
}
#endif
diff --git a/indra/llcommon/threadpool.cpp b/indra/llcommon/threadpool.cpp
index d5adf11264..22bbff4478 100644
--- a/indra/llcommon/threadpool.cpp
+++ b/indra/llcommon/threadpool.cpp
@@ -21,11 +21,12 @@
#include "llevents.h"
#include "stringize.h"
-LL::ThreadPool::ThreadPool(const std::string& name, size_t threads, size_t capacity):
+LL::ThreadPool::ThreadPool(const std::string& name, size_t threads, size_t capacity, bool auto_shutdown):
super(name),
mQueue(name, capacity),
mName("ThreadPool:" + name),
- mThreadCount(threads)
+ mThreadCount(threads),
+ mAutomaticShutdown(auto_shutdown)
{}
void LL::ThreadPool::start()
@@ -39,6 +40,13 @@ void LL::ThreadPool::start()
run(tname);
});
}
+
+ // Some threads might need to run longer than LLEventPumps
+ if (!mAutomaticShutdown)
+ {
+ return;
+ }
+
// Listen on "LLApp", and when the app is shutting down, close the queue
// and join the workers.
LLEventPumps::instance().obtain("LLApp").listen(
diff --git a/indra/llcommon/threadpool.h b/indra/llcommon/threadpool.h
index f8eec3b457..22c875edb9 100644
--- a/indra/llcommon/threadpool.h
+++ b/indra/llcommon/threadpool.h
@@ -31,7 +31,7 @@ namespace LL
* Pass ThreadPool a string name. This can be used to look up the
* relevant WorkQueue.
*/
- ThreadPool(const std::string& name, size_t threads=1, size_t capacity=1024);
+ ThreadPool(const std::string& name, size_t threads=1, size_t capacity=1024, bool auto_shutdown = true);
virtual ~ThreadPool();
/**
@@ -66,6 +66,7 @@ namespace LL
std::string mName;
size_t mThreadCount;
std::vector<std::pair<std::string, std::thread>> mThreads;
+ bool mAutomaticShutdown;
};
} // namespace LL