Commit 334b3c4b authored by Frederic De Jaeger's avatar Frederic De Jaeger Committed by Dominik Charousset

don't reimplement a thread local storage. Use the c++ keyword.

parent 0964a009
...@@ -352,12 +352,6 @@ private: ...@@ -352,12 +352,6 @@ private:
// References the parent system. // References the parent system.
actor_system& 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`. // Identifies the thread that called `logger::start`.
std::thread::id parent_thread_; std::thread::id parent_thread_;
......
...@@ -295,29 +295,16 @@ std::string logger::line_builder::get() const { ...@@ -295,29 +295,16 @@ std::string logger::line_builder::get() const {
} }
// returns the actor ID for the current thread // returns the actor ID for the current thread
thread_local actor_id _currentActoId;
actor_id logger::thread_local_aid() { actor_id logger::thread_local_aid() {
shared_lock<detail::shared_spinlock> guard{aids_lock_}; return _currentActoId;
auto i = aids_.find(std::this_thread::get_id());
if (i != aids_.end())
return i->second;
return 0;
} }
actor_id logger::thread_local_aid(actor_id aid) { actor_id logger::thread_local_aid(actor_id aid) {
auto tid = std::this_thread::get_id(); auto old = _currentActoId;
upgrade_lock<detail::shared_spinlock> guard{aids_lock_}; _currentActoId = aid;
auto i = aids_.find(tid); return old;
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
} }
void logger::log(event&& x) { void logger::log(event&& x) {
......
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