Async: Drop-in SyncCancelerForAsyncWork without execUncancelableSegment*

We're doing this to prep for the coro port
This commit is contained in:
2026-05-30 10:52:15 -04:00
parent c7dee57072
commit f100764bd8
9 changed files with 72 additions and 91 deletions
@@ -39,7 +39,6 @@ clAverageIntensityBufferClBuffer(nullptr),
clAssemblyBuffer(nullptr),
clCollationBuffer(nullptr),
clAverageIntensityBuffer(nullptr),
shouldAcceptRequests(false),
compactIsRunning(false),
collateIsRunning(false),
currentCompactKernelEvent(nullptr), currentCollateKernelEvent(nullptr),
@@ -64,13 +63,10 @@ OpenClCollatingAndMeshingEngine::~OpenClCollatingAndMeshingEngine()
bool OpenClCollatingAndMeshingEngine::setup()
{
// Defensive check to prevent double-calling
if (!openClCollMeshEngnCanceler.isCancellationRequested())
{
sscl::SpinLock::Guard lock(shouldAcceptRequestsLock);
if (shouldAcceptRequests)
{
throw std::runtime_error(std::string(__func__) + ": setup() called "
"while already set up");
}
throw std::runtime_error(std::string(__func__) + ": setup() called "
"while already set up");
}
if (!smoHooksPtr || !smoHooksPtr->ComputeManager_getDevice)
@@ -202,13 +198,13 @@ bool OpenClCollatingAndMeshingEngine::setup()
clFlush(computeDevice->commandQueue);
clFinish(computeDevice->commandQueue);
shouldAcceptRequests = true;
openClCollMeshEngnCanceler.startAcceptingWork();
return true;
}
void OpenClCollatingAndMeshingEngine::finalize()
{
// Call stop() to set shouldAcceptRequests to false and get previous state
// Call stop() to clear shouldContinue and get previous state
bool wasAcceptingRequests = stop();
(void)wasAcceptingRequests;
@@ -771,11 +767,7 @@ bool OpenClCollatingAndMeshingEngine::setupCollateDgramsArgs(
bool OpenClCollatingAndMeshingEngine::stop()
{
// Acquire and release lock tightly around setting the flag
sscl::SpinLock::Guard lock(shouldAcceptRequestsLock);
bool wasAcceptingRequests = shouldAcceptRequests;
shouldAcceptRequests = false;
return wasAcceptingRequests;
return openClCollMeshEngnCanceler.requestStop();
}
void OpenClCollatingAndMeshingEngine::compactKernelComplete(bool isFinalizing)
@@ -1051,8 +1043,8 @@ public:
void compactCollateAndMeshFrameReq1_doCompact_posted(
std::shared_ptr<CompactCollateAndMeshFrameReq> context)
{
sscl::SpinLock::Guard lock(engine.shouldAcceptRequestsLock);
if (!engine.shouldAcceptRequests)
sscl::SpinLock::Guard guard(engine.openClCollMeshEngnCanceler.s.lock);
if (engine.openClCollMeshEngnCanceler.isCancellationRequestedUnlocked())
{
callOriginalCallback(false);
return;
@@ -1082,8 +1074,8 @@ public:
std::shared_ptr<CompactCollateAndMeshFrameReq> context,
cl_int compactStatus)
{
sscl::SpinLock::Guard lock(engine.shouldAcceptRequestsLock);
if (!engine.shouldAcceptRequests)
sscl::SpinLock::Guard guard(engine.openClCollMeshEngnCanceler.s.lock);
if (engine.openClCollMeshEngnCanceler.isCancellationRequestedUnlocked())
{
/** EXPLANATION:
* We intentionally don't call compactKernelComplete() here because
@@ -1116,15 +1108,15 @@ public:
}
#endif
lock.unlockPrematurely();
guard.unlockPrematurely();
context->compactCollateAndMeshFrameReq3_doCollate_posted(context);
}
void compactCollateAndMeshFrameReq3_doCollate_posted(
std::shared_ptr<CompactCollateAndMeshFrameReq> context)
{
sscl::SpinLock::Guard lock(engine.shouldAcceptRequestsLock);
if (!engine.shouldAcceptRequests)
sscl::SpinLock::Guard guard(engine.openClCollMeshEngnCanceler.s.lock);
if (engine.openClCollMeshEngnCanceler.isCancellationRequestedUnlocked())
{
callOriginalCallback(false);
return;
@@ -1155,8 +1147,8 @@ public:
[[maybe_unused]] std::shared_ptr<CompactCollateAndMeshFrameReq> context,
cl_int collateStatus)
{
sscl::SpinLock::Guard lock(engine.shouldAcceptRequestsLock);
if (!engine.shouldAcceptRequests)
sscl::SpinLock::Guard guard(engine.openClCollMeshEngnCanceler.s.lock);
if (engine.openClCollMeshEngnCanceler.isCancellationRequestedUnlocked())
{
/* We intentionally don't call collateKernelComplete() here for the
* same reason as above.
@@ -1256,8 +1248,8 @@ void OpenClCollatingAndMeshingEngine::compactCollateAndMeshFrameReq(
sscl::cps::Callback<compactCollateAndMeshFrameReqCbFn> callback)
{
{
sscl::SpinLock::Guard lock(shouldAcceptRequestsLock);
if (!shouldAcceptRequests)
sscl::SpinLock::Guard guard(openClCollMeshEngnCanceler.s.lock);
if (openClCollMeshEngnCanceler.isCancellationRequestedUnlocked())
{
callback.callbackFn(false, stimulusFrame);
return;