alpaka
Abstraction Library for Parallel Kernel Acceleration
Loading...
Searching...
No Matches
Handle.hpp
Go to the documentation of this file.
1/* Copyright 2024 René Widera
2 * SPDX-License-Identifier: MPL-2.0
3 */
4
5#pragma once
6
7#include <memory>
8#include <mutex>
9#include <type_traits>
10
11namespace alpaka::onHost
12{
13 template<typename T_Object, typename... T_Args>
14 inline auto make_sharedSingleton(T_Args&&... args)
15 {
16 static std::mutex mutex;
17 static std::weak_ptr<T_Object> platform;
18
19 std::lock_guard<std::mutex> lk(mutex);
20 if(auto sharedPtr = platform.lock())
21 {
22 return sharedPtr;
23 }
24 auto new_platform = std::make_shared<T_Object>(std::forward<T_Args>(args)...);
25 platform = new_platform;
26 return new_platform;
27 }
28
29 template<typename T>
30 using Handle = std::shared_ptr<T>;
31} // namespace alpaka::onHost
Functionality which is usable on the host CPU controller thread.
Definition api.hpp:40
std::shared_ptr< T > Handle
Definition Handle.hpp:30
auto make_sharedSingleton(T_Args &&... args)
Definition Handle.hpp:14