@@ -47,31 +47,26 @@ platform_impl::~platform_impl() = default;
4747platform_impl &
4848platform_impl::getOrMakePlatformImpl (ur_platform_handle_t UrPlatform,
4949 adapter_impl &Adapter) {
50- std::shared_ptr<platform_impl> Result;
51- {
52- const std::lock_guard<std::mutex> Guard (
53- GlobalHandler::instance ().getPlatformMapMutex ());
54-
55- std::vector<std::shared_ptr<platform_impl>> &PlatformCache =
56- GlobalHandler::instance ().getPlatformCache ();
57-
58- // If we've already seen this platform, return the impl
59- for (const auto &PlatImpl : PlatformCache) {
60- if (PlatImpl->getHandleRef () == UrPlatform)
61- return *PlatImpl;
62- }
50+ const std::lock_guard<std::mutex> Guard (
51+ GlobalHandler::instance ().getPlatformMapMutex ());
52+
53+ std::vector<std::unique_ptr<platform_impl>> &PlatformCache =
54+ GlobalHandler::instance ().getPlatformCache ();
6355
64- // Otherwise make the impl. Our ctor/dtor are private, so std::make_shared
65- // needs a bit of help...
66- struct creator : platform_impl {
67- creator (ur_platform_handle_t APlatform, adapter_impl &AAdapter)
68- : platform_impl(APlatform, AAdapter) {}
69- };
70- Result = std::make_shared<creator>(UrPlatform, Adapter);
71- PlatformCache.emplace_back (Result);
56+ // If we've already seen this platform, return the impl
57+ for (const auto &PlatImpl : PlatformCache) {
58+ if (PlatImpl->getHandleRef () == UrPlatform)
59+ return *PlatImpl;
7260 }
7361
74- return *Result;
62+ // Otherwise make the impl. Our ctor/dtor are private, so std::make_unique
63+ // needs a bit of help...
64+ struct creator : platform_impl {
65+ creator (ur_platform_handle_t APlatform, adapter_impl &AAdapter)
66+ : platform_impl(APlatform, AAdapter) {}
67+ };
68+ return *PlatformCache.emplace_back (
69+ std::make_unique<creator>(UrPlatform, Adapter));
7570}
7671
7772platform_impl &
0 commit comments