minior thread pool change

v1
Brett 2024-03-22 11:30:58 -04:00
parent 9bba525b1f
commit 6a5b7a6865
2 changed files with 6 additions and 4 deletions

View File

@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 3.5)
include(cmake/color.cmake)
set(BLT_VERSION 0.15.0)
set(BLT_VERSION 0.15.1)
set(BLT_TEST_VERSION 0.0.1)
set(BLT_TARGET BLT)

View File

@ -47,6 +47,7 @@ namespace blt
std::vector<std::thread*> threads;
std::variant<std::queue<thread_function>, thread_function> func_queue;
std::mutex queue_mutex;
bool func_loaded = false;
public:
explicit thread_pool(std::uint64_t number_of_threads = 8, std::optional<thread_function> default_function = {})
{
@ -76,14 +77,15 @@ namespace blt
func();
} else
{
{
if (!func_loaded){
std::scoped_lock lock(queue_mutex);
if (std::holds_alternative<std::queue<thread_function>>(func_queue))
{
std::this_thread::sleep_for(std::chrono::milliseconds(16));
BLT_WARN("Running non queue variant with a queue inside!");
break;
//BLT_WARN("Running non queue variant with a queue inside!");
continue;
}
func_loaded = true;
}
auto& func = std::get<thread_function>(func_queue);
func();