Commit 94f2fb53 authored by Frantisek Foston's avatar Frantisek Foston

pthreads are only used by XCode V7 and less

on OSX config.hpp will now define 'CAF_NO_THREAD_LOCAL' if the toolchain does not support it
parent cf0e7e2c
...@@ -101,6 +101,9 @@ ...@@ -101,6 +101,9 @@
# define CAF_ANNOTATE_FALLTHROUGH [[clang::fallthrough]] # define CAF_ANNOTATE_FALLTHROUGH [[clang::fallthrough]]
# define CAF_COMPILER_VERSION \ # define CAF_COMPILER_VERSION \
(__clang_major__ * 10000 + __clang_minor__ * 100 + __clang_patchlevel__) (__clang_major__ * 10000 + __clang_minor__ * 100 + __clang_patchlevel__)
# if !__has_feature(cxx_thread_local)
# define CAF_NO_THREAD_LOCAL
# endif
#elif defined(__GNUC__) #elif defined(__GNUC__)
# define CAF_GCC # define CAF_GCC
# define CAF_DEPRECATED __attribute__((__deprecated__)) # define CAF_DEPRECATED __attribute__((__deprecated__))
......
...@@ -62,19 +62,7 @@ constexpr const char* log_level_name[] = { ...@@ -62,19 +62,7 @@ constexpr const char* log_level_name[] = {
static_assert(CAF_LOG_LEVEL >= 0 && CAF_LOG_LEVEL <= 4, static_assert(CAF_LOG_LEVEL >= 0 && CAF_LOG_LEVEL <= 4,
"assertion: 0 <= CAF_LOG_LEVEL <= 4"); "assertion: 0 <= CAF_LOG_LEVEL <= 4");
#ifdef CAF_MSVC #if defined(CAF_NO_THREAD_LOCAL)
thread_local intrusive_ptr<logger> current_logger;
inline void set_current_logger(logger* x) {
current_logger.reset(x);
}
inline logger* get_current_logger() {
return current_logger.get();
}
#else // CAF_MSVC
pthread_key_t s_key; pthread_key_t s_key;
pthread_once_t s_key_once = PTHREAD_ONCE_INIT; pthread_once_t s_key_once = PTHREAD_ONCE_INIT;
...@@ -102,7 +90,19 @@ logger* get_current_logger() { ...@@ -102,7 +90,19 @@ logger* get_current_logger() {
return reinterpret_cast<logger*>(pthread_getspecific(s_key)); return reinterpret_cast<logger*>(pthread_getspecific(s_key));
} }
#endif // CAF_MSVC #else // !CAF_NO_THREAD_LOCAL
thread_local intrusive_ptr<logger> current_logger;
inline void set_current_logger(logger* x) {
current_logger.reset(x);
}
inline logger* get_current_logger() {
return current_logger.get();
}
#endif // CAF_NO_THREAD_LOCAL
#else // CAF_LOG_LEVEL #else // CAF_LOG_LEVEL
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
* http://www.boost.org/LICENSE_1_0.txt. * * http://www.boost.org/LICENSE_1_0.txt. *
******************************************************************************/ ******************************************************************************/
#include "caf/config.hpp"
#include "caf/detail/memory.hpp" #include "caf/detail/memory.hpp"
#include <vector> #include <vector>
...@@ -43,7 +44,8 @@ using cache_map = std::map<const std::type_info*, std::unique_ptr<memory_cache>> ...@@ -43,7 +44,8 @@ using cache_map = std::map<const std::type_info*, std::unique_ptr<memory_cache>>
} // namespace <anonymous> } // namespace <anonymous>
#if defined(CAF_CLANG) || defined(CAF_MACOS) #if defined(CAF_NO_THREAD_LOCAL)
namespace { namespace {
pthread_key_t s_key; pthread_key_t s_key;
...@@ -72,7 +74,7 @@ cache_map& get_cache_map() { ...@@ -72,7 +74,7 @@ cache_map& get_cache_map() {
return *cache; return *cache;
} }
#else // !CAF_CLANG && !CAF_MACOS #else // !CAF_NO_THREAD_LOCAL
namespace { namespace {
...@@ -90,7 +92,7 @@ cache_map& get_cache_map() { ...@@ -90,7 +92,7 @@ cache_map& get_cache_map() {
return *s_key; return *s_key;
} }
#endif #endif // !CAF_NO_THREAD_LOCAL
memory_cache::~memory_cache() { memory_cache::~memory_cache() {
// nop // nop
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment