diff --git a/osal/linux/PeriodicPosixTask.cpp b/osal/linux/PeriodicPosixTask.cpp index bbf33b01..3c1df6bb 100644 --- a/osal/linux/PeriodicPosixTask.cpp +++ b/osal/linux/PeriodicPosixTask.cpp @@ -1,8 +1,7 @@ #include "../../tasks/ExecutableObjectIF.h" #include "../../serviceinterface/ServiceInterfaceStream.h" -#include "../../osal/linux/PeriodicPosixTask.h" - #include +#include "PeriodicPosixTask.h" PeriodicPosixTask::PeriodicPosixTask(const char* name_, int priority_, size_t stackSize_, uint32_t period_, void(deadlineMissedFunc_)()): @@ -26,14 +25,14 @@ ReturnValue_t PeriodicPosixTask::addComponent(object_id_t object) { ExecutableObjectIF* newObject = objectManager->get( object); if (newObject == nullptr) { - sif::error << "PeriodicTask::addComponent: Invalid object. Make sure" - "it implements ExecutableObjectIF" << std::endl; + sif::error << "PeriodicTask::addComponent: Invalid object. Make sure" + << " 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(); diff --git a/osal/linux/PeriodicPosixTask.h b/osal/linux/PeriodicPosixTask.h index 38825bbf..ffee236b 100644 --- a/osal/linux/PeriodicPosixTask.h +++ b/osal/linux/PeriodicPosixTask.h @@ -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 @@ -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.