summaryrefslogtreecommitdiff
path: root/indra
diff options
context:
space:
mode:
Diffstat (limited to 'indra')
-rw-r--r--indra/llcommon/classic_callback.h10
-rw-r--r--indra/llcommon/llrand.cpp14
-rw-r--r--indra/llcommon/llthread.cpp13
-rw-r--r--indra/llcommon/llthread.h2
-rw-r--r--indra/llcommon/stdtypes.h18
-rw-r--r--indra/llmessage/llxfer.cpp9
6 files changed, 27 insertions, 39 deletions
diff --git a/indra/llcommon/classic_callback.h b/indra/llcommon/classic_callback.h
index 1ad6dbc58f..009c25d67c 100644
--- a/indra/llcommon/classic_callback.h
+++ b/indra/llcommon/classic_callback.h
@@ -119,11 +119,11 @@ public:
* ClassicCallback must not itself be copied or moved! Once you've passed
* get_userdata() to some API, this object MUST remain at that address.
*/
- // However, we can't yet count on C++17 Class Template Argument Deduction,
- // which means makeClassicCallback() is still useful, which means we MUST
- // be able to return one to construct into caller's instance (move ctor).
- // Possible defense: bool 'referenced' data member set by get_userdata(),
- // with an llassert_always(! referenced) check in the move constructor.
+ // However, makeClassicCallback() is useful for deducing the CALLABLE
+ // type, which means we MUST be able to return one to construct into
+ // caller's instance (move ctor). Possible defense: bool 'referenced' data
+ // member set by get_userdata(), with an llassert_always(! referenced)
+ // check in the move constructor.
ClassicCallback(ClassicCallback const&) = delete;
ClassicCallback(ClassicCallback&&) = default; // delete;
ClassicCallback& operator=(ClassicCallback const&) = delete;
diff --git a/indra/llcommon/llrand.cpp b/indra/llcommon/llrand.cpp
index 33afc50cf7..e4065e23bf 100644
--- a/indra/llcommon/llrand.cpp
+++ b/indra/llcommon/llrand.cpp
@@ -58,7 +58,9 @@
* to restore uniform distribution.
*/
-static LLRandLagFib2281 gRandomGenerator(LLUUID::getRandomSeed());
+// gRandomGenerator is a stateful static object, which is therefore not
+// inherently thread-safe.
+static thread_local LLRandLagFib2281 gRandomGenerator(LLUUID::getRandomSeed());
// no default implementation, only specific F64 and F32 specializations
template <typename REAL>
@@ -71,7 +73,7 @@ inline F64 ll_internal_random<F64>()
// CPUs (or at least multi-threaded processes) seem to
// occasionally give an obviously incorrect random number -- like
// 5^15 or something. Sooooo, clamp it as described above.
- F64 rv = gRandomGenerator();
+ F64 rv{ gRandomGenerator() };
if(!((rv >= 0.0) && (rv < 1.0))) return fmod(rv, 1.0);
return rv;
}
@@ -79,7 +81,13 @@ inline F64 ll_internal_random<F64>()
template <>
inline F32 ll_internal_random<F32>()
{
- return F32(ll_internal_random<F64>());
+ // *HACK: clamp the result as described above.
+ // Per Monty, it's important to clamp using the correct fmodf() rather
+ // than expanding to F64 for fmod() and then truncating back to F32. Prior
+ // to this change, we were getting sporadic ll_frand() == 1.0 results.
+ F32 rv{ narrow(gRandomGenerator()) };
+ if(!((rv >= 0.0f) && (rv < 1.0f))) return fmodf(rv, 1.0f);
+ return rv;
}
/*------------------------------ F64 aliases -------------------------------*/
diff --git a/indra/llcommon/llthread.cpp b/indra/llcommon/llthread.cpp
index 4eaa05c335..cd4975d9d3 100644
--- a/indra/llcommon/llthread.cpp
+++ b/indra/llcommon/llthread.cpp
@@ -113,15 +113,16 @@ LL_COMMON_API bool on_main_thread()
return (LLThread::currentID() == main_thread());
}
-LL_COMMON_API void assert_main_thread()
+LL_COMMON_API bool assert_main_thread()
{
auto curr = LLThread::currentID();
auto main = main_thread();
- if (curr != main)
- {
- LL_WARNS() << "Illegal execution from thread id " << curr
- << " outside main thread " << main << LL_ENDL;
- }
+ if (curr == main)
+ return true;
+
+ LL_WARNS() << "Illegal execution from thread id " << curr
+ << " outside main thread " << main << LL_ENDL;
+ return false;
}
// this function has become moot
diff --git a/indra/llcommon/llthread.h b/indra/llcommon/llthread.h
index 50202631e7..9f1c589fcd 100644
--- a/indra/llcommon/llthread.h
+++ b/indra/llcommon/llthread.h
@@ -152,7 +152,7 @@ public:
//============================================================================
-extern LL_COMMON_API void assert_main_thread();
+extern LL_COMMON_API bool assert_main_thread();
extern LL_COMMON_API bool on_main_thread();
#endif // LL_LLTHREAD_H
diff --git a/indra/llcommon/stdtypes.h b/indra/llcommon/stdtypes.h
index 0b43d7ad4b..3aba9dda00 100644
--- a/indra/llcommon/stdtypes.h
+++ b/indra/llcommon/stdtypes.h
@@ -156,18 +156,15 @@ typedef int intptr_t;
* type.
*/
// narrow_holder is a struct that accepts the passed value as its original
-// type and provides templated conversion functions to other types. Once we're
-// building with compilers that support Class Template Argument Deduction, we
-// can rename this class template 'narrow' and eliminate the narrow() factory
-// function below.
+// type and provides templated conversion functions to other types.
template <typename FROM>
-class narrow_holder
+class narrow
{
private:
FROM mValue;
public:
- narrow_holder(FROM value): mValue(value) {}
+ narrow(FROM value): mValue(value) {}
/*---------------------- Narrowing unsigned to signed ----------------------*/
template <typename TO,
@@ -207,13 +204,4 @@ public:
}
};
-/// narrow() factory function returns a narrow_holder<FROM>(), which can be
-/// implicitly converted to the target type.
-template <typename FROM>
-inline
-narrow_holder<FROM> narrow(FROM value)
-{
- return { value };
-}
-
#endif
diff --git a/indra/llmessage/llxfer.cpp b/indra/llmessage/llxfer.cpp
index 93d5cfc131..212d0619d1 100644
--- a/indra/llmessage/llxfer.cpp
+++ b/indra/llmessage/llxfer.cpp
@@ -386,12 +386,3 @@ std::ostream& operator<< (std::ostream& os, LLXfer &hh)
os << hh.getFileName() ;
return os;
}
-
-
-
-
-
-
-
-
-