aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Saleem Abdulrasool <compnerd@compnerd.org> 2016-01-28 18:19:36 -0800
committerAvatar Saleem Abdulrasool <compnerd@compnerd.org> 2016-02-14 23:12:29 -0800
commite42d5ffe29b4cd6cf9bac0f36fe37ec5001dfd68 (patch)
tree618a32afdb1555e9944e68f379695b7dfe6a1234
parente0f11780797f6ddee5bdfd965c7f499e8810c2b4 (diff)
downloadpaludis-e42d5ffe29b4cd6cf9bac0f36fe37ec5001dfd68.tar.gz
paludis-e42d5ffe29b4cd6cf9bac0f36fe37ec5001dfd68.tar.xz
switch TLS to C++11 TLS semantics
Rather than using the compiler specific `__thread` mechanism for TLS, use the C++11 standard `thread_local` keyword. This removes the check for the `__thread` keyword and the `PALUDIS_TLS` macro in the single usage site. Take advantage of the fact that `thread_local` can be applied to non-POD types to avoid the heap allocation of the context buffer and letting the loader perform the allocation. This has a slight penalty (an extra function call) on thread construction. However, given that the heap allocation would likely be performed, this will be largely offset by the loss of the allocation.
-rw-r--r--configure.ac11
-rw-r--r--paludis/util/attributes.hh2
-rw-r--r--paludis/util/exception.cc22
3 files changed, 7 insertions, 28 deletions
diff --git a/configure.ac b/configure.ac
index da6ee9b..7c1fe4f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -235,17 +235,6 @@ fi
PTHREAD_LIBS=""
RT_LIBS=""
-AC_MSG_CHECKING([for compiler __thread support])
-AC_COMPILE_IFELSE([AC_LANG_SOURCE([
-int main(int, char **)
-{
- static __thread int x(0);
- return x;
-}
-])],
-[AC_MSG_RESULT([yes])],
-[AC_MSG_RESULT([no])
-AC_MSG_ERROR([Your compiler does not support __thread])])
AC_MSG_CHECKING([whether -pthread -lpthread gets us posix threads])
save_CXXFLAGS=$CXXFLAGS
diff --git a/paludis/util/attributes.hh b/paludis/util/attributes.hh
index 270fbc3..88877f6 100644
--- a/paludis/util/attributes.hh
+++ b/paludis/util/attributes.hh
@@ -63,6 +63,4 @@
# define PALUDIS_HIDDEN PALUDIS_ATTRIBUTE((visibility("hidden")))
#endif
-#define PALUDIS_TLS static __thread
-
#endif
diff --git a/paludis/util/exception.cc b/paludis/util/exception.cc
index 391f1e4..d0ce9d2 100644
--- a/paludis/util/exception.cc
+++ b/paludis/util/exception.cc
@@ -35,35 +35,28 @@ using namespace paludis;
namespace
{
- PALUDIS_TLS std::list<std::string> * context = 0;
+ static thread_local std::list<std::string> context;
}
Context::Context(const std::string & s)
{
- if (! context)
- context = new std::list<std::string>;
- context->push_back(s);
+ context.push_back(s);
}
Context::~Context() noexcept(false)
{
- if (! context)
+ if (context.empty())
throw InternalError(PALUDIS_HERE, "no context");
- context->pop_back();
- if (context->empty())
- {
- delete context;
- context = 0;
- }
+ context.pop_back();
}
std::string
Context::backtrace(const std::string & delim)
{
- if (! context)
+ if (context.empty())
return "";
- return join(context->begin(), context->end(), delim) + delim;
+ return join(context.begin(), context.end(), delim) + delim;
}
namespace paludis
@@ -74,8 +67,7 @@ namespace paludis
ContextData()
{
- if (context)
- local_context.assign(context->begin(), context->end());
+ local_context.assign(context.begin(), context.end());
}
ContextData(const ContextData & other) :