changed taken over

This commit is contained in:
Robin Müller 2020-09-04 14:49:27 +02:00
parent 9d1f292af0
commit 94b45d7407
2 changed files with 21 additions and 18 deletions

View File

@ -1,8 +1,7 @@
#include "../../tasks/ExecutableObjectIF.h"
#include "../../serviceinterface/ServiceInterfaceStream.h"
#include "../../osal/linux/PeriodicPosixTask.h"
#include <errno.h>
#include "PeriodicPosixTask.h"
PeriodicPosixTask::PeriodicPosixTask(const char* name_, int priority_,
size_t stackSize_, uint32_t period_, void(deadlineMissedFunc_)()):
@ -27,13 +26,13 @@ ReturnValue_t PeriodicPosixTask::addComponent(object_id_t object) {
object);
if (newObject == nullptr) {
sif::error << "PeriodicTask::addComponent: Invalid object. Make sure"
"it implements ExecutableObjectIF" << std::endl;
<< " it implements ExecutableObjectIF!" << std::endl;
return HasReturnvaluesIF::RETURN_FAILED;
}
objectList.push_back(newObject);
newObject->setTaskIF(this);
return newObject->initializeAfterTaskCreation();
return HasReturnvaluesIF::RETURN_OK;
}
ReturnValue_t PeriodicPosixTask::sleepFor(uint32_t ms) {
@ -49,27 +48,31 @@ ReturnValue_t PeriodicPosixTask::startTask(void) {
}
void PeriodicPosixTask::taskFunctionality(void) {
if(!started){
if(not started) {
suspend();
}
for (auto const &object: objectList) {
object->initializeAfterTaskCreation();
}
uint64_t lastWakeTime = getCurrentMonotonicTimeMs();
//The task's "infinite" inner loop is entered.
while (1) {
for (ObjectList::iterator it = objectList.begin();
it != objectList.end(); ++it) {
(*it)->performOperation();
for (auto const &object: objectList) {
object->performOperation();
}
if(!PosixThread::delayUntil(&lastWakeTime,periodMs)){
if(not PosixThread::delayUntil(&lastWakeTime, periodMs)){
char name[20] = {0};
int status = pthread_getname_np(pthread_self(),name,sizeof(name));
if(status == 0){
//sif::error << "PeriodicPosixTask " << name << ": Deadline "
// "missed." << std::endl;
int status = pthread_getname_np(pthread_self(), name, sizeof(name));
if(status == 0) {
sif::error << "PeriodicPosixTask " << name << ": Deadline "
"missed." << std::endl;
}
else {
//sif::error << "PeriodicPosixTask X: Deadline missed. " <<
// status << std::endl;
sif::error << "PeriodicPosixTask X: Deadline missed. " <<
status << std::endl;
}
if (this->deadlineMissedFunc != nullptr) {
this->deadlineMissedFunc();

View File

@ -3,7 +3,7 @@
#include "../../tasks/PeriodicTaskIF.h"
#include "../../objectmanager/ObjectManagerIF.h"
#include "../../osal/linux/PosixThread.h"
#include "PosixThread.h"
#include "../../tasks/ExecutableObjectIF.h"
#include <vector>
@ -32,7 +32,7 @@ public:
* The address of the task object is passed as an argument
* to the system call.
*/
ReturnValue_t startTask(void) override;
ReturnValue_t startTask() override;
/**
* Adds an object to the list of objects to be executed.
* The objects are executed in the order added.