From 9b66818bda1d00f72572b96d4614a4964e7ee202 Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Fri, 13 Feb 2026 22:43:24 +0100 Subject: [PATCH] BufferProvider: inline the buildHandle function to simplify calls In the old version of `BufferProvider`, there was a single backend implementation, which was assumed to call-back into `buildHandle(typeID, storage, localTag)` after allocating memory. This implies, the state transition to `LOCKED` happened there. My next goal is to clarify and abstract also the state transition API, and this refactoring helps a lot to see the underlying call structure. --- src/steam/engine/buffer-metadata.hpp | 2 +- src/steam/engine/buffer-provider.cpp | 41 ++++++++++------------------ src/steam/engine/buffer-provider.hpp | 2 -- 3 files changed, 15 insertions(+), 30 deletions(-) diff --git a/src/steam/engine/buffer-metadata.hpp b/src/steam/engine/buffer-metadata.hpp index c4cfd6b9c..d4bcca3b5 100644 --- a/src/steam/engine/buffer-metadata.hpp +++ b/src/steam/engine/buffer-metadata.hpp @@ -377,7 +377,7 @@ namespace engine { __buffer_required(); if (nontrivial (instanceFunc_)) instanceFunc_.destroyAttached (buffer_); - buffer_ = 0; + buffer_ = nullptr; } private: diff --git a/src/steam/engine/buffer-provider.cpp b/src/steam/engine/buffer-provider.cpp index c6ef2c5cc..4969569d8 100644 --- a/src/steam/engine/buffer-provider.cpp +++ b/src/steam/engine/buffer-provider.cpp @@ -78,25 +78,6 @@ namespace engine { } - /** - * Callback from implementation to build and enrol a BufferHandle, - * to be returned to the client as result of the #lockBuffer call. - * Performs the necessary metadata state transition leading from an - * abstract buffer type to a metadata::Entry corresponding to an - * actual buffer, which is locked for exclusive use by one client. - * @note the implementation is free to provide an opaque \a implMarker, - * which becomes part of the key to designate this specific buffer. - */ - BuffHandle - BufferProvider::buildHandle (HashVal typeID, Buff* storage, LocalTag implMarker) - { - metadata::Key& typeKey = bufferStage_->get (typeID); - metadata::Entry& entry = bufferStage_->markLocked (typeKey, storage, implMarker); - - return BuffHandle (BuffDescr(*this, entry), storage); - } - - /** BufferProvider API: declare in advance the need for working buffers. * This optional call allows client code to ensure the availability of the * necessary working space, prior to starting the actual operations. The @@ -123,10 +104,15 @@ namespace engine { /** BufferProvider API: retrieve a single buffer for exclusive use. * This call actually claims a buffer of this type and marks it for - * use by client code. The returned handle allows for convenient access, - * but provides no automatic tracking or memory management. The client is - * explicitly responsible to invoke #releaseBuffer (which can be done directly - * on the BuffHandle). + * use by client code. Performs the necessary metadata state transition + * leading from an abstract buffer type to a derived metadata::Entry + * that corresponds to an actual buffer and has a lifecycle state. + * This entry is marked as _locked_ for exclusive use by one client. + * The returned handle allows to query state and perform further + * state transitions (_emitted_, _released_), yet provides no + * automatic tracking and clean-up. The client is explicitly + * responsible to invoke #releaseBuffer (either on the + * BufferProvider, or directly on the BuffHandle). * @return a copyable handle, representing this buffer and this usage transaction. * @throw error::State when unable to provide this buffer * @note this function may be used right away, without prior announcing, but then @@ -138,10 +124,11 @@ namespace engine { BufferProvider::lockBuffer (BuffDescr const& type) { REQUIRE (was_created_by_this_provider (type)); - metadata::Entry& metaEntry = bufferStage_->get (type); - size_t buffSiz = metaEntry.storageSize(); - auto [storage, implMarker] = bufferStore_->provideBuffer (buffSiz, type, metaEntry.localTag()); - return buildHandle (type, storage, implMarker); + metadata::Key& typeKey = bufferStage_->get (type); + auto [storage, implMarker] = bufferStore_->provideBuffer (typeKey.storageSize(), type, typeKey.localTag()); + metadata::Entry& entry = bufferStage_->markLocked (typeKey, storage, implMarker); + + return BuffHandle (BuffDescr(*this, entry), storage); } diff --git a/src/steam/engine/buffer-provider.hpp b/src/steam/engine/buffer-provider.hpp index 97538fab6..b75e91399 100644 --- a/src/steam/engine/buffer-provider.hpp +++ b/src/steam/engine/buffer-provider.hpp @@ -180,8 +180,6 @@ namespace engine { /// placeholder marker type for an actual data buffer using Buff = StreamType::ImplFacade::DataBuffer; - BuffHandle buildHandle (HashVal typeID, Buff* storage, LocalTag =LocalTag::UNKNOWN); - bool was_created_by_this_provider (BuffDescr const&) const;