From 3aeb5a06fcd2e1348b757e35ae0572e42e944312 Mon Sep 17 00:00:00 2001 From: Xie Han <63350856@qq.com> Date: Mon, 13 Jan 2025 17:52:20 +0800 Subject: [PATCH] Enable to set connection context without changing deleter. --- src/factory/WFConnection.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/factory/WFConnection.h b/src/factory/WFConnection.h index 68adf05a86..9d6b43fbd2 100644 --- a/src/factory/WFConnection.h +++ b/src/factory/WFConnection.h @@ -38,6 +38,11 @@ class WFConnection : public CommConnection this->deleter = std::move(deleter); } + void set_context(void *context) + { + this->context = context; + } + void *test_set_context(void *test_context, void *new_context, std::function deleter) { @@ -50,6 +55,14 @@ class WFConnection : public CommConnection return test_context; } + void *test_set_context(void *test_context, void *new_context) + { + if (this->context.compare_exchange_strong(test_context, new_context)) + return new_context; + + return test_context; + } + private: std::atomic context; std::function deleter;