#pragma once #include #include #include #include #include #include #include #include #include namespace ReloadableHost { struct ReleaseDescriptor { std::string id; std::string path; std::uint64_t generation{0}; }; /// Host-supplied trust/checksum validation for a candidate release. using ReleaseValidator = std::function(const ReleaseDescriptor&)>; struct ReleaseLimits { /// Maximum unpinned-reclaimable older generations retained. std::size_t max_retained_generations{2}; }; /// Immutable pinned release handle. Holding it keeps its generation alive /// across reloads, exactly like an old read handle in the reference host. using ReleaseHandle = std::shared_ptr; /// Immutable release generations with pin-based retention. /// /// Publishing never invalidates an acquired handle. Older generations are /// retired only after every pin is released, so the retained set stays /// bounded by the pin count and the configured cap. class ReleaseRegistry { public: explicit ReleaseRegistry(ReleaseLimits limits = {}); /// Validate and publish a candidate. Returns its generation. [[nodiscard]] Void::Result::Result publish(ReleaseDescriptor candidate, const ReleaseValidator& validate); /// Pin the current generation. Empty when nothing is published. [[nodiscard]] ReleaseHandle acquire() const; [[nodiscard]] std::optional current() const; /// Retire older generations with no outstanding pins. std::size_t collect() noexcept; [[nodiscard]] std::size_t retained() const noexcept; private: std::size_t collect_locked() noexcept; mutable std::mutex m_mutex; ReleaseLimits m_limits; std::uint64_t m_next_generation{1}; ReleaseHandle m_current; std::vector m_retained; }; } // namespace ReloadableHost