From 4eadff48fe5ac281b1df4c12d6ac6565a6ac128f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcin=20Smoczy=C5=84ski?= Date: Sat, 27 Feb 2021 00:03:57 +0100 Subject: [PATCH] [EGD-5911] Allow configuring worker stack size MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Allow configuring stack size of a worker by a child class for a better system heap utilization control. Signed-off-by: Marcin SmoczyƄski --- module-sys/Service/Worker.cpp | 12 +++++++----- module-sys/Service/Worker.hpp | 9 +++++---- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/module-sys/Service/Worker.cpp b/module-sys/Service/Worker.cpp index 7c9386460ff8bc975b5238bfeb1447e92bb0ff2b..f3cf4f5da3ed0d8d41d5bdb5b8e3a79a9cc245bc 100644 --- a/module-sys/Service/Worker.cpp +++ b/module-sys/Service/Worker.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved. +// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved. // For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md #include "Worker.hpp" @@ -76,13 +76,14 @@ namespace sys vTaskDelete(nullptr); } - Worker::Worker(sys::Service *service) : name(service->GetName()), priority(service->GetPriority()) + Worker::Worker(sys::Service *service, std::uint16_t stackDepth) + : name(service->GetName()), priority(service->GetPriority()), stackDepth(stackDepth) { constructName(); } - Worker::Worker(std::string workerNamePrefix, UBaseType_t priority) - : name(std::move(workerNamePrefix)), priority(priority) + Worker::Worker(std::string workerNamePrefix, UBaseType_t priority, std::uint16_t stackDepth) + : name(std::move(workerNamePrefix)), priority(priority), stackDepth(stackDepth) { constructName(); } @@ -211,7 +212,8 @@ namespace sys runnerTask = xTaskGetCurrentTaskHandle(); BaseType_t task_error = 0; - task_error = xTaskCreate(Worker::taskAdapter, name.c_str(), defaultStackSize, this, priority, &taskHandle); + task_error = xTaskCreate( + Worker::taskAdapter, name.c_str(), stackDepth / sizeof(StackType_t), this, priority, &taskHandle); if (task_error != pdPASS) { LOG_ERROR("Failed to start the task"); diff --git a/module-sys/Service/Worker.hpp b/module-sys/Service/Worker.hpp index a28c47e465903df9dd86b9d0f29531e1f7577997..c6321700644236a367dd0acf68ea37d6874c910a 100644 --- a/module-sys/Service/Worker.hpp +++ b/module-sys/Service/Worker.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved. +// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved. // For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md #pragma once @@ -100,7 +100,7 @@ namespace sys WorkerQueue &getControlQueue() const; static constexpr std::size_t controlMessagesCount = static_cast(ControlMessage::MessageCount); - static constexpr std::size_t defaultStackSize = 2048; + static constexpr std::size_t defaultStackSize = 8192; static constexpr TickType_t defaultJoinTimeout = portMAX_DELAY; static constexpr auto controlQueueNamePrefix = "wctrl"; @@ -132,13 +132,14 @@ namespace sys static unsigned int count; const UBaseType_t priority; + std::uint16_t stackDepth = defaultStackSize; QueueSetHandle_t queueSet = nullptr; std::vector> queues; public: - Worker(sys::Service *service); - Worker(std::string workerNamePrefix, const UBaseType_t priority); + Worker(sys::Service *service, std::uint16_t stackDepth = defaultStackSize); + Worker(std::string workerNamePrefix, const UBaseType_t priority, std::uint16_t stackDepth = defaultStackSize); virtual ~Worker();