Libspinscale: Initial top-level SMO port to coroutine framework

We haven't ported everything. Just the top-level methods. We'll
dig in to the leaf stuff later. Surprisingly, this all went without
any real difficulties.

Runs like a charm on first try.
This commit is contained in:
2026-05-24 16:12:29 -04:00
parent c539e6e924
commit cde2737876
44 changed files with 1296 additions and 1530 deletions
@@ -17,11 +17,11 @@
#include <boost/system/error_code.hpp>
#include <livoxProto1/device.h>
#include <livoxProto1/livoxProto1.h>
#include <spinscale/asynchronousContinuation.h>
#include <spinscale/cps/asynchronousContinuation.h>
#include <spinscale/asynchronousLoop.h>
#include <spinscale/asynchronousBridge.h>
#include <spinscale/callback.h>
#include <spinscale/callableTracer.h>
#include <spinscale/cps/asynchronousBridge.h>
#include <spinscale/cps/callback.h>
#include <spinscale/cps/callableTracer.h>
#include <spinscale/spinLock.h>
#include "ioUringAssemblyEngine.h"
#include "pcloudStimulusProducer.h"
@@ -175,7 +175,7 @@ void IoUringAssemblyEngine::finalize()
{
auto& ioService = smoHooksPtr->ComponentThread_getSelf()->getIoService();
sscl::AsynchronousBridge bridge(ioService);
sscl::cps::AsynchronousBridge bridge(ioService);
boost::asio::deadline_timer timeoutTimer(ioService);
/** EXPLANATION:
@@ -420,15 +420,15 @@ cleanup_eventfd:
// Continuation class for assembleFrameReq
class IoUringAssemblyEngine::AssembleFrameReq
: public sscl::PostedAsynchronousContinuation<
: public sscl::cps::PostedAsynchronousContinuation<
IoUringAssemblyEngine::assembleFrameReqCbFn>
{
public:
AssembleFrameReq(
IoUringAssemblyEngine& engine_,
const std::shared_ptr<sscl::ComponentThread>& caller,
sscl::Callback<IoUringAssemblyEngine::assembleFrameReqCbFn> cb)
: sscl::PostedAsynchronousContinuation<
sscl::cps::Callback<IoUringAssemblyEngine::assembleFrameReqCbFn> cb)
: sscl::cps::PostedAsynchronousContinuation<
IoUringAssemblyEngine::assembleFrameReqCbFn>(caller, cb),
engine(engine_),
loop(engine_.frameAssemblyDesc->numSlots),
@@ -635,7 +635,7 @@ public:
};
void IoUringAssemblyEngine::assembleFrameReq(
sscl::Callback<assembleFrameReqCbFn> cb)
sscl::cps::Callback<assembleFrameReqCbFn> cb)
{
{
sscl::SpinLock::Guard lock(shouldAcceptRequestsLock);
@@ -16,9 +16,9 @@
#include <boost/asio/deadline_timer.hpp>
#include <boost/asio/posix/stream_descriptor.hpp>
#include <livoxProto1/device.h>
#include <spinscale/asynchronousContinuation.h>
#include <spinscale/cps/asynchronousContinuation.h>
#include <spinscale/asynchronousLoop.h>
#include <spinscale/callback.h>
#include <spinscale/cps/callback.h>
#include <spinscale/spinLock.h>
#include <user/frameAssemblyDesc.h>
#include <user/stagingBuffer.h>
@@ -42,7 +42,7 @@ public:
void finalize();
typedef std::function<void(bool, sscl::AsynchronousLoop)> assembleFrameReqCbFn;
void assembleFrameReq(sscl::Callback<assembleFrameReqCbFn> cb);
void assembleFrameReq(sscl::cps::Callback<assembleFrameReqCbFn> cb);
// Telemetry helpers
static size_t computePointsPerFrame(int returnMode, size_t nDgramsPerFrame)
+10 -10
View File
@@ -11,11 +11,11 @@
#include <user/senseApiDesc.h>
#include <user/deviceAttachmentSpec.h>
#include <user/intrinThresholdParams.h>
#include <spinscale/callback.h>
#include <spinscale/cps/callback.h>
#include <livoxProto1/livoxProto1.h>
#include <livoxProto1/device.h>
#include <livoxProto1/protocol.h>
#include <spinscale/asynchronousContinuation.h>
#include <spinscale/cps/asynchronousContinuation.h>
#include <boost/asio/deadline_timer.hpp>
#include "pcloudStimulusProducer.h"
#include "livoxGen1.h"
@@ -91,13 +91,13 @@ LivoxProto1DllState livoxProto1;
// Continuation classes for async operations
class AttachDeviceReq
: public sscl::NonPostedAsynchronousContinuation<sal_mlo_attachDeviceReqCbFn>
: public sscl::cps::NonPostedAsynchronousContinuation<sal_mlo_attachDeviceReqCbFn>
{
public:
AttachDeviceReq(
const std::shared_ptr<smo::device::DeviceAttachmentSpec>& spec,
sscl::Callback<sal_mlo_attachDeviceReqCbFn> cb)
: sscl::NonPostedAsynchronousContinuation<sal_mlo_attachDeviceReqCbFn>(
sscl::cps::Callback<sal_mlo_attachDeviceReqCbFn> cb)
: sscl::cps::NonPostedAsynchronousContinuation<sal_mlo_attachDeviceReqCbFn>(
std::move(cb)),
spec(spec)
{}
@@ -360,14 +360,14 @@ public:
};
class DetachDeviceReq
: public sscl::NonPostedAsynchronousContinuation<sal_mlo_detachDeviceReqCbFn>
: public sscl::cps::NonPostedAsynchronousContinuation<sal_mlo_detachDeviceReqCbFn>
{
public:
DetachDeviceReq(
const std::shared_ptr<smo::device::DeviceAttachmentSpec>& spec,
const std::shared_ptr<StimulusBuffer>& stimBuffer,
sscl::Callback<sal_mlo_detachDeviceReqCbFn> cb)
: sscl::NonPostedAsynchronousContinuation<sal_mlo_detachDeviceReqCbFn>(
sscl::cps::Callback<sal_mlo_detachDeviceReqCbFn> cb)
: sscl::cps::NonPostedAsynchronousContinuation<sal_mlo_detachDeviceReqCbFn>(
std::move(cb)),
spec(spec), stimBuffer(stimBuffer)
{}
@@ -625,7 +625,7 @@ extern "C" int livoxGen1_finalizeInd(void)
extern "C" void livoxGen1_attachDeviceReq(
const std::shared_ptr<smo::device::DeviceAttachmentSpec>& desc,
const std::shared_ptr<sscl::ComponentThread>& componentThread,
sscl::Callback<smo::stim_buff::sal_mlo_attachDeviceReqCbFn> cb
sscl::cps::Callback<smo::stim_buff::sal_mlo_attachDeviceReqCbFn> cb
)
{
if (!livoxProto1.livoxProto1_getOrCreateDeviceReq)
@@ -825,7 +825,7 @@ extern "C" void livoxGen1_attachDeviceReq(
extern "C" void livoxGen1_detachDeviceReq(
const std::shared_ptr<smo::device::DeviceAttachmentSpec>& desc,
sscl::Callback<smo::stim_buff::sal_mlo_detachDeviceReqCbFn> cb
sscl::cps::Callback<smo::stim_buff::sal_mlo_detachDeviceReqCbFn> cb
)
{
// Case 1: Check if StimBuffer doesn't exist (early return)
@@ -9,9 +9,9 @@
#include <algorithm>
#include <boost/system/error_code.hpp>
#include <boost/asio/deadline_timer.hpp>
#include <spinscale/asynchronousContinuation.h>
#include <spinscale/asynchronousBridge.h>
#include <spinscale/callback.h>
#include <spinscale/cps/asynchronousContinuation.h>
#include <spinscale/cps/asynchronousBridge.h>
#include <spinscale/cps/callback.h>
#include <spinscale/asynchronousLoop.h>
#include <componentThread.h>
#include <user/stimulusFrame.h>
@@ -229,7 +229,7 @@ void OpenClCollatingAndMeshingEngine::finalize()
int delayMs = std::max(OCLCOLLMESH_ENGN_FINALIZE_DELAY_MS, 0);
auto& ioService = smoHooksPtr->ComponentThread_getSelf()->getIoService();
sscl::AsynchronousBridge bridge(ioService);
sscl::cps::AsynchronousBridge bridge(ioService);
boost::asio::deadline_timer timeoutTimer(ioService);
/** EXPLANATION:
@@ -1008,7 +1008,7 @@ void OpenClCollatingAndMeshingEngine::produceAmbienceStimulusFrame(
}
class OpenClCollatingAndMeshingEngine::CompactCollateAndMeshFrameReq
: public sscl::PostedAsynchronousContinuation<compactCollateAndMeshFrameReqCbFn>
: public sscl::cps::PostedAsynchronousContinuation<compactCollateAndMeshFrameReqCbFn>
{
private:
OpenClCollatingAndMeshingEngine& engine;
@@ -1027,8 +1027,8 @@ public:
std::optional<AmbienceProductionDesc> lightAmbienceProductionDesc_,
std::optional<AmbienceProductionDesc> darkAmbienceProductionDesc_,
const std::shared_ptr<sscl::ComponentThread>& caller,
sscl::Callback<compactCollateAndMeshFrameReqCbFn> cb)
: sscl::PostedAsynchronousContinuation<compactCollateAndMeshFrameReqCbFn>(
sscl::cps::Callback<compactCollateAndMeshFrameReqCbFn> cb)
: sscl::cps::PostedAsynchronousContinuation<compactCollateAndMeshFrameReqCbFn>(
caller, cb),
engine(engine_),
frameAssemblyResult(asyncLoop), stimulusFrame(stimulusFrame_),
@@ -1253,7 +1253,7 @@ void OpenClCollatingAndMeshingEngine::compactCollateAndMeshFrameReq(
std::optional<std::reference_wrapper<StimulusFrame>> intensityStimFrame,
std::optional<AmbienceProductionDesc> lightAmbienceProductionDesc,
std::optional<AmbienceProductionDesc> darkAmbienceProductionDesc,
sscl::Callback<compactCollateAndMeshFrameReqCbFn> callback)
sscl::cps::Callback<compactCollateAndMeshFrameReqCbFn> callback)
{
{
sscl::SpinLock::Guard lock(shouldAcceptRequestsLock);
@@ -14,7 +14,7 @@
#define CL_TARGET_OPENCL_VERSION 120
#include <CL/cl.h>
#include <spinscale/asynchronousLoop.h>
#include <spinscale/callback.h>
#include <spinscale/cps/callback.h>
#include <spinscale/spinLock.h>
#include <user/stimulusFrame.h>
#include <user/stagingBuffer.h>
@@ -94,7 +94,7 @@ public:
std::optional<std::reference_wrapper<StimulusFrame>> intensityStimFrame,
std::optional<AmbienceProductionDesc> lightAmbienceProductionDesc,
std::optional<AmbienceProductionDesc> darkAmbienceProductionDesc,
sscl::Callback<compactCollateAndMeshFrameReqCbFn> callback);
sscl::cps::Callback<compactCollateAndMeshFrameReqCbFn> callback);
private:
// Callback function types
@@ -426,7 +426,7 @@ void PcloudStimulusProducer::stimFrameProductionTimesliceInd()
}
class PcloudStimulusProducer::ProduceFrameReq
: public sscl::PostedAsynchronousContinuation<produceFrameReqCbFn>
: public sscl::cps::PostedAsynchronousContinuation<produceFrameReqCbFn>
{
private:
PcloudStimulusProducer& pcloudProducer;
@@ -440,8 +440,8 @@ public:
ProduceFrameReq(
PcloudStimulusProducer& producer,
const std::shared_ptr<sscl::ComponentThread>& caller,
sscl::Callback<produceFrameReqCbFn> cb)
: sscl::PostedAsynchronousContinuation<produceFrameReqCbFn>(caller, cb),
sscl::cps::Callback<produceFrameReqCbFn> cb)
: sscl::cps::PostedAsynchronousContinuation<produceFrameReqCbFn>(caller, cb),
pcloudProducer(producer),
frameAssemblyResult(0),
stimulusFrame(producer.tempStimulusFrame)
@@ -724,7 +724,7 @@ public:
};
void PcloudStimulusProducer::produceFrameReq(
sscl::Callback<produceFrameReqCbFn> callback)
sscl::cps::Callback<produceFrameReqCbFn> callback)
{
/** EXPLANATION:
* We shouldn't acquire the StimulusProducer::shouldContinueLock here because
@@ -6,8 +6,8 @@
#include <user/stimulusProducer.h>
#include <user/stimulusFrame.h>
#include <livoxProto1/device.h>
#include <spinscale/asynchronousContinuation.h>
#include <spinscale/callback.h>
#include <spinscale/cps/asynchronousContinuation.h>
#include <spinscale/cps/callback.h>
#include <user/stagingBuffer.h>
#include "ioUringAssemblyEngine.h"
#include "livoxPcloudFrameDumper.h"
@@ -87,7 +87,7 @@ protected:
typedef std::function<void()> produceFrameReqCbFn;
public:
void produceFrameReq(sscl::Callback<produceFrameReqCbFn> callback);
void produceFrameReq(sscl::cps::Callback<produceFrameReqCbFn> callback);
size_t nDgramsPerStagingBufferFrame;
std::shared_ptr<livoxProto1::Device> device;
+3 -3
View File
@@ -8,7 +8,7 @@
#include <xcb/xcb.h>
#include <user/senseApiDesc.h>
#include <user/deviceAttachmentSpec.h>
#include <spinscale/callback.h>
#include <spinscale/cps/callback.h>
#include <xcbXorg/xcbXorg.h>
#include "xcbWindow.h"
@@ -277,7 +277,7 @@ static int xcbWindow_finalizeInd(void)
static void xcbWindow_attachDeviceReq(
const std::shared_ptr<smo::device::DeviceAttachmentSpec>& desc,
const std::shared_ptr<sscl::ComponentThread>& componentThread,
sscl::Callback<smo::stim_buff::sal_mlo_attachDeviceReqCbFn> cb
sscl::cps::Callback<smo::stim_buff::sal_mlo_attachDeviceReqCbFn> cb
)
{
// Not used yet, but may be used later.
@@ -302,7 +302,7 @@ static void xcbWindow_attachDeviceReq(
static void xcbWindow_detachDeviceReq(
const std::shared_ptr<smo::device::DeviceAttachmentSpec>& spec,
sscl::Callback<smo::stim_buff::sal_mlo_detachDeviceReqCbFn> cb
sscl::cps::Callback<smo::stim_buff::sal_mlo_detachDeviceReqCbFn> cb
)
{
auto it = std::find_if(g_attachedWindows.begin(), g_attachedWindows.end(),