summaryrefslogtreecommitdiff
path: root/indra/llcorehttp/httpcommon.cpp
diff options
context:
space:
mode:
authorNat Goodspeed <nat@lindenlab.com>2019-12-06 16:31:49 -0500
committerNat Goodspeed <nat@lindenlab.com>2020-03-25 15:28:17 -0400
commit5e7df752a66b2082d063d2c4a10bc7013d479f55 (patch)
tree35d0a70687b3516a4486b001f71f571cc7c31251 /indra/llcorehttp/httpcommon.cpp
parentd6baa7a8533a65174f96051c67f7d8b5b160394f (diff)
DRTVWR-494: Use std::thread::id for LLThread::currentID().
LLThread::currentID() used to return a U32, a distinct unsigned value incremented by explicitly constructing LLThread or by calling LLThread:: registerThreadID() early in a thread launched by other means. The latter imposed an unobvious requirement on new code based on std::thread. Using std::thread::id instead delegates to the compiler/library the problem of distinguishing threads launched by any means. Change lots of explicit U32 declarations. Introduce LLThread::id_t typedef to avoid having to run around fixing uses again if we later revisit this decision. LLMutex, which stores an LLThread::id_t, wants a distinguished value meaning NO_THREAD, and had an enum with that name. But as std::thread::id promises that the default-constructed value is distinct from every valid value, NO_THREAD becomes unnecessary and goes away. Because LLMutex now stores LLThread::id_t instead of U32, make llmutex.h #include "llthread.h" instead of the other way around. This makes LLMutex an incomplete type within llthread.h, so move LLThread::lockData() and unlockData() to the .cpp file. Similarly, remove llrefcount.h's #include "llmutex.h" to break circularity; instead forward-declare LLMutex. It turns out that a number of source files assumed that #include "llthread.h" would get the definition for LLMutex. Sprinkle #include "llmutex.h" as needed. In the SAFE_SSL code in llcorehttp/httpcommon.cpp, there's an ssl_thread_id() callback that returns an unsigned long to the SSL library. When LLThread:: currentID() was U32, we could simply return that. But std::thread::id is very deliberately opaque, and can't be reinterpret_cast to unsigned long. Fortunately it can be hashed because std::hash is specialized with that type.
Diffstat (limited to 'indra/llcorehttp/httpcommon.cpp')
-rw-r--r--indra/llcorehttp/httpcommon.cpp4
1 files changed, 3 insertions, 1 deletions
diff --git a/indra/llcorehttp/httpcommon.cpp b/indra/llcorehttp/httpcommon.cpp
index 7c93c54cdf..e37a38b05f 100644
--- a/indra/llcorehttp/httpcommon.cpp
+++ b/indra/llcorehttp/httpcommon.cpp
@@ -40,6 +40,7 @@
#include <sstream>
#if SAFE_SSL
#include <openssl/crypto.h>
+#include <functional> // std::hash
#endif
@@ -369,7 +370,8 @@ void ssl_locking_callback(int mode, int type, const char *file, int line)
//static
unsigned long ssl_thread_id(void)
{
- return LLThread::currentID();
+ // std::thread::id is very deliberately opaque, but we can hash it
+ return std::hash<LLThread::id_t>()(LLThread::currentID());
}
#endif