From de3a402b09ba28f422456425545d2978a65ff214 Mon Sep 17 00:00:00 2001 From: i0gan Date: Sat, 21 Sep 2024 16:44:09 +0800 Subject: [PATCH] Config init cnt is fixed. --- src/squick/plugin/config/class_module.cc | 7 +++---- src/squick/plugin/config/element_module.cc | 7 ++++++- src/squick/plugin/config/element_module.h | 3 ++- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/squick/plugin/config/class_module.cc b/src/squick/plugin/config/class_module.cc index 0843b004..83d6c6c9 100644 --- a/src/squick/plugin/config/class_module.cc +++ b/src/squick/plugin/config/class_module.cc @@ -17,9 +17,7 @@ ClassModule::ClassModule(IPluginManager *p) { #endif if (!this->mbBackup) { - // IThreadPoolModule *threadPoolModule = pm_->FindModule(); - // const int threadCount = threadPoolModule->GetThreadCount(); - for (int i = 0; i < 10; ++i) { + for (int i = 0; i < CONFIG_DATA_THREADS_CAN_BE_USED_CNT; ++i) { ThreadClassModule threadElement; threadElement.used = false; threadElement.classModule = new ClassModule(); @@ -64,6 +62,7 @@ bool ClassModule::Destroy() { return true; } +// Get a free class module for find IClassModule *ClassModule::GetThreadClassModule() { std::thread::id threadID = std::this_thread::get_id(); @@ -73,12 +72,12 @@ IClassModule *ClassModule::GetThreadClassModule() { return mThreadClasses[i].classModule; } } else { + // init for this thread mThreadClasses[i].used = true; mThreadClasses[i].threadID = threadID; return mThreadClasses[i].classModule; } } - return nullptr; } diff --git a/src/squick/plugin/config/element_module.cc b/src/squick/plugin/config/element_module.cc index 70785180..01952434 100644 --- a/src/squick/plugin/config/element_module.cc +++ b/src/squick/plugin/config/element_module.cc @@ -16,7 +16,7 @@ ElementModule::ElementModule(IPluginManager *p) { mbLoaded = false; if (!this->mbBackup) { - for (int i = 0; i < pm_->GetAppCPUCount(); ++i) { + for (int i = 0; i < CONFIG_DATA_THREADS_CAN_BE_USED_CNT; ++i) { ThreadElementModule threadElement; threadElement.used = false; threadElement.elementModule = new ElementModule(this); @@ -84,6 +84,11 @@ bool ElementModule::Destroy() { return true; } +bool ElementModule::Reload(int type) +{ + return true; +} + IElementModule *ElementModule::GetThreadElementModule() { std::thread::id threadID = std::this_thread::get_id(); diff --git a/src/squick/plugin/config/element_module.h b/src/squick/plugin/config/element_module.h index 935611f7..c546503e 100644 --- a/src/squick/plugin/config/element_module.h +++ b/src/squick/plugin/config/element_module.h @@ -19,7 +19,7 @@ #include class Class; - +#define CONFIG_DATA_THREADS_CAN_BE_USED_CNT 1 class ElementConfigInfo { public: ElementConfigInfo() { @@ -55,6 +55,7 @@ class ElementModule : public IElementModule, MapEx