onnxruntime/winml/lib/Common/inc/PheonixSingleton.h
2019-11-07 11:51:44 -08:00

19 lines
No EOL
413 B
C++

// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
#pragma once
template <typename T>
std::shared_ptr<T> PheonixSingleton() {
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>();
instance_ = instance;
return instance;
}