StimBuff: Use a single StagingBuffer for all StimFrames

We now allocate all the stimFrames for a StimBuffer using a
single StagingBuffer. This gives us all the benefits we're
looking for (pinning, alignment, etc).
This commit is contained in:
2025-11-19 03:08:16 -04:00
parent 3f04d1b387
commit 41b8385cb2
8 changed files with 93 additions and 57 deletions
+22 -15
View File
@@ -6,7 +6,9 @@
#include <stdexcept>
#include <string>
#include <new>
#include <memory>
#include <user/stimulusFrame.h>
#include <user/frameAssemblyDesc.h>
#include <user/sequenceLock.h>
namespace smo {
@@ -24,32 +26,35 @@ class SpMcRingBuffer
{
public:
/** EXPLANATION:
* Constructor initializes the ring buffer with the given constraints and
* number of buffers. Allocates slots vector with properly constructed
* StimulusFrame instances.
* Constructor initializes the ring buffer with FrameAssemblyDesc.
* Allocates frames vector with properly constructed StimulusFrame instances,
* each initialized with a SlotDesc from the FrameAssemblyDesc.
*/
explicit SpMcRingBuffer(
size_t nBuffers_,
const StagingBuffer::IOEngineConstraints& inputEngineConstraints,
const StagingBuffer::IOEngineConstraints& outputEngineConstraints,
size_t nSlotsPerStimFrame)
: nBuffers(nBuffers_),
// Default-construct all frames
slots(nBuffers)
const std::shared_ptr<FrameAssemblyDesc> &frameAssemblyDesc_)
:
nBuffers(frameAssemblyDesc_ ? frameAssemblyDesc_->slots.size() : 0),
frameAssemblyDesc(frameAssemblyDesc_),
slots(nBuffers) // Default-construct all frames
{
if (!frameAssemblyDesc)
{
throw std::invalid_argument(std::string(__func__)
+ ": SpMcRingBuffer: frameAssemblyDesc must not be null");
}
if (nBuffers == 0)
{
throw std::invalid_argument(std::string(__func__)
+ ": SpMcRingBuffer: nBuffers must be > 0");
+ ": SpMcRingBuffer: frameAssemblyDesc must have at least one "
"slot");
}
// Re-invoke constructors w/placement new on default-constructed frames
for (size_t i = 0; i < nBuffers; ++i)
{
slots[i].~StimulusFrame(); // Destroy default-constructed object
new (&slots[i]) StimulusFrame(
inputEngineConstraints, outputEngineConstraints,
nSlotsPerStimFrame);
new (&slots[i]) StimulusFrame(frameAssemblyDesc->slots[i]);
}
}
@@ -94,7 +99,9 @@ public:
size_t nBuffers;
private:
// Frames vector: each frame contains a sequence lock and staging buffer
// FrameAssemblyDesc describing the memory layout
std::shared_ptr<FrameAssemblyDesc> frameAssemblyDesc;
// Frames vector: each frame contains a sequence lock and SlotDesc
std::vector<StimulusFrame> slots;
};