Unverified Commit 921ab3c7 authored by Dominik Charousset's avatar Dominik Charousset Committed by GitHub

Merge pull request #1083

Make getter/setter of thread-local variable static
parents f3203e75 69a6b5ce
......@@ -220,10 +220,10 @@ public:
// -- properties -------------------------------------------------------------
/// Returns the ID of the actor currently associated to the calling thread.
actor_id thread_local_aid();
static actor_id thread_local_aid();
/// Associates an actor ID to the calling thread and returns the last value.
actor_id thread_local_aid(actor_id aid);
static actor_id thread_local_aid(actor_id aid);
/// Returns whether the logger is configured to accept input for given
/// component and log level.
......@@ -431,29 +431,20 @@ CAF_CORE_EXPORT bool operator==(const logger::field& x, const logger::field& y);
if (CAF_UNIFYN(caf_logger) != nullptr \
&& CAF_UNIFYN(caf_logger)->accepts(loglvl, component)) \
CAF_UNIFYN(caf_logger) \
->log(CAF_LOG_MAKE_EVENT(CAF_UNIFYN(caf_logger)->thread_local_aid(), \
component, loglvl, message)); \
->log(CAF_LOG_MAKE_EVENT(caf::logger::thread_local_aid(), component, \
loglvl, message)); \
} while (false)
#define CAF_PUSH_AID(aarg) \
auto CAF_UNIFYN(caf_tmp_ptr) = caf::logger::current_logger(); \
caf::actor_id CAF_UNIFYN(caf_aid_tmp) = 0; \
if (CAF_UNIFYN(caf_tmp_ptr)) \
CAF_UNIFYN(caf_aid_tmp) = CAF_UNIFYN(caf_tmp_ptr)->thread_local_aid(aarg); \
auto CAF_UNIFYN(aid_aid_tmp_guard) = caf::detail::make_scope_guard([=] { \
auto CAF_UNIFYN(caf_tmp2_ptr) = caf::logger::current_logger(); \
if (CAF_UNIFYN(caf_tmp2_ptr)) \
CAF_UNIFYN(caf_tmp2_ptr)->thread_local_aid(CAF_UNIFYN(caf_aid_tmp)); \
})
caf::actor_id CAF_UNIFYN(caf_aid_tmp) = caf::logger::thread_local_aid(aarg); \
auto CAF_UNIFYN(caf_aid_tmp_guard) = caf::detail::make_scope_guard( \
[=] { caf::logger::thread_local_aid(CAF_UNIFYN(caf_aid_tmp)); })
#define CAF_PUSH_AID_FROM_PTR(some_ptr) \
auto CAF_UNIFYN(caf_aid_ptr) = some_ptr; \
CAF_PUSH_AID(CAF_UNIFYN(caf_aid_ptr) ? CAF_UNIFYN(caf_aid_ptr)->id() : 0)
#define CAF_SET_AID(aid_arg) \
(caf::logger::current_logger() \
? caf::logger::current_logger()->thread_local_aid(aid_arg) \
: 0)
#define CAF_SET_AID(aid_arg) caf::logger::thread_local_aid(aid_arg)
#define CAF_SET_LOGGER_SYS(ptr) caf::logger::set_current_actor_system(ptr)
......
......@@ -33,22 +33,23 @@ namespace caf {
template <class T, class R = infer_handle_from_class_t<T>, class... Ts>
R make_actor(actor_id aid, node_id nid, actor_system* sys, Ts&&... xs) {
#if CAF_LOG_LEVEL >= CAF_LOG_LEVEL_DEBUG
actor_storage<T>* ptr = nullptr;
if (logger::current_logger()->accepts(CAF_LOG_LEVEL_DEBUG,
CAF_LOG_FLOW_COMPONENT)) {
std::string args;
args = deep_to_string(std::forward_as_tuple(xs...));
ptr
= new actor_storage<T>(aid, std::move(nid), sys, std::forward<Ts>(xs)...);
actor_storage<T>* ptr;
{
CAF_PUSH_AID(aid);
ptr = new actor_storage<T>(aid, std::move(nid), sys,
std::forward<Ts>(xs)...);
}
CAF_LOG_SPAWN_EVENT(ptr->data, args);
} else {
ptr
= new actor_storage<T>(aid, std::move(nid), sys, std::forward<Ts>(xs)...);
return {&(ptr->ctrl), false};
}
#else
auto ptr
= new actor_storage<T>(aid, std::move(nid), sys, std::forward<Ts>(xs)...);
#endif
CAF_PUSH_AID(aid);
auto ptr = new actor_storage<T>(aid, std::move(nid), sys,
std::forward<Ts>(xs)...);
return {&(ptr->ctrl), false};
}
......
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