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.
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
#ifndef CALLBACK_H
|
||||
#define CALLBACK_H
|
||||
|
||||
#include <memory>
|
||||
#include <functional>
|
||||
|
||||
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<typename CbFnT>
|
||||
class Callback
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* @brief Constructor
|
||||
* @param caller The caller's continuation
|
||||
* @param cb The callback function to invoke
|
||||
*/
|
||||
Callback(std::shared_ptr<AsyncContinuation> caller, std::function<CbFnT> cb)
|
||||
: callerContinuation(std::move(caller)), callback(std::move(cb))
|
||||
{}
|
||||
|
||||
public:
|
||||
std::shared_ptr<AsyncContinuation> callerContinuation;
|
||||
std::function<CbFnT> callback;
|
||||
};
|
||||
|
||||
} // namespace smo
|
||||
|
||||
#endif // CALLBACK_H
|
||||
Reference in New Issue
Block a user