mirror of
https://git.intern.spaceteamaachen.de/ALPAKA/TACOS.git
synced 2025-09-28 18:57:33 +00:00
Changed registerThread to accept shared_ptrs to fix some issues with polymorphism.
This commit is contained in:
@@ -15,8 +15,9 @@
|
||||
# error "Manger task priority not specified in config.hpp"
|
||||
#else
|
||||
|
||||
#include <list>
|
||||
#include <set>
|
||||
#include <list>
|
||||
#include <memory>
|
||||
#include <sta/tacos/thread.hpp>
|
||||
|
||||
namespace sta
|
||||
@@ -39,7 +40,10 @@ namespace sta
|
||||
return _instance;
|
||||
}
|
||||
|
||||
void registerThread(TacosThread thread, std::list<uint16_t> states);
|
||||
/**
|
||||
*
|
||||
*/
|
||||
void registerThread(std::shared_ptr<TacosThread> thread, std::list<uint16_t> states);
|
||||
|
||||
void init() override;
|
||||
|
||||
@@ -73,7 +77,7 @@ namespace sta
|
||||
|
||||
void stopThreads(uint16_t state);
|
||||
|
||||
std::set<TacosThread> threads_[STA_TACOS_NUM_STATES];
|
||||
std::set<std::shared_ptr<TacosThread>> threads_[STA_TACOS_NUM_STATES];
|
||||
};
|
||||
} // namespace tacos
|
||||
} // namespace sta
|
||||
|
@@ -61,12 +61,12 @@ namespace sta
|
||||
/**
|
||||
* @brief This function is executed first when this thread is started.
|
||||
*/
|
||||
virtual void init();
|
||||
virtual void init() = 0;
|
||||
|
||||
/**
|
||||
* @brief The body of the thread's loop. Has to be implemented by the user.
|
||||
*/
|
||||
virtual void func();
|
||||
virtual void func() = 0;
|
||||
|
||||
private:
|
||||
|
||||
|
@@ -14,7 +14,7 @@ namespace sta
|
||||
{
|
||||
namespace tacos
|
||||
{
|
||||
void Manager::registerThread(TacosThread thread, std::list<uint16_t> states)
|
||||
void Manager::registerThread(std::shared_ptr<TacosThread> thread, std::list<uint16_t> states)
|
||||
{
|
||||
for (uint16_t state : states)
|
||||
{
|
||||
@@ -28,11 +28,11 @@ namespace sta
|
||||
{
|
||||
STA_ASSERT(state < STA_TACOS_NUM_STATES);
|
||||
|
||||
for (TacosThread thread : threads_[state])
|
||||
for (std::shared_ptr<TacosThread> thread : threads_[state])
|
||||
{
|
||||
if (!thread.isRunning())
|
||||
if (!thread->isRunning())
|
||||
{
|
||||
thread.start();
|
||||
thread->start();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -48,13 +48,13 @@ namespace sta
|
||||
continue;
|
||||
}
|
||||
|
||||
for (TacosThread thread : threads_[state])
|
||||
for (std::shared_ptr<TacosThread> thread : threads_[state])
|
||||
{
|
||||
// If the thread is currently running but not part of the set of threads that should be running...
|
||||
if (thread.isRunning() && threads_[currentState].count(thread) == 0)
|
||||
if (thread->isRunning() && threads_[currentState].count(thread) == 0)
|
||||
{
|
||||
// ...politely request termination.
|
||||
thread.requestTermination();
|
||||
thread->requestTermination();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -70,20 +70,11 @@ namespace sta
|
||||
|
||||
void Manager::init()
|
||||
{
|
||||
STA_DEBUG_PRINTLN("INITIALIZING MANAGER!");
|
||||
|
||||
startThreads(Statemachine::instance()->getCurrentState());
|
||||
}
|
||||
|
||||
void Manager::func()
|
||||
{
|
||||
if (true)
|
||||
{
|
||||
// STA_DEBUG_PRINTLN("LOOPY LOOP IN MANAGER TASK");
|
||||
osDelay(1000);
|
||||
}
|
||||
|
||||
|
||||
// Wait for either the termination request or the state change flag.
|
||||
uint32_t flags = osEventFlagsWait(getInstance(), STA_RTOS_THREAD_FLAG_TERMINATE, osFlagsWaitAny, osWaitForever);
|
||||
|
||||
|
@@ -35,10 +35,7 @@ namespace sta
|
||||
|
||||
void Statemachine::func()
|
||||
{
|
||||
STA_DEBUG_PRINTLN("LOOPY LOOP IN STATEMACHINE.");
|
||||
STA_DEBUG_PRINTLN(lockoutTimer_.isRunning() ? "LOCKOUT RUNNING!" : "LOCKOUT STOPPED!");
|
||||
|
||||
osDelay(500);
|
||||
}
|
||||
|
||||
uint16_t Statemachine::getCurrentState() const
|
||||
|
@@ -8,6 +8,7 @@
|
||||
|
||||
#include <sta/tacos/thread.hpp>
|
||||
#include <sta/debug/assert.hpp>
|
||||
#include <sta/debug/debug.hpp>
|
||||
|
||||
#include <functional>
|
||||
#include <cstring>
|
||||
@@ -87,10 +88,6 @@ namespace sta
|
||||
return std::strcmp(this->getName(), other.getName()) < 0;
|
||||
}
|
||||
|
||||
void TacosThread::init(){}
|
||||
|
||||
void TacosThread::func(){}
|
||||
|
||||
TacosThread::~TacosThread(){}
|
||||
|
||||
} // namespace tacos
|
||||
|
Reference in New Issue
Block a user