Skip to content

Instantly share code, notes, and snippets.

@jamesob
Created May 8, 2018 17:00
Show Gist options
  • Save jamesob/7759579c2ece06e9fa7db43652a47600 to your computer and use it in GitHub Desktop.
Save jamesob/7759579c2ece06e9fa7db43652a47600 to your computer and use it in GitHub Desktop.
git diff threadnames2.5..threadnames2.6
diff --git a/src/threadutil.cpp b/src/threadutil.cpp
index 6ad720c..29bae65 100644
--- a/src/threadutil.cpp
+++ b/src/threadutil.cpp
@@ -12,8 +12,9 @@
#include <threadutil.h>
/*
- * TODO: using thread_local changes the abi in ways that may not play nice
- * when the c++ stdlib is linked dynamically. Disable it until thorough
+ * TODO: We'd like to use thread_local instead of the more involved implementations
+ * below, but it changes the abi in ways that may not play nice
+ * when the c++ stdlib is linked dynamically. Don't use it until thorough
* testing has been done.
*
* mingw32's implementation of thread_local has also been shown to behave
@@ -21,7 +22,6 @@
*
* https://gist.github.com/jamesob/fe9a872051a88b2025b1aa37bfa98605
*/
-#undef HAVE_THREAD_LOCAL
#ifdef HAVE_SYS_PRCTL_H
#include <sys/prctl.h> // For prctl, PR_SET_NAME, PR_GET_NAME
@@ -31,9 +31,7 @@
#include <pthread_np.h>
#endif
-#if defined(HAVE_THREAD_LOCAL)
-
-#elif defined(HAVE_PTHREAD)
+#if defined(HAVE_PTHREAD)
#include <pthread.h>
#else
@@ -88,34 +86,14 @@ void thread_util::Rename(std::string name)
}
/*
- * What follows are three separate platform-dependent implementations of
+ * What follows are separate platform-dependent implementations of
* *name and *id parts of the thread_utils interface. Each implementation
* emulates thread_local storage.
*
- * If we have thread_local, just keep thread ID and name in a thread_local
- * global.
- */
-#if defined(HAVE_THREAD_LOCAL)
-
-static thread_local thread_data_type g_thread_data;
-std::string thread_util::GetInternalName()
-{
- return g_thread_data.m_name;
-}
-
-bool thread_util::SetInternalName(std::string name)
-{
- static std::atomic<long> id_accumulator{0};
- static thread_local thread_id{id_accumulator++};
- g_thread_data = {thread_id, std::move(name)};
- return true;
-}
-
-/*
- * Otherwise if we don't have use of thread_local, use the pthreads interface
+ * In this implementation, use the pthreads interface
* to stash thread data in thread-specific key using getspecific/setspecific.
*/
-#elif defined(HAVE_PTHREAD)
+#if defined(HAVE_PTHREAD)
static pthread_key_t g_key;
static void destruct_data(void* data)
@@ -160,7 +138,7 @@ bool thread_util::SetInternalName(std::string name)
}
/*
- * As a final fallback, maintain thread data in a shared map guarded by a
+ * As a fallback, maintain thread data in a shared map guarded by a
* mutex.
*/
#else
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment