diff options
author | alexvru <alexvru@ydb.tech> | 2023-11-09 11:40:47 +0300 |
---|---|---|
committer | alexvru <alexvru@ydb.tech> | 2023-11-09 12:12:45 +0300 |
commit | c576fbcfb493c33a2342baeef87219b1839889c5 (patch) | |
tree | 1569ecdf367aa7b15329cbf6f010f7388757b473 /library | |
parent | 271de17955e199c5c8c7775734d3ac519c06c497 (diff) | |
download | ydb-c576fbcfb493c33a2342baeef87219b1839889c5.tar.gz |
Fix TlsActivationContext caching by compiler KIKIMR-19993
Diffstat (limited to 'library')
-rw-r--r-- | library/cpp/actors/core/actor.cpp | 29 | ||||
-rw-r--r-- | library/cpp/actors/core/actor.h | 13 | ||||
-rw-r--r-- | library/cpp/actors/core/log.h | 12 |
3 files changed, 45 insertions, 9 deletions
diff --git a/library/cpp/actors/core/actor.cpp b/library/cpp/actors/core/actor.cpp index ddd849d285..6d6c92f431 100644 --- a/library/cpp/actors/core/actor.cpp +++ b/library/cpp/actors/core/actor.cpp @@ -6,7 +6,34 @@ namespace NActors { Y_POD_THREAD(TThreadContext*) TlsThreadContext(nullptr); - Y_POD_THREAD(TActivationContext*) TlsActivationContext(nullptr); + thread_local TActivationContext *TActivationContextHolder::Value = nullptr; + TActivationContextHolder TlsActivationContext; + + [[gnu::noinline]] TActivationContextHolder::operator bool() const { + asm volatile(""); + return Value != nullptr; + } + + [[gnu::noinline]] TActivationContextHolder::operator TActivationContext*() const { + asm volatile(""); + return Value; + } + + [[gnu::noinline]] TActivationContext *TActivationContextHolder::operator ->() { + asm volatile(""); + return Value; + } + + [[gnu::noinline]] TActivationContext& TActivationContextHolder::operator *() { + asm volatile(""); + return *Value; + } + + [[gnu::noinline]] TActivationContextHolder& TActivationContextHolder::operator =(TActivationContext *context) { + asm volatile(""); + Value = context; + return *this; + } template<i64 Increment> static void UpdateQueueSizeAndTimestamp(TActorUsageImpl<true>& impl, ui64 time) { diff --git a/library/cpp/actors/core/actor.h b/library/cpp/actors/core/actor.h index c807227c43..7452b50571 100644 --- a/library/cpp/actors/core/actor.h +++ b/library/cpp/actors/core/actor.h @@ -29,7 +29,18 @@ namespace NActors { struct TActorContext; struct TActivationContext; - extern Y_POD_THREAD(TActivationContext*) TlsActivationContext; + class TActivationContextHolder { + static thread_local TActivationContext *Value; + + public: + [[gnu::noinline]] operator bool() const; + [[gnu::noinline]] operator TActivationContext*() const; + [[gnu::noinline]] TActivationContext *operator ->(); + [[gnu::noinline]] TActivationContext& operator *(); + [[gnu::noinline]] TActivationContextHolder& operator=(TActivationContext *context); + }; + + extern TActivationContextHolder TlsActivationContext; struct TActivationContext { public: diff --git a/library/cpp/actors/core/log.h b/library/cpp/actors/core/log.h index a07540dc49..fa95b2521d 100644 --- a/library/cpp/actors/core/log.h +++ b/library/cpp/actors/core/log.h @@ -25,13 +25,11 @@ // TODO: limit number of messages per second // TODO: make TLogComponentLevelRequest/Response network messages -#define IS_LOG_PRIORITY_ENABLED(priority, component) \ - (NActors::TlsActivationContext ? (static_cast<::NActors::NLog::TSettings*>((*NActors::TlsActivationContext).LoggerSettings()) && \ - static_cast<::NActors::NLog::TSettings*>((*NActors::TlsActivationContext).LoggerSettings())->Satisfies( \ - static_cast<::NActors::NLog::EPriority>(priority), \ - static_cast<::NActors::NLog::EComponent>(component), \ - 0ull) \ - ) : true) +#define IS_LOG_PRIORITY_ENABLED(priority, component) \ + [p = static_cast<::NActors::NLog::EPriority>(priority), c = static_cast<::NActors::NLog::EComponent>(component)]() -> bool { \ + ::NActors::TActivationContext *context = ::NActors::TlsActivationContext; \ + return !context || context->LoggerSettings()->Satisfies(p, c, 0ull); \ + }() #define IS_EMERG_LOG_ENABLED(component) IS_LOG_PRIORITY_ENABLED(NActors::NLog::PRI_EMERG, component) #define IS_ALERT_LOG_ENABLED(component) IS_LOG_PRIORITY_ENABLED(NActors::NLog::PRI_ALERT, component) |