diff --git a/example/ExampleTasks.hpp b/example/ExampleTasks.hpp index af2053d..c2afe73 100644 --- a/example/ExampleTasks.hpp +++ b/example/ExampleTasks.hpp @@ -5,7 +5,7 @@ #include #include #include "TaskListener.hpp" -#include "executor/ThreadPool.hpp" +#include "executor/ThreadPoolExecutor.hpp" std::mutex m; diff --git a/example/main.cpp b/example/main.cpp index 672f880..98f1f60 100644 --- a/example/main.cpp +++ b/example/main.cpp @@ -50,17 +50,23 @@ struct DeviceEventListener : TaskListenerBase int main() { DefaultSchedulerPolicy policy; - std::shared_ptr wg = std::make_shared(policy); - TaskChannel ch(wg); - DeviceFwUploadTaskListener listener(ch); + auto executor = std::make_shared(policy); + TaskChannel ch(executor); + DeviceFwUploadTaskListener deviceListener(ch); DeviceEventListener evListener(ch); + std::vector listOfToken; - listener.get_channel().push(std::make_shared("my_server_url:/upload/image/", "firmware.bin")); - listener.get_channel().push(std::make_shared("my_server_url:/download/image/", "firmware.bin")); - evListener.get_channel().push(std::make_shared()); - evListener.get_channel().push(std::make_shared()); - evListener.get_channel().push(std::make_shared()); - evListener.get_channel().push(std::make_shared()); + listOfToken.push_back(deviceListener.get_channel().push(std::make_shared("my_server_url:/upload/image/", "firmware.bin"))); + listOfToken.push_back(deviceListener.get_channel().push(std::make_shared("my_server_url:/download/image/", "firmware.bin"))); + listOfToken.push_back(evListener.get_channel().push(std::make_shared())); + listOfToken.push_back(evListener.get_channel().push(std::make_shared())); + listOfToken.push_back(evListener.get_channel().push(std::make_shared())); + listOfToken.push_back(evListener.get_channel().push(std::make_shared())); + + for (size_t i = 0; i < listOfToken.size(); i++) + { + while (!listOfToken[i]->is_set()) { } + } return 0; } \ No newline at end of file diff --git a/include/TaskDispatcher.hpp b/include/TaskDispatcher.hpp index 51a93fa..c0ea066 100644 --- a/include/TaskDispatcher.hpp +++ b/include/TaskDispatcher.hpp @@ -2,7 +2,7 @@ #include #include -#include "executor/ThreadPool.hpp" +#include "executor/ThreadPoolExecutor.hpp" #include "detail/TaskMapping.hpp" struct TaskDispatcher diff --git a/include/executor/ThreadPool.hpp b/include/executor/ThreadPoolExecutor.hpp similarity index 91% rename from include/executor/ThreadPool.hpp rename to include/executor/ThreadPoolExecutor.hpp index 2efc3d7..b71b339 100644 --- a/include/executor/ThreadPool.hpp +++ b/include/executor/ThreadPoolExecutor.hpp @@ -86,9 +86,9 @@ struct Worker } // namespace detail -struct ThreadPool final : public executor::detail::ExecutorInterface +struct ThreadPoolExecutor final : public executor::detail::ExecutorInterface { - ThreadPool(SchedulePolicy& policy, std::size_t worker_size = 4) : number_of_workers(worker_size), _policy(policy) + ThreadPoolExecutor(SchedulePolicy& policy, std::size_t worker_size = 4) : number_of_workers(worker_size), _policy(policy) { for (size_t i = 0; i < number_of_workers; i++) { @@ -103,7 +103,7 @@ struct ThreadPool final : public executor::detail::ExecutorInterface } _policy.set_worker_id_list(wids); } - virtual ~ThreadPool() override + virtual ~ThreadPoolExecutor() override { } diff --git a/tests/task_tests.cpp b/tests/task_tests.cpp index 0e2e757..ca70445 100644 --- a/tests/task_tests.cpp +++ b/tests/task_tests.cpp @@ -46,7 +46,7 @@ struct DummyTaskListener : TaskListenerBase TEST(TaskTestFixture, canDispatchTasks) { DefaultSchedulerPolicy policy; - std::shared_ptr wg = std::make_shared(policy); + std::shared_ptr wg = std::make_shared(policy); TaskChannel ch(wg); DummyTaskListener listener(ch);