Skip to content

Commit

Permalink
improve
Browse files Browse the repository at this point in the history
  • Loading branch information
mehah committed Nov 24, 2023
1 parent ea07201 commit 295eeaa
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 11 deletions.
10 changes: 4 additions & 6 deletions src/framework/core/asyncdispatcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ void AsyncDispatcher::init(uint8_t maxThreads)
if (maxThreads == 0)
maxThreads = 6;

// -2 = Main Thread and Map Thread
int_fast8_t threads = std::clamp<int_fast8_t>(std::thread::hardware_concurrency() - 2, 1, maxThreads);
int_fast8_t threads = std::clamp<int_fast8_t>(std::thread::hardware_concurrency() - 1, 1, maxThreads);
while (--threads >= 0)
m_threads.emplace_back([this] { m_ioService.run(); });
}
Expand All @@ -45,9 +44,8 @@ void AsyncDispatcher::stop()

m_ioService.stop();

for (std::size_t i = 0; i < m_threads.size(); i++) {
if (m_threads[i].joinable()) {
m_threads[i].join();
}
for (auto& thread : m_threads) {
if (thread.joinable())
thread.join();
}
};
6 changes: 1 addition & 5 deletions src/framework/core/graphicalapplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,8 @@ void GraphicalApplication::run()
const auto& foreground = g_drawPool.get(DrawPoolType::FOREGROUND);
const auto& foreground_tile = g_drawPool.get(DrawPoolType::FOREGROUND_TILE);
const auto& txt = g_drawPool.get(DrawPoolType::TEXT);
const auto& map = g_drawPool.get(DrawPoolType::MAP);

// clang c++20 dont support jthread
std::thread t1([&]() {
g_asyncDispatcher.dispatch([&] {
g_eventThreadId = std::this_thread::get_id();
while (!m_stopping) {
poll();
Expand Down Expand Up @@ -194,8 +192,6 @@ void GraphicalApplication::run()
m_frameCounter.update();
}

t1.join();

m_stopping = false;
m_running = false;
}
Expand Down

0 comments on commit 295eeaa

Please sign in to comment.