Skip to content

Commit

Permalink
Config init cnt is fixed.
Browse files Browse the repository at this point in the history
  • Loading branch information
i0gan committed Sep 21, 2024
1 parent 0d7cbfe commit de3a402
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
7 changes: 3 additions & 4 deletions src/squick/plugin/config/class_module.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ ClassModule::ClassModule(IPluginManager *p) {
#endif

if (!this->mbBackup) {
// IThreadPoolModule *threadPoolModule = pm_->FindModule<IThreadPoolModule>();
// 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();
Expand Down Expand Up @@ -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();

Expand All @@ -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;
}

Expand Down
7 changes: 6 additions & 1 deletion src/squick/plugin/config/element_module.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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();

Expand Down
3 changes: 2 additions & 1 deletion src/squick/plugin/config/element_module.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include <thread>

class Class;

#define CONFIG_DATA_THREADS_CAN_BE_USED_CNT 1
class ElementConfigInfo {
public:
ElementConfigInfo() {
Expand Down Expand Up @@ -55,6 +55,7 @@ class ElementModule : public IElementModule, MapEx<std::string, ElementConfigInf
virtual bool AfterStart() override;
virtual bool BeforeDestroy() override;
virtual bool Update() override;
virtual bool Reload(int type) override;

virtual bool Load() override;
virtual bool Save() override;
Expand Down

0 comments on commit de3a402

Please sign in to comment.