/* * case10.cpp * * Created on: Feb 7, 2024 * Author: Dario */ /** * A sleeping thread is not restarted by the watchdog. Additionally, using blocking() also prevents a restart. */ #include #ifdef TASTY_CASE_10 #include #include #include #include namespace sta { namespace tasty { RtosSignal * signal; class ThreadA : public tacos::TacosThread { public: ThreadA() : tacos::TacosThread{"A", osPriorityNormal} { } void pointless_expensive_computation() { uint32_t ticks = osKernelGetSysTimerCount(); uint32_t freq = osKernelGetSysTimerCount(); uint64_t dummyCounter = 0; while (osKernelGetSysTimerCount() <= ticks + 2 * freq) { dummyCounter++; } } void func() override { this->sleep(3000); signal->notify(); // This should notify the watchdog that this thread should be monitored. blocking( pointless_expensive_computation(); ) signal->notify(); pointless_expensive_computation(); } }; std::shared_ptr thread_A; class Observer : public tacos::TacosThread { public: Observer() : tacos::TacosThread{"Observer", osPriorityNormal} { } void func() override { uint16_t restarts = tacos::Watchdog::instance()->getNumRestarts(); // Wait for thread A to finish sleeping. blocking( signal->wait(); ) // Thread A shouldn't have been restarted because sleep() sets the thread's status to WAITING. STA_TASTY_ASSERT(tacos::Watchdog::instance()->getNumRestarts() == restarts); blocking( signal->wait(); ) // Thread A shouldn't have been restarted because the computationally expensive computation was wrapped in blocking() STA_TASTY_ASSERT(tacos::Watchdog::instance()->getNumRestarts() == restarts); this->sleep(2500); STA_TASTY_ASSERT(tacos::Watchdog::instance()->getNumRestarts() == restarts + 1); STA_TASTY_TERMINATE(); } }; void onTastyInit() { signal = new RtosSignal(2); thread_A = tacos::addThread({0}); tacos::addThread({0, 1}); } } // namespace tasty } #endif // TASTY_CASE_10