Unravel Engine C++ Reference
Loading...
Searching...
No Matches
asset_link< T > Struct Template Reference

Thread-safe link to an asset. More...

#include <asset_handle.h>

Classes

struct  state_t
 Immutable snapshot of the link's logical state. More...
 

Public Types

using task_future_t = task_future<std::shared_ptr<T>>
 
using weak_asset_t = std::weak_ptr<T>
 

Public Attributes

asset_detail::atomic_shared_ptr< state_tstate {std::make_shared<state_t>()}
 
std::mutex weak_asset_mtx
 
weak_asset_t weak_asset
 
std::atomic< int64_t > last_access_ns {0}
 

Detailed Description

template<typename T>
struct asset_link< T >

Thread-safe link to an asset.

The link's "logical state" (uid, id, task) lives in an immutable state_t snapshot held by std::atomic<std::shared_ptr<state_t>>. Readers do a single state.load() to obtain a coherent snapshot — no torn reads are possible even when another thread is concurrently invalidating or reloading the link.

The weak-asset cache and the last-access timestamp are kept outside the snapshot so they can be updated without allocating a new snapshot on every cache hit / get() call. weak_asset is guarded by a small mutex (weak_ptr cannot be portably made atomic), last_access_ns is a relaxed int64 atomic.

Definition at line 92 of file asset_handle.h.

Member Typedef Documentation

◆ task_future_t

template<typename T >
using asset_link< T >::task_future_t = task_future<std::shared_ptr<T>>

Definition at line 94 of file asset_handle.h.

◆ weak_asset_t

template<typename T >
using asset_link< T >::weak_asset_t = std::weak_ptr<T>

Definition at line 95 of file asset_handle.h.

Member Data Documentation

◆ last_access_ns

template<typename T >
std::atomic<int64_t> asset_link< T >::last_access_ns {0}
mutable

Last-access timestamp in nanoseconds-since-steady-epoch. Stored as std::atomic<int64_t> so updates from the rendering hot path never race with concurrent readers (and never block).

Definition at line 132 of file asset_handle.h.

◆ state

template<typename T >
asset_detail::atomic_shared_ptr<state_t> asset_link< T >::state {std::make_shared<state_t>()}

Current snapshot. Initialised to an empty state so readers never see null.

Wrapped in asset_detail::atomic_shared_ptr rather than std::atomic<std::shared_ptr<...>> directly because the C++20 specialisation isn't available on libstdc++ < 11 / libc++ < 16 and the primary std::atomic<T> template static_asserts on shared_ptr's non-trivial copyability. The wrapper presents the same .load() / .store() member API.

Definition at line 120 of file asset_handle.h.

◆ weak_asset

template<typename T >
weak_asset_t asset_link< T >::weak_asset
mutable

Definition at line 127 of file asset_handle.h.

◆ weak_asset_mtx

template<typename T >
std::mutex asset_link< T >::weak_asset_mtx
mutable

Best-effort cache of the resolved asset. Updated on cache miss in get(). Guarded by weak_asset_mtx (weak_ptr can't be portably atomic). The critical section is just a load or assignment, so contention is negligible.

Definition at line 126 of file asset_handle.h.


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