From d0303becd737cd50484950ff2a767bd9b8fde4ff Mon Sep 17 00:00:00 2001 From: Hayodea Hakol Date: Mon, 22 Sep 2025 21:30:33 -0400 Subject: [PATCH] Async: Add a new Callback class for accessing caller's contin We previously passed a sh_ptr to the caller's contin as arguments to the std::bind() callable. In order for us to be able to trace deadlocks, we need to be able to access them explicitly. So here's that change. --- include/callback.h | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 include/callback.h diff --git a/include/callback.h b/include/callback.h new file mode 100644 index 0000000..2a6e98c --- /dev/null +++ b/include/callback.h @@ -0,0 +1,39 @@ +#ifndef CALLBACK_H +#define CALLBACK_H + +#include +#include + +namespace smo { + +// Forward declaration +class AsyncContinuation; + +/** + * @brief Callback class that wraps a function and its caller continuation + * + * This class provides a way to pass both a callback function and the + * caller's continuation in a single object, enabling deadlock detection + * by walking the chain of continuations. + */ +template +class Callback +{ +public: + /** + * @brief Constructor + * @param caller The caller's continuation + * @param cb The callback function to invoke + */ + Callback(std::shared_ptr caller, std::function cb) + : callerContinuation(std::move(caller)), callback(std::move(cb)) + {} + +public: + std::shared_ptr callerContinuation; + std::function callback; +}; + +} // namespace smo + +#endif // CALLBACK_H