mirror of
https://git.intern.spaceteamaachen.de/ALPAKA/Tasty.git
synced 2025-06-13 03:35:59 +00:00
119 lines
2.3 KiB
C++
119 lines
2.3 KiB
C++
/*
|
|
* 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 <sta/tasty/config.hpp>
|
|
#ifdef TASTY_CASE_10
|
|
|
|
#include <sta/tacos.hpp>
|
|
#include <sta/tasty/utils.hpp>
|
|
#include <sta/tacos/watchdog.hpp>
|
|
#include <sta/rtos/signal.hpp>
|
|
|
|
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<ThreadA> 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<ThreadA>({0});
|
|
tacos::addThread<Observer>({0, 1});
|
|
}
|
|
} // namespace tasty
|
|
}
|
|
|
|
#endif // TASTY_CASE_10
|
|
|
|
|
|
|
|
|