fixed bug (critical!)

This commit is contained in:
Robin Müller 2020-06-06 15:26:22 +02:00
parent ef01b78140
commit b0634ab0a2
3 changed files with 29 additions and 17 deletions

View File

@ -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;

View File

@ -1,11 +1,11 @@
#include <framework/serviceinterface/ServiceInterfaceStream.h>
#include <framework/osal/linux/PosixThread.h>
#include <cstring>
#include <errno.h>
#include <framework/osal/linux/PosixThread.h>
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<PeriodicPosixTask*>(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);

View File

@ -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;
};