diff --git a/osal/linux/FixedTimeslotTask.h b/osal/linux/FixedTimeslotTask.h index 6350f347..6d523ba9 100644 --- a/osal/linux/FixedTimeslotTask.h +++ b/osal/linux/FixedTimeslotTask.h @@ -8,7 +8,8 @@ class FixedTimeslotTask: public FixedTimeslotTaskIF, public PosixThread { public: - FixedTimeslotTask(const char* name_, int priority_, size_t stackSize_, uint32_t periodMs_); + FixedTimeslotTask(const char* name_, int priority_, size_t stackSize_, + uint32_t periodMs_); virtual ~FixedTimeslotTask(); virtual ReturnValue_t startTask(); @@ -17,7 +18,9 @@ public: virtual uint32_t getPeriodMs() const; - virtual ReturnValue_t addSlot(object_id_t componentId, uint32_t slotTimeMs, int8_t executionStep); + virtual ReturnValue_t addSlot(object_id_t componentId, uint32_t slotTimeMs, + int8_t executionStep); + virtual ReturnValue_t checkSequence() const; /** @@ -34,11 +37,10 @@ public: protected: /** * @brief This function holds the main functionality of the thread. - * - * - * @details Holding the main functionality of the task, this method is most important. - * It links the functionalities provided by FixedSlotSequence with the OS's System Calls - * to keep the timing of the periods. + * @details + * Holding the main functionality of the task, this method is most important. + * It links the functionalities provided by FixedSlotSequence with the + * OS's System Calls to keep the timing of the periods. */ virtual void taskFunctionality(); @@ -46,8 +48,10 @@ private: /** * @brief This is the entry point in a new thread. * - * @details This method, that is the entry point in the new thread and calls taskFunctionality of the child class. - * Needs a valid pointer to the derived class. + * @details + * This method, that is the entry point in the new thread and calls + * taskFunctionality of the child class. Needs a valid pointer to the + * derived class. */ static void* taskEntryPoint(void* arg); FixedSlotSequence pst; diff --git a/osal/linux/PosixThread.cpp b/osal/linux/PosixThread.cpp index 5f91858f..24545f6f 100644 --- a/osal/linux/PosixThread.cpp +++ b/osal/linux/PosixThread.cpp @@ -1,11 +1,11 @@ #include +#include #include #include -#include PosixThread::PosixThread(const char* name_, int priority_, size_t stackSize_): thread(0),priority(priority_),stackSize(stackSize_) { - strcpy(name,name_); + strncpy(name,name_,16); } PosixThread::~PosixThread() { @@ -128,9 +128,6 @@ void PosixThread::createTask(void* (*fnc_)(void*), void* arg_) { default attributes. */ pthread_attr_t attributes; - //PeriodicPosixTask* task = reinterpret_cast(arg_); - //sif::info << task->stackSize << std::endl; - sif::info << stackSize << std::endl; int status = pthread_attr_init(&attributes); if(status != 0){ sif::error << "Posix Thread attribute init failed with: " << @@ -142,7 +139,7 @@ void PosixThread::createTask(void* (*fnc_)(void*), void* arg_) { sif::error << "PosixThread::createTask: Stack init failed with: " << strerror(status) << std::endl; if(errno == ENOMEM) { - double stackMb = (double)((double)stackSize/(double)10e6); + uint64_t stackMb = stackSize/10e6; sif::error << "PosixThread::createTask: Insufficient memory for" " the requested " << stackMb << " MB" << std::endl; } @@ -199,8 +196,19 @@ void PosixThread::createTask(void* (*fnc_)(void*), void* arg_) { status = pthread_setname_np(thread,name); if(status != 0){ - sif::error << "Posix Thread setname failed with: " << + sif::error << "PosixThread::createTask: setname failed with: " << strerror(status) << std::endl; + if(status == ERANGE) { + sif::error << "PosixThread::createTask: Task name length longer" + " than 16 chars. Truncating.." << std::endl; + name[15] = '\0'; + status = pthread_setname_np(thread,name); + if(status != 0){ + sif::error << "PosixThread::createTask: Setting name" + " did not work.." << std::endl; + } + } + } status = pthread_attr_destroy(&attributes); diff --git a/osal/linux/PosixThread.h b/osal/linux/PosixThread.h index ad403ac4..488e1986 100644 --- a/osal/linux/PosixThread.h +++ b/osal/linux/PosixThread.h @@ -69,7 +69,7 @@ protected: void createTask(void* (*fnc_)(void*),void* arg_); private: - char name[10]; + char name[16]; int priority; size_t stackSize = 0; };