Skip to content

Commit

Permalink
hotfix: move Executors initialization to a source file (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
piotrmacha committed May 26, 2024
1 parent 29c2282 commit 2dc9a17
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
11 changes: 6 additions & 5 deletions src/NH/Executor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,22 @@

namespace NH
{
CommonExecutors Executors = {
.IO = ThreadPool("IO", std::thread::hardware_concurrency())
};

ThreadPool::ThreadPool(const String& name, size_t threads)
: Executor(), m_Name(name), log(NH::CreateLogger(String::Format("zBassMusic::ThreadPool({0})", name)))
{
for (size_t i = 0; i < threads; i++)
{
m_Threads.emplace_back([this]()
auto& thread = m_Threads.emplace_back([this]()
{
log->Info("[thread-{0}] started", std::format("{}", std::this_thread::get_id()).c_str());
EventLoop();
log->Info("[thread-{0}] exiting", std::format("{}", std::this_thread::get_id()).c_str());
});
for (auto& thread: m_Threads)
{
thread.detach();
}
thread.detach();
}
}

Expand Down
8 changes: 5 additions & 3 deletions src/NH/Executor.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ namespace NH
void EventLoop();
};

struct {
ThreadPool IO = ThreadPool("IO", std::thread::hardware_concurrency());
} Executors;
struct CommonExecutors {
ThreadPool IO;
};

extern CommonExecutors Executors;
}

0 comments on commit 2dc9a17

Please sign in to comment.