onnxruntime/winml/lib/Common/inc/PheonixSingleton.h
Justin Chu eeef157888
Format c++ code under winml/ (#16660)
winml/ was previously excluded from lintrunner config. This change
includes the directory and adds the clang-format config file specific to
winml/ that fits existing style.

---------

Signed-off-by: Justin Chu <justinchu@microsoft.com>
2023-07-25 21:56:50 -07:00

19 lines
497 B
C++

// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
#pragma once
template <typename T, typename... TArgs>
std::shared_ptr<T> PheonixSingleton(TArgs&&... args) {
static std::weak_ptr<T> instance_;
static std::mutex lock_;
std::lock_guard<std::mutex> lock(lock_);
if (auto instance = instance_.lock()) {
return instance;
}
auto instance = std::make_shared<T>(std::forward<TArgs>(args)...);
instance_ = instance;
return instance;
}