From ca9eae197f12141bd48a2a75ff1ceb916f27031b Mon Sep 17 00:00:00 2001 From: Hayodea Hekol Date: Tue, 30 Sep 2025 02:55:25 -0400 Subject: [PATCH] Lockvoker: Add registerInLockSet We now create the sh_ptr to the copy of a lockvoker object in its own supplied register method. This enables us to retain type safety when calling make_shared, by copying the most derived version of the lockvoker object. Then we can pass in the LockerAndInvokerBase to the rest of the call chain. --- include/lockSet.h | 3 +-- include/serializedAsynchronousContinuation.h | 15 ++++++++++++++- smocore/lockSet.cpp | 8 ++------ 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/include/lockSet.h b/include/lockSet.h index 00acc13..19dbedb 100644 --- a/include/lockSet.h +++ b/include/lockSet.h @@ -74,9 +74,8 @@ public: * cleaned up in the qutexQ's std::list destructor -- and that won't * execute any fancy cleanup logic. It'll just clear() out the list. */ - template void registerInQutexQueues( - const typename SerializedAsynchronousContinuation::template LockerAndInvoker &lockvoker); + const std::shared_ptr &lockvoker); /** * @brief Try to acquire all locks in order; back off if acquisition fails diff --git a/include/serializedAsynchronousContinuation.h b/include/serializedAsynchronousContinuation.h index f7f5d4d..796d637 100644 --- a/include/serializedAsynchronousContinuation.h +++ b/include/serializedAsynchronousContinuation.h @@ -253,6 +253,19 @@ public: void allowAwakening() { serializedContinuation.isAwakeOrBeingAwakened.store(false); } + /** EXPLANATION: + * Creates a shared_ptr copy of this lockvoker and registers it with + * the serialized continuation's LockSet. + */ + void registerInLockSet() + { + auto sharedLockvoker = std::make_shared< + LockerAndInvoker>(*this); + + serializedContinuation.requiredLocks.registerInQutexQueues( + sharedLockvoker); + } + /** * @brief First wake - register in queues and awaken * @@ -263,7 +276,7 @@ public: void firstWake() { serializedContinuation.isAwakeOrBeingAwakened.store(true); - serializedContinuation.requiredLocks.registerInQutexQueues(*this); + registerInLockSet(); // Force awaken since we just set the flag above awaken(true); } diff --git a/smocore/lockSet.cpp b/smocore/lockSet.cpp index d180fce..15a98c6 100644 --- a/smocore/lockSet.cpp +++ b/smocore/lockSet.cpp @@ -7,9 +7,8 @@ namespace smo { // These will be explicitly instantiated for the types we need template -template void LockSet::registerInQutexQueues( - const typename SerializedAsynchronousContinuation::template LockerAndInvoker &lockvoker + const std::shared_ptr &lockvoker ) { /** EXPLANATION: @@ -34,13 +33,10 @@ void LockSet::registerInQutexQueues( * io_service, potentially without being executed if they fail to * acquire all locks. */ - auto sharedLockvoker = std::make_shared< - typename SerializedAsynchronousContinuation::template LockerAndInvoker>(lockvoker); - for (auto& lockUsageDesc : locks) { lockUsageDesc.second = lockUsageDesc.first.get().registerInQueue( - sharedLockvoker); + lockvoker); } registeredInQutexQueues = true;