From 237367dfd3f00691a581344d5c277f3a26933c88 Mon Sep 17 00:00:00 2001 From: Kevin Chou Date: Mon, 10 Nov 2025 14:42:52 +0800 Subject: [PATCH 1/2] check module registration before unregistering --- src/bthread/eloq_module.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/bthread/eloq_module.cpp b/src/bthread/eloq_module.cpp index 9876bf34..8585ce00 100644 --- a/src/bthread/eloq_module.cpp +++ b/src/bthread/eloq_module.cpp @@ -47,6 +47,17 @@ namespace eloq { } int unregister_module(EloqModule *module) { + // Verify that the module is currently registered. + std::shared_lock s_lk(module_mutex); + const bool exists = std::find(registered_modules.begin(), + registered_modules.end(), + module) != registered_modules.end(); + if (!exists) { + LOG(WARNING) << "Attempted to unregister a non-registered module: " << module; + return -1; + } + s_lk.unlock(); + const auto concurrency = bthread_get_task_control()->concurrency(); while (module->registered_workers_.load(std::memory_order_acquire) != concurrency) { for (int thd_id = 0; thd_id < concurrency; ++thd_id) { From 237c3594b530e4e9ae15b2d706d6feeb3052de81 Mon Sep 17 00:00:00 2001 From: Kevin Chou Date: Mon, 10 Nov 2025 14:48:42 +0800 Subject: [PATCH 2/2] format --- src/bthread/eloq_module.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/bthread/eloq_module.cpp b/src/bthread/eloq_module.cpp index 8585ce00..309e457d 100644 --- a/src/bthread/eloq_module.cpp +++ b/src/bthread/eloq_module.cpp @@ -23,8 +23,9 @@ #include "bthread/bthread.h" extern "C" { - bthread::TaskControl* bthread_get_task_control(); +bthread::TaskControl *bthread_get_task_control(); } + extern std::array registered_modules; extern std::atomic registered_module_cnt; @@ -50,8 +51,8 @@ namespace eloq { // Verify that the module is currently registered. std::shared_lock s_lk(module_mutex); const bool exists = std::find(registered_modules.begin(), - registered_modules.end(), - module) != registered_modules.end(); + registered_modules.end(), + module) != registered_modules.end(); if (!exists) { LOG(WARNING) << "Attempted to unregister a non-registered module: " << module; return -1;