Class ResourceLifetime
Defined in File resource-lifetime.h
Class Documentation
-
class ResourceLifetime
Declaration:
finalOne retained native-resource domain with thread-safe retirement and owner-context deletion.
The current-context predicate borrows a context that outlives the active domain; it runs only on the owner and must not reenter this lifetime. Retaining the lifetime after shutdown preserves identity/statistics, not native usability.
See also
Public Functions
-
ResourceLifetime(std::thread::id owner, std::function<bool()> is_current)
Create active tracking for one context owner.
- Parameters:
owner – Nondefault thread identity permitted to issue native operations.
is_current – Nonempty predicate borrowing the context; it must outlive active tracking and not reenter this object.
- Throws:
CE::Exceptions::invalid_args – If owner/predicate is absent. Construction allocates tracking state but adopts no native objects.
-
~ResourceLifetime()
Abandon any still-active domain without native calls or listener invocation.
Prefer explicit shutdown() while the context is usable. Retained portable tokens become unavailable even when a separate backend authority remains retained.
-
inline ::CE::Rendering::GraphicsDomain graphics_domain() const noexcept
Declaration:
[[nodiscard]]
-
std::size_t track(::CE::Rendering::OpenGL::ResourceKind kind, NativeHandle id)
Declaration:
[[nodiscard]]Adopt an untracked nonzero native name on the live owner/current context.
- Parameters:
kind – Matching deletion family; unknown values reject.
id – Native name whose successful registration transfers cleanup responsibility to this lifetime.
- Returns:
Internal registration slot passed to retire(), not a native name or permanent public identifier. Validation/allocation failure leaves adoption incomplete: the caller must discard_untracked() without replacing the original exception. Do not adopt the same native object twice.
-
void retire(std::size_t slot) noexcept
Queue a tracked slot for deletion from any thread without native calls.
- Parameters:
slot – Registration from track(); inactive, absent or already-pending entries are ignored. Requires live tracking storage, not a current context. Collection/shutdown later deletes the name; mutex failures are reported and defer cleanup to shutdown. Do not reuse a stale slot after collection.
-
void collect()
Delete queued native objects on the live owner/current context.
After deletion tracking slots become reusable. Owner/context failure throws failed_operation; this does not stop the domain or delete still-retained objects.
-
void discard_untracked(::CE::Rendering::OpenGL::ResourceKind kind, NativeHandle id) noexcept
Best-effort constructor-failure cleanup for a name not adopted by track().
- Parameters:
kind – Correct native deletion family.
id – Untracked object name; zero is ignored. Deletes only on the live owner/current context. Failure is reported without replacing the original exception; context destruction owns remaining cleanup. Never pass an adopted name.
-
void shutdown()
Delete every tracked object and permanently deactivate the domain.
Requires the live owner/current context; otherwise failed_operation is thrown. Retained logical handles become unusable for native operations, including handles not yet retired. The caller must finish rendering/loading before shutdown.
-
void abandon() noexcept
Deactivate tracking without any OpenGL calls when native cleanup cannot run.
Retained handles stop querying the borrowed context. Remaining native names are left to context destruction; diagnostics record abandoned objects. This is a failure fallback, not ordinary collection.
-
void require_owner() const
Check active domain and calling-thread identity under the lifetime lock.
- Throws:
CE::Exceptions::failed_operation – For a stopped domain or foreign thread. Does not query the context.
-
void require_current() const
Check active owner first, then the borrowed current-context predicate.
- Throws:
CE::Exceptions::failed_operation – For stopped/foreign/noncurrent use. The predicate is never called from a foreign thread or after deactivation.
-
::CE::Rendering::OpenGL::ResourceStats diagnostics() const
Declaration:
[[nodiscard]]- Returns:
Copied counters under the lifetime mutex, with no logging or native queries; safe to observe independently of the native owner while retaining this object.
-
ResourceLifetime(std::thread::id owner, std::function<bool()> is_current)