Skip to content

Commit

Permalink
Add initialization check to prevent re-entry into the lock during Tra…
Browse files Browse the repository at this point in the history
…ceLoggingRegisterEx
  • Loading branch information
Sheil Kumar committed Jul 22, 2024
1 parent 8b71d89 commit afd6858
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
13 changes: 10 additions & 3 deletions onnxruntime/core/platform/windows/logging/etw_sink.cc
Original file line number Diff line number Diff line change
Expand Up @@ -143,17 +143,24 @@ EtwRegistrationManager::~EtwRegistrationManager() {
EtwRegistrationManager::EtwRegistrationManager() {
}

void EtwRegistrationManager::LazyInitialize() {
if (!initialized_) {
void EtwRegistrationManager::LazyInitialize() try {
if (!initialized_ && !initializing_) {
std::lock_guard<OrtMutex> lock(init_mutex_);
if (!initialized_) { // Double-check locking pattern
if (!initialized_ && !initializing_) { // Double-check locking pattern
initializing_ = true;
etw_status_ = ::TraceLoggingRegisterEx(etw_provider_handle, ORT_TL_EtwEnableCallback, nullptr);
if (FAILED(etw_status_)) {
ORT_THROW("ETW registration failed. Logging will be broken: " + std::to_string(etw_status_));
}
initialized_ = true;
initializing_ = false;
}
}
} catch (...)
{
initialized_ = false;
initializing_ = false;
throw;
}

void EtwRegistrationManager::InvokeCallbacks(LPCGUID SourceId, ULONG IsEnabled, UCHAR Level, ULONGLONG MatchAnyKeyword,
Expand Down
1 change: 1 addition & 0 deletions onnxruntime/core/platform/windows/logging/etw_sink.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ class EtwRegistrationManager {
mutable OrtMutex provider_change_mutex_;
OrtMutex init_mutex_;
bool initialized_ = false;
bool initializing_ = false;
bool is_enabled_;
UCHAR level_;
ULONGLONG keyword_;
Expand Down

0 comments on commit afd6858

Please sign in to comment.