WIP: somethings wrong.. #19
@ -8,7 +8,8 @@
|
|||||||
|
|
||||||
class FixedTimeslotTask: public FixedTimeslotTaskIF, public PosixThread {
|
class FixedTimeslotTask: public FixedTimeslotTaskIF, public PosixThread {
|
||||||
public:
|
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 ~FixedTimeslotTask();
|
||||||
|
|
||||||
virtual ReturnValue_t startTask();
|
virtual ReturnValue_t startTask();
|
||||||
@ -17,7 +18,9 @@ public:
|
|||||||
|
|
||||||
virtual uint32_t getPeriodMs() const;
|
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;
|
virtual ReturnValue_t checkSequence() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -34,11 +37,10 @@ public:
|
|||||||
protected:
|
protected:
|
||||||
/**
|
/**
|
||||||
* @brief This function holds the main functionality of the thread.
|
* @brief This function holds the main functionality of the thread.
|
||||||
*
|
* @details
|
||||||
*
|
* Holding the main functionality of the task, this method is most important.
|
||||||
* @details Holding the main functionality of the task, this method is most important.
|
* It links the functionalities provided by FixedSlotSequence with the
|
||||||
* It links the functionalities provided by FixedSlotSequence with the OS's System Calls
|
* OS's System Calls to keep the timing of the periods.
|
||||||
* to keep the timing of the periods.
|
|
||||||
*/
|
*/
|
||||||
virtual void taskFunctionality();
|
virtual void taskFunctionality();
|
||||||
|
|
||||||
@ -46,8 +48,10 @@ private:
|
|||||||
/**
|
/**
|
||||||
* @brief This is the entry point in a new thread.
|
* @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.
|
* @details
|
||||||
* Needs a valid pointer to the derived class.
|
* 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);
|
static void* taskEntryPoint(void* arg);
|
||||||
FixedSlotSequence pst;
|
FixedSlotSequence pst;
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
#include <framework/serviceinterface/ServiceInterfaceStream.h>
|
#include <framework/serviceinterface/ServiceInterfaceStream.h>
|
||||||
|
#include <framework/osal/linux/PosixThread.h>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <framework/osal/linux/PosixThread.h>
|
|
||||||
|
|
||||||
PosixThread::PosixThread(const char* name_, int priority_, size_t stackSize_):
|
PosixThread::PosixThread(const char* name_, int priority_, size_t stackSize_):
|
||||||
thread(0),priority(priority_),stackSize(stackSize_) {
|
thread(0),priority(priority_),stackSize(stackSize_) {
|
||||||
strcpy(name,name_);
|
strncpy(name,name_,16);
|
||||||
}
|
}
|
||||||
|
|
||||||
PosixThread::~PosixThread() {
|
PosixThread::~PosixThread() {
|
||||||
@ -128,9 +128,6 @@ void PosixThread::createTask(void* (*fnc_)(void*), void* arg_) {
|
|||||||
default attributes.
|
default attributes.
|
||||||
*/
|
*/
|
||||||
pthread_attr_t 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);
|
int status = pthread_attr_init(&attributes);
|
||||||
if(status != 0){
|
if(status != 0){
|
||||||
sif::error << "Posix Thread attribute init failed with: " <<
|
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: " <<
|
sif::error << "PosixThread::createTask: Stack init failed with: " <<
|
||||||
strerror(status) << std::endl;
|
strerror(status) << std::endl;
|
||||||
if(errno == ENOMEM) {
|
if(errno == ENOMEM) {
|
||||||
double stackMb = (double)((double)stackSize/(double)10e6);
|
uint64_t stackMb = stackSize/10e6;
|
||||||
sif::error << "PosixThread::createTask: Insufficient memory for"
|
sif::error << "PosixThread::createTask: Insufficient memory for"
|
||||||
" the requested " << stackMb << " MB" << std::endl;
|
" the requested " << stackMb << " MB" << std::endl;
|
||||||
}
|
}
|
||||||
@ -199,8 +196,19 @@ void PosixThread::createTask(void* (*fnc_)(void*), void* arg_) {
|
|||||||
|
|
||||||
status = pthread_setname_np(thread,name);
|
status = pthread_setname_np(thread,name);
|
||||||
if(status != 0){
|
if(status != 0){
|
||||||
sif::error << "Posix Thread setname failed with: " <<
|
sif::error << "PosixThread::createTask: setname failed with: " <<
|
||||||
strerror(status) << std::endl;
|
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);
|
status = pthread_attr_destroy(&attributes);
|
||||||
|
@ -69,7 +69,7 @@ protected:
|
|||||||
void createTask(void* (*fnc_)(void*),void* arg_);
|
void createTask(void* (*fnc_)(void*),void* arg_);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
char name[10];
|
char name[16];
|
||||||
int priority;
|
int priority;
|
||||||
size_t stackSize = 0;
|
size_t stackSize = 0;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user