minior thread pool change
parent
9bba525b1f
commit
6a5b7a6865
|
@ -1,7 +1,7 @@
|
||||||
cmake_minimum_required(VERSION 3.5)
|
cmake_minimum_required(VERSION 3.5)
|
||||||
include(cmake/color.cmake)
|
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_TEST_VERSION 0.0.1)
|
||||||
|
|
||||||
set(BLT_TARGET BLT)
|
set(BLT_TARGET BLT)
|
||||||
|
|
|
@ -47,6 +47,7 @@ namespace blt
|
||||||
std::vector<std::thread*> threads;
|
std::vector<std::thread*> threads;
|
||||||
std::variant<std::queue<thread_function>, thread_function> func_queue;
|
std::variant<std::queue<thread_function>, thread_function> func_queue;
|
||||||
std::mutex queue_mutex;
|
std::mutex queue_mutex;
|
||||||
|
bool func_loaded = false;
|
||||||
public:
|
public:
|
||||||
explicit thread_pool(std::uint64_t number_of_threads = 8, std::optional<thread_function> default_function = {})
|
explicit thread_pool(std::uint64_t number_of_threads = 8, std::optional<thread_function> default_function = {})
|
||||||
{
|
{
|
||||||
|
@ -76,14 +77,15 @@ namespace blt
|
||||||
func();
|
func();
|
||||||
} else
|
} else
|
||||||
{
|
{
|
||||||
{
|
if (!func_loaded){
|
||||||
std::scoped_lock lock(queue_mutex);
|
std::scoped_lock lock(queue_mutex);
|
||||||
if (std::holds_alternative<std::queue<thread_function>>(func_queue))
|
if (std::holds_alternative<std::queue<thread_function>>(func_queue))
|
||||||
{
|
{
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(16));
|
std::this_thread::sleep_for(std::chrono::milliseconds(16));
|
||||||
BLT_WARN("Running non queue variant with a queue inside!");
|
//BLT_WARN("Running non queue variant with a queue inside!");
|
||||||
break;
|
continue;
|
||||||
}
|
}
|
||||||
|
func_loaded = true;
|
||||||
}
|
}
|
||||||
auto& func = std::get<thread_function>(func_queue);
|
auto& func = std::get<thread_function>(func_queue);
|
||||||
func();
|
func();
|
||||||
|
|
Loading…
Reference in New Issue