diff --git a/libs/util/CMakeLists.txt b/libs/util/CMakeLists.txt index 11b79d25..3f74f9fa 100644 --- a/libs/util/CMakeLists.txt +++ b/libs/util/CMakeLists.txt @@ -5,4 +5,4 @@ file(GLOB_RECURSE PSEMEK_UTIL_SOURCES RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "so add_library(psemek-util ${PSEMEK_UTIL_HEADERS} ${PSEMEK_UTIL_SOURCES}) target_include_directories(psemek-util PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include") -target_link_libraries(psemek-util PUBLIC ${CMAKE_THREAD_LIBS_INIT}) +target_link_libraries(psemek-util PUBLIC psemek-log ${CMAKE_THREAD_LIBS_INIT}) diff --git a/libs/util/include/psemek/util/threadpool.hpp b/libs/util/include/psemek/util/threadpool.hpp index 2ee490b4..40f0b22e 100644 --- a/libs/util/include/psemek/util/threadpool.hpp +++ b/libs/util/include/psemek/util/threadpool.hpp @@ -6,17 +6,19 @@ #include #include +#include namespace psemek::util { struct threadpool { - threadpool() - : threadpool(std::max(1u, std::thread::hardware_concurrency())) + threadpool(std::string const & name) + : threadpool(name, std::max(1u, std::thread::hardware_concurrency())) {} - threadpool(std::size_t thread_count) + threadpool(std::string const & name, std::size_t thread_count) + : name(name) { start(thread_count); } @@ -50,6 +52,7 @@ namespace psemek::util } private: + std::string const name; std::vector threads; util::synchronized_queue> tasks_queue; }; diff --git a/libs/util/source/threadpool.cpp b/libs/util/source/threadpool.cpp index ca6d46e9..9faa2989 100644 --- a/libs/util/source/threadpool.cpp +++ b/libs/util/source/threadpool.cpp @@ -1,5 +1,8 @@ #include #include +#include + +#include namespace psemek::util { @@ -8,8 +11,9 @@ namespace psemek::util { for (std::size_t th = 0; th < thread_count; ++th) { - threads.emplace_back([this] + threads.emplace_back([this, th] { + log::register_thread(to_string(name, '#', th)); while (true) { auto task = tasks_queue.pop();