diff --git a/include/sta/tacos.hpp b/include/sta/tacos.hpp index 3ca9f85..b92f699 100644 --- a/include/sta/tacos.hpp +++ b/include/sta/tacos.hpp @@ -68,9 +68,13 @@ namespace sta * @ingroup tacos_api */ template - void addThread(std::list states, Args ... args) + std::shared_ptr addThread(std::list states, Args ... args) { - Manager::instance()->registerThread(std::make_shared(args...), states); + std::shared_ptr thread_ptr = std::make_shared(args...); + + Manager::instance()->registerThread(thread_ptr, states); + + return thread_ptr; } } // namespace tacos } diff --git a/include/sta/tacos/thread.hpp b/include/sta/tacos/thread.hpp index ca01469..4cebf27 100644 --- a/include/sta/tacos/thread.hpp +++ b/include/sta/tacos/thread.hpp @@ -32,10 +32,13 @@ namespace sta public: /** * @brief Create a new thread with the given name and priority. + * + * @param name The thread's name. This is used for debugging. + * @param prio The thread's priority. Generally, this should be lower than the manager and statemachine priority. + * @param stack_size The stack size for the task. The default is 0, i.e. the stack size specified in the FreeRTOS settings. + * @param cb_size The control block size for the task. The default is 0, i.e. the size specified in the FreeRTOS settings. */ - TacosThread(const char* name, osPriority_t prio); - - TacosThread(); + TacosThread(const char* name, osPriority_t prio, uint32_t stack_size = 0, uint32_t cb_size = 0); virtual ~TacosThread(); diff --git a/src/thread.cpp b/src/thread.cpp index 49c6b14..a392422 100644 --- a/src/thread.cpp +++ b/src/thread.cpp @@ -19,19 +19,15 @@ namespace sta { namespace tacos { - TacosThread::TacosThread(const char* name, osPriority_t prio) + TacosThread::TacosThread(const char* name, osPriority_t prio, uint32_t stack_size /* = 0 */, uint32_t cb_size /* = 0 */) : RtosThread(RtosHandle(Handle::Deferred(&instance_))), instance_{ NULL }, - attribs_{ .name = name, .priority = prio }, + attribs_{ .name=name, .cb_size=cb_size, .stack_size=stack_size, .priority=prio }, running_{false} - {} - - TacosThread::TacosThread() - : RtosThread(RtosHandle(Handle::Deferred(&instance_))), - instance_{ NULL }, - attribs_{ }, - running_{false} - {} + { + STA_ASSERT(stack_size >= 0); + STA_ASSERT(cb_size >= 0); + } void TacosThread::entry_point(void* arg) {