Skip to content

Commit

Permalink
Per PR, place active_sessions_mutex_ under win32 since it's only used…
Browse files Browse the repository at this point in the history
… there for now
  • Loading branch information
ivberg committed Feb 7, 2024
1 parent 2086d76 commit 4fc424b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
7 changes: 6 additions & 1 deletion onnxruntime/core/session/inference_session.cc
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,9 @@ Status GetMinimalBuildOptimizationHandling(

std::atomic<uint32_t> InferenceSession::global_session_id_{1};
std::map<uint32_t, InferenceSession*> InferenceSession::active_sessions_;
#ifdef _WIN32
OrtMutex InferenceSession::active_sessions_mutex_; // Protects access to active_sessions_
#endif

static Status FinalizeSessionOptions(const SessionOptions& user_provided_session_options,
const ONNX_NAMESPACE::ModelProto& model_proto,
Expand Down Expand Up @@ -359,10 +361,11 @@ void InferenceSession::ConstructorCommon(const SessionOptions& session_options,

// a monotonically increasing session id for use in telemetry
session_id_ = global_session_id_.fetch_add(1);

#ifdef _WIN32
std::lock_guard<OrtMutex> lock(active_sessions_mutex_);
active_sessions_[global_session_id_++] = this;

#ifdef _WIN32
// Register callback for ETW capture state (rundown)
WindowsTelemetry::RegisterInternalCallback(
[this](
Expand Down Expand Up @@ -654,7 +657,9 @@ InferenceSession::~InferenceSession() {
}

// Unregister the session
#ifdef _WIN32
std::lock_guard<OrtMutex> lock(active_sessions_mutex_);
#endif
active_sessions_.erase(global_session_id_);

#ifdef ONNXRUNTIME_ENABLE_INSTRUMENT
Expand Down
2 changes: 2 additions & 0 deletions onnxruntime/core/session/inference_session.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,9 @@ class InferenceSession {

using InputOutputDefMetaMap = InlinedHashMap<std::string_view, InputOutputDefMetaData>;
static std::map<uint32_t, InferenceSession*> active_sessions_;
#ifdef _WIN32
static OrtMutex active_sessions_mutex_; // Protects access to active_sessions_
#endif

public:
#if !defined(ORT_MINIMAL_BUILD)
Expand Down

0 comments on commit 4fc424b

Please sign in to comment.