Files
salmanoff/stimBuffApis/livoxGen1/ioUringAssemblyEngine.h
T
hayodea bb59f47549 IoUringAssmEngn: add assembleFrameReq
Invoke it instimFrameProductionTimesliceInd.

Also, we discovered:
* stream_descriptor::release() doesn't fully release all metadata
  from the fd it was assigned. This suggests that we should go
  through the codebase and do: release()=>reset() whenever we
  wish to release().
* We've confirmed that spinlocks can be used to prevent race
  conditions between stop() and handler methods.
2025-11-06 01:04:10 -04:00

89 lines
2.5 KiB
C++

#ifndef _LIVOX_GEN1_IOURING_ASSEMBLY_ENGINE_H
#define _LIVOX_GEN1_IOURING_ASSEMBLY_ENGINE_H
#include <boostAsioLinkageFix.h>
#include <cstdint>
#include <cstddef>
#include <memory>
#include <functional>
#include <vector>
#include <chrono>
#include <atomic>
#include <liburing.h>
#include <boost/asio/io_service.hpp>
#include <boost/asio/deadline_timer.hpp>
#include <boost/asio/posix/stream_descriptor.hpp>
#include <livoxProto1/device.h>
#include <asynchronousContinuation.h>
#include <asynchronousLoop.h>
#include <callback.h>
#include <spinLock.h>
#include "frameAssemblyDesc.h"
namespace smo {
namespace stim_buff {
class PcloudStimulusBuffer;
class IoUringAssemblyEngine
{
public:
explicit IoUringAssemblyEngine(PcloudStimulusBuffer& parent);
~IoUringAssemblyEngine() = default;
bool setup();
void finalize();
typedef std::function<void(void*, int)> resetAndAssembleFrameCbFn;
void resetAndAssembleFrame(resetAndAssembleFrameCbFn onCqeReady);
void stop(bool doAcquireLock = true);
typedef std::function<void(bool, AsynchronousLoop)> assembleFrameReqCbFn;
void assembleFrameReq(Callback<assembleFrameReqCbFn> cb);
// Telemetry helpers
static size_t computePointsPerDgram(int returnMode);
static size_t computePointsPerFrame(int returnMode, size_t nDgramsPerFrame)
{ return computePointsPerDgram(returnMode) * nDgramsPerFrame; }
private:
PcloudStimulusBuffer& parent;
// Cached descriptor for reuse across iterations
std::shared_ptr<FrameAssemblyDesc> frameAssemblyDesc;
// io_uring infrastructure
struct io_uring ring;
bool isSetup;
// Eventfd for CQE notifications (used with boost's unified loop)
int eventfdFd;
std::unique_ptr<boost::asio::posix::stream_descriptor> eventfdDesc;
uint64_t eventfd_value; // Buffer for async_read_some
// Point cloud data socket descriptor
std::shared_ptr<boost::asio::posix::stream_descriptor> pcloudDataFdDesc;
// Stall detection timer
boost::asio::deadline_timer stallTimer;
// Callback for CQE ntfns (called with user_data+result from each CQE)
resetAndAssembleFrameCbFn onCqeReadyCallback;
// Flag to indicate assembly is in progress (cleared by stop())
// Protected by isAssemblingLock
SpinLock isAssemblingLock;
bool isAssembling;
void cancelIncompleteAndFillDummies();
void onEventfdRead(
const boost::system::error_code& error, std::size_t bytes_transferred);
class AssembleFrameReq;
friend class AssembleFrameReq;
};
} // namespace stim_buff
} // namespace smo
#endif // _LIVOX_GEN1_IOURING_ASSEMBLY_ENGINE_H