19#ifndef HF_UTILS_RTOS_WRAP_BASETHREADSMANAGER_H_
20#define HF_UTILS_RTOS_WRAP_BASETHREADSMANAGER_H_
41 BaseThreadsManager(
const std::map<EnumType, BaseThread*>& threads, std::function<
const char*(EnumType)> enumToStringFunc) ;
64 bool ResumeSelected(const std::vector<EnumType>& selectedEnums) noexcept;
68 bool StartSelected(const std::vector<EnumType>& selectedEnums) noexcept;
80 bool StopSelected(const std::vector<EnumType>& selectedEnums) noexcept;
122template <typename EnumType, EnumType MaxCount>
135template <
typename EnumType, EnumType MaxCount>
146template <
typename EnumType, EnumType MaxCount>
156template <
typename EnumType, EnumType MaxCount>
165 threadMap.second->Resume();
173template <
typename EnumType, EnumType MaxCount>
176 bool resumed =
false;
182 for(
const auto& enumValue : selectedEnums)
187 resumed = threadMap->second->Resume();
195template <
typename EnumType, EnumType MaxCount>
215template <
typename EnumType, EnumType MaxCount>
223 bool allSelectedStarted =
true;
224 for(
const auto& enumValue : selectedEnums) {
227 bool started = threadMap->second->Start();
228 allSelectedStarted = allSelectedStarted && started;
234 return allSelectedStarted;
240template <
typename EnumType, EnumType MaxCount>
248 bool allExceptSelectedStarted =
true;
252 if(std::find(selectedEnums.begin(), selectedEnums.end(), threadMap.first) == selectedEnums.end()) {
254 bool started = threadMap.second->Start();
255 allExceptSelectedStarted = allExceptSelectedStarted && started;
262 return allExceptSelectedStarted;
268template <
typename EnumType, EnumType MaxCount>
277 threadMap.second->Start();
282 std::function<bool()> CheckIfAllHalSubThreadsAreStarted = [
this]() {
312template <
typename EnumType, EnumType MaxCount>
321 for(
const auto& enumValue : selectedEnums) {
324 threadMap->second->Start();
331 std::function<bool()> CheckIfAllSelectedThreadsAreStarted = [
this, selectedEnums] {
333 for(
const auto& enumValue : selectedEnums) {
337 for(
const auto& enumValue : selectedEnums) {
359 for(
const auto& enumValue : selectedEnums) {
368template <
typename EnumType, EnumType MaxCount>
380 if(std::find(selectedEnums.begin(), selectedEnums.end(), threadMap.first) == selectedEnums.end()) {
382 threadMap.second->Start();
388 std::function<bool()> CheckIfAllExceptSelectedThreadsAreStarted = [
this, selectedEnums] {
391 if(std::find(selectedEnums.begin(), selectedEnums.end(), threadMap.first) == selectedEnums.end()) {
397 if(std::find(selectedEnums.begin(), selectedEnums.end(), threadMap.first) == selectedEnums.end()) {
421 if(std::find(selectedEnums.begin(), selectedEnums.end(), threadMap.first) == selectedEnums.end()) {
431template <
typename EnumType, EnumType MaxCount>
450template <
typename EnumType, EnumType MaxCount>
459 bool allSelectedStopped =
true;
460 for(
const auto& enumValue : selectedEnums) {
463 bool stopped = threadMap->second->Stop();
464 allSelectedStopped = allSelectedStopped && stopped;
470 return allSelectedStopped;
476template <
typename EnumType, EnumType MaxCount>
485 bool allExceptSelectedStopped =
true;
487 if(std::find(selectedEnums.begin(), selectedEnums.end(), threadMap.first) == selectedEnums.end()) {
488 bool stopped = threadMap.second->Stop();
489 allExceptSelectedStopped = allExceptSelectedStopped && stopped;
496 return allExceptSelectedStopped;
501template <
typename EnumType, EnumType MaxCount>
515 std::function<bool()> CheckIfAllHalSubThreadsAreStopped = [
this]() {
531template <
typename EnumType, EnumType MaxCount>
540 for(
const auto& enumValue : selectedEnums) {
549 std::function<bool()> CheckIfAllSelectedThreadsAreStopped = [
this, selectedEnums] {
550 for(
const auto& enumValue : selectedEnums) {
553 for(
const auto& enumValue : selectedEnums) {
571template <
typename EnumType, EnumType MaxCount>
582 if(std::find(selectedEnums.begin(), selectedEnums.end(), threadMap.first) == selectedEnums.end()) {
584 threadMap.second->Stop();
591 std::function<bool()> CheckIfAllExceptSelectedThreadsAreStopped = [
this, selectedEnums] {
594 if(std::find(selectedEnums.begin(), selectedEnums.end(), threadMap.first) == selectedEnums.end()) {
600 if(std::find(selectedEnums.begin(), selectedEnums.end(), threadMap.first) == selectedEnums.end()) {
624 if(std::find(selectedEnums.begin(), selectedEnums.end(), threadMap.first) == selectedEnums.end()) {
634template <
typename EnumType, EnumType MaxCount>
639template <
typename EnumType, EnumType MaxCount>
649template <
typename EnumType, EnumType MaxCount>
652 bool success =
false;
661 bool threadInitialized = threadMap.second->EnsureInitialized();
664 if(threadInitialized) {
681template <
typename EnumType, EnumType MaxCount>
Abstract base class for long running worker threads.
Named-mutex wrapper used by BaseThread infrastructure.
MutexGuard class definition.
Generic RTOS abstraction — public header.
C-facing helper functions for delays, cycle counters, and creation of RTOS handles (queues,...
uint32_t os_get_elapsed_time_msec()
Retrieves the elapsed time in milliseconds.
Definition OsUtility.cpp:65
void os_delay_msec(uint16_t msec)
Delays execution for the specified number of milliseconds.
Definition OsUtility.cpp:28
Miscellaneous utility helpers for the RTOS wrapper.
static bool TestLogicWithTimeout(Func func, T expected, uint32_t timeoutMsec, uint32_t checkIntervalMs)
Helper to repeatedly check a condition until timeout.
Definition Utility.h:26
Abstract class to assist in designing thread-based execution sequences.
Definition BaseThread.h:32
Definition BaseThreadsManager.h:39
bool StartSelected(const std::vector< EnumType > &selectedEnums) noexcept
Definition BaseThreadsManager.h:216
static constexpr bool timeBetweenChecksMsec
Definition BaseThreadsManager.h:106
bool StopAllAndWaitToVerify(uint32_t waitToVerifyTimeoutMsec) noexcept
Definition BaseThreadsManager.h:502
BaseThreadsManager(const BaseThreadsManager &)=delete
The Copy constructor is deleted to avoid copying instances.
bool StartAll() noexcept
Definition BaseThreadsManager.h:196
bool EnsureInitialized() noexcept
Ensures that the BaseThreadsManager is initialized.
Definition BaseThreadsManager.h:147
bool ResumeSelected(const std::vector< EnumType > &selectedEnums) noexcept
Definition BaseThreadsManager.h:174
virtual bool PreThreadInitializationActions() noexcept
Definition BaseThreadsManager.h:635
std::function< const char *(EnumType)> enumToString
Definition BaseThreadsManager.h:114
std::bitset< MaxCount > threadsStartedTracker
Definition BaseThreadsManager.h:117
bool StopSelectedAndWaitToVerify(const std::vector< EnumType > &selectedEnums, uint32_t waitToVerifyTimeoutMsec) noexcept
Definition BaseThreadsManager.h:532
bool StopAll() noexcept
Definition BaseThreadsManager.h:432
bool StartSelectedAndWaitToVerify(const std::vector< EnumType > &selectedEnums, uint32_t waitToVerifyTimeoutMsec) noexcept
Definition BaseThreadsManager.h:313
bool StopAllExceptSelectedAndWaitToVerify(const std::vector< EnumType > &selectedEnums, uint32_t waitToVerifyTimeoutMsec) noexcept
Definition BaseThreadsManager.h:572
bool StartAllExceptSelectedAndWaitToVerify(const std::vector< EnumType > &selectedEnums, uint32_t waitToVerifyTimeoutMsec) noexcept
Definition BaseThreadsManager.h:369
virtual bool PostThreadInitializationActions() noexcept
Definition BaseThreadsManager.h:640
std::bitset< MaxCount > threadsStoppedTracker
Definition BaseThreadsManager.h:118
BaseThreadsManager & operator=(const BaseThreadsManager &)=delete
The assignment operator constructor is deleted to avoid copying instances.
bool StartAllExceptSelected(const std::vector< EnumType > &selectedEnums) noexcept
Definition BaseThreadsManager.h:241
std::bitset< MaxCount > threadsInitializedTracker
Definition BaseThreadsManager.h:116
Mutex mutex
Definition BaseThreadsManager.h:110
bool StopAllExceptSelected(const std::vector< EnumType > &selectedEnums) noexcept
Definition BaseThreadsManager.h:477
bool StopSelected(const std::vector< EnumType > &selectedEnums) noexcept
Definition BaseThreadsManager.h:451
bool initialized
Definition BaseThreadsManager.h:108
bool Initialize() noexcept
Initializes the BaseThreadsManager.
Definition BaseThreadsManager.h:650
static const char mutexName[]
Definition BaseThreadsManager.h:111
bool ResumeAll() noexcept
Definition BaseThreadsManager.h:157
bool StartAllAndWaitToVerify(uint32_t waitToVerifyTimeoutMsec) noexcept
Definition BaseThreadsManager.h:269
static constexpr bool verbose
Definition BaseThreadsManager.h:105
virtual ~BaseThreadsManager()
Definition BaseThreadsManager.h:136
std::map< EnumType, BaseThread * > threadsManaged
Definition BaseThreadsManager.h:113
Definition MutexGuard.h:29