Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
Actor Framework
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
cpp-libs
Actor Framework
Commits
cc0b51c2
Commit
cc0b51c2
authored
Dec 17, 2019
by
Dominik Charousset
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove CAF_NO_THREAD_LOCAL and its workarounds
parent
334b3c4b
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
21 additions
and
66 deletions
+21
-66
cmake/check-compiler-features.cpp
cmake/check-compiler-features.cpp
+4
-0
libcaf_core/caf/config.hpp
libcaf_core/caf/config.hpp
+0
-9
libcaf_core/src/logger.cpp
libcaf_core/src/logger.cpp
+17
-57
No files found.
cmake/check-compiler-features.cpp
View file @
cc0b51c2
...
...
@@ -10,6 +10,10 @@
# error "No support for 'if constexpr' (__cpp_if_constexpr)"
#endif
// Unfortunately there's no feature test macro for thread_local. By putting this
// here, at least we'll get a compiler error on unsupported platforms.
[[
maybe_unused
]]
thread_local
int
foo
;
int
main
(
int
,
char
**
)
{
return
0
;
}
libcaf_core/caf/config.hpp
View file @
cc0b51c2
...
...
@@ -108,9 +108,6 @@
# define CAF_ANNOTATE_FALLTHROUGH [[clang::fallthrough]]
# define CAF_COMPILER_VERSION \
(__clang_major__ * 10000 + __clang_minor__ * 100 + __clang_patchlevel__)
# if !__has_feature(cxx_thread_local)
# define CAF_NO_THREAD_LOCAL
# endif
#elif defined(__GNUC__)
# define CAF_GCC
# define CAF_LIKELY(x) __builtin_expect((x), 1)
...
...
@@ -146,12 +143,6 @@
(__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
// disable thread_local on GCC/macOS due to heap-use-after-free bug:
// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67135
# ifdef __APPLE__
# define CAF_NO_THREAD_LOCAL
# endif
# ifdef __MINGW32__
# define CAF_NO_THREAD_LOCAL
# endif
#elif defined(_MSC_VER)
# define CAF_MSVC
# define CAF_LIKELY(x) x
...
...
libcaf_core/src/logger.cpp
View file @
cc0b51c2
...
...
@@ -18,14 +18,15 @@
#include "caf/logger.hpp"
#include <ctime>
#include <thread>
#include <cstring>
#include <iomanip>
#include <fstream>
#include <algorithm>
#include <condition_variable>
#include <cstring>
#include <ctime>
#include <fstream>
#include <iomanip>
#include <thread>
#include <unordered_map>
#include <utility>
#include "caf/config.hpp"
...
...
@@ -47,6 +48,12 @@ namespace caf {
namespace
{
// Stores the ID of the currently running actor.
thread_local
actor_id
current_actor_id
;
// Stores a pointer to the system-wide logger.
thread_local
intrusive_ptr
<
logger
>
current_logger_ptr
;
constexpr
string_view
log_level_name
[]
=
{
"QUIET"
,
""
,
...
...
@@ -188,48 +195,6 @@ string_view reduce_symbol(std::ostream& out, string_view symbol) {
return
symbol
;
}
#if defined(CAF_NO_THREAD_LOCAL)
pthread_key_t
s_key
;
pthread_once_t
s_key_once
=
PTHREAD_ONCE_INIT
;
void
logger_ptr_destructor
(
void
*
ptr
)
{
if
(
ptr
!=
nullptr
)
{
intrusive_ptr_release
(
reinterpret_cast
<
logger
*>
(
ptr
));
}
}
void
make_logger_ptr
()
{
pthread_key_create
(
&
s_key
,
logger_ptr_destructor
);
}
void
set_current_logger
(
logger
*
x
)
{
pthread_once
(
&
s_key_once
,
make_logger_ptr
);
logger_ptr_destructor
(
pthread_getspecific
(
s_key
));
if
(
x
!=
nullptr
)
intrusive_ptr_add_ref
(
x
);
pthread_setspecific
(
s_key
,
x
);
}
logger
*
get_current_logger
()
{
pthread_once
(
&
s_key_once
,
make_logger_ptr
);
return
reinterpret_cast
<
logger
*>
(
pthread_getspecific
(
s_key
));
}
#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
}
// namespace
logger
::
config
::
config
()
...
...
@@ -296,15 +261,13 @@ std::string logger::line_builder::get() const {
// returns the actor ID for the current thread
thread_local
actor_id
_currentActoId
;
actor_id
logger
::
thread_local_aid
()
{
return
_currentActoI
d
;
return
current_actor_i
d
;
}
actor_id
logger
::
thread_local_aid
(
actor_id
aid
)
{
auto
old
=
_currentActoId
;
_currentActoId
=
aid
;
return
old
;
std
::
swap
(
current_actor_id
,
aid
);
return
aid
;
}
void
logger
::
log
(
event
&&
x
)
{
...
...
@@ -315,14 +278,11 @@ void logger::log(event&& x) {
}
void
logger
::
set_current_actor_system
(
actor_system
*
x
)
{
if
(
x
!=
nullptr
)
set_current_logger
(
&
x
->
logger
());
else
set_current_logger
(
nullptr
);
current_logger_ptr
.
reset
(
x
!=
nullptr
?
&
x
->
logger
()
:
nullptr
);
}
logger
*
logger
::
current_logger
()
{
return
get_current_logger
();
return
current_logger_ptr
.
get
();
}
bool
logger
::
accepts
(
unsigned
level
,
atom_value
cname
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment