Unravel Engine C++ Reference
Loading...
Searching...
No Matches
asset_detail::atomic_shared_ptr< T > Class Template Reference

#include <asset_handle.h>

Public Member Functions

 atomic_shared_ptr ()=default
 
 atomic_shared_ptr (std::shared_ptr< T > initial)
 
auto load (std::memory_order order=std::memory_order_seq_cst) const -> std::shared_ptr< T >
 
void store (std::shared_ptr< T > desired, std::memory_order order=std::memory_order_seq_cst)
 

Detailed Description

template<typename T>
class asset_detail::atomic_shared_ptr< T >

Portable atomic-shared-ptr wrapper.

C++20 specifies a std::atomic<std::shared_ptr<T>> partial specialisation that works lock- free without requiring T to be trivially copyable. However, that specialisation only ships in libstdc++ >= 11 and libc++ >= 16 (older standard libraries fall back to the primary std::atomic<T> template, whose static_assert(__is_trivially_copyable(T)) fires because std::shared_ptr<X> – with its ref-count and non-trivial destructor – is NOT trivially copyable). On those older stdlibs we fall back to a plain std::shared_ptr<T> plus the C++11-era free-function atomics, which compile everywhere shared_ptr does. The free functions were deprecated in C++20, but they only entered the deprecation path on stdlibs that also ship the new specialisation – so the feature-test pivot below avoids the deprecation diagnostic in both branches.

API mirrors the subset of std::atomic<std::shared_ptr<T>> that asset_handle actually uses (.load() / .store() with explicit memory orders), so the rest of this header is unchanged.

Definition at line 41 of file asset_handle.h.

Constructor & Destructor Documentation

◆ atomic_shared_ptr() [1/2]

template<typename T >
asset_detail::atomic_shared_ptr< T >::atomic_shared_ptr ( )
default

◆ atomic_shared_ptr() [2/2]

template<typename T >
asset_detail::atomic_shared_ptr< T >::atomic_shared_ptr ( std::shared_ptr< T > initial)
inlineexplicit

Definition at line 45 of file asset_handle.h.

Member Function Documentation

◆ load()

template<typename T >
auto asset_detail::atomic_shared_ptr< T >::load ( std::memory_order order = std::memory_order_seq_cst) const -> std::shared_ptr<T>
inline

Definition at line 47 of file asset_handle.h.

◆ store()

template<typename T >
void asset_detail::atomic_shared_ptr< T >::store ( std::shared_ptr< T > desired,
std::memory_order order = std::memory_order_seq_cst )
inline

Definition at line 56 of file asset_handle.h.


The documentation for this class was generated from the following file: