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
07931b0b
Unverified
Commit
07931b0b
authored
Dec 18, 2019
by
Dominik Charousset
Committed by
GitHub
Dec 18, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #996
Remove CAF_NO_THREAD_LOCAL and its workarounds
parents
0964a009
cc0b51c2
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
22 additions
and
86 deletions
+22
-86
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/caf/logger.hpp
libcaf_core/caf/logger.hpp
+0
-6
libcaf_core/src/logger.cpp
libcaf_core/src/logger.cpp
+18
-71
No files found.
cmake/check-compiler-features.cpp
View file @
07931b0b
...
...
@@ -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 @
07931b0b
...
...
@@ -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/caf/logger.hpp
View file @
07931b0b
...
...
@@ -352,12 +352,6 @@ private:
// References the parent system.
actor_system
&
system_
;
// Guards aids_.
detail
::
shared_spinlock
aids_lock_
;
// Maps thread IDs to actor IDs.
std
::
unordered_map
<
std
::
thread
::
id
,
actor_id
>
aids_
;
// Identifies the thread that called `logger::start`.
std
::
thread
::
id
parent_thread_
;
...
...
libcaf_core/src/logger.cpp
View file @
07931b0b
...
...
@@ -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
()
...
...
@@ -295,29 +260,14 @@ std::string logger::line_builder::get() const {
}
// returns the actor ID for the current thread
actor_id
logger
::
thread_local_aid
()
{
shared_lock
<
detail
::
shared_spinlock
>
guard
{
aids_lock_
};
auto
i
=
aids_
.
find
(
std
::
this_thread
::
get_id
());
if
(
i
!=
aids_
.
end
())
return
i
->
second
;
return
0
;
return
current_actor_id
;
}
actor_id
logger
::
thread_local_aid
(
actor_id
aid
)
{
auto
tid
=
std
::
this_thread
::
get_id
();
upgrade_lock
<
detail
::
shared_spinlock
>
guard
{
aids_lock_
};
auto
i
=
aids_
.
find
(
tid
);
if
(
i
!=
aids_
.
end
())
{
// we modify it despite the shared lock because the elements themselves
// are considered thread-local
auto
res
=
i
->
second
;
i
->
second
=
aid
;
return
res
;
}
// upgrade to unique lock and insert new element
upgrade_to_unique_lock
<
detail
::
shared_spinlock
>
uguard
{
guard
};
aids_
.
emplace
(
tid
,
aid
);
return
0
;
// was empty before
std
::
swap
(
current_actor_id
,
aid
);
return
aid
;
}
void
logger
::
log
(
event
&&
x
)
{
...
...
@@ -328,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