Merge remote-tracking branch 'origin/master' into mohr_serialize
This commit is contained in:
@ -19,8 +19,7 @@ FixedTimeslotTask::~FixedTimeslotTask() {
|
||||
void FixedTimeslotTask::taskEntryPoint(void* argument) {
|
||||
|
||||
//The argument is re-interpreted as FixedTimeslotTask. The Task object is global, so it is found from any place.
|
||||
FixedTimeslotTask *originalTask(
|
||||
reinterpret_cast<FixedTimeslotTask*>(argument));
|
||||
FixedTimeslotTask *originalTask(reinterpret_cast<FixedTimeslotTask*>(argument));
|
||||
// Task should not start until explicitly requested
|
||||
// in FreeRTOS, tasks start as soon as they are created if the scheduler is running
|
||||
// but not if the scheduler is not running.
|
||||
@ -33,14 +32,14 @@ void FixedTimeslotTask::taskEntryPoint(void* argument) {
|
||||
}
|
||||
|
||||
originalTask->taskFunctionality();
|
||||
debug << "Polling task " << originalTask->handle
|
||||
sif::debug << "Polling task " << originalTask->handle
|
||||
<< " returned from taskFunctionality." << std::endl;
|
||||
}
|
||||
|
||||
void FixedTimeslotTask::missedDeadlineCounter() {
|
||||
FixedTimeslotTask::deadlineMissedCount++;
|
||||
if (FixedTimeslotTask::deadlineMissedCount % 10 == 0) {
|
||||
error << "PST missed " << FixedTimeslotTask::deadlineMissedCount
|
||||
sif::error << "PST missed " << FixedTimeslotTask::deadlineMissedCount
|
||||
<< " deadlines." << std::endl;
|
||||
}
|
||||
}
|
||||
@ -58,8 +57,19 @@ ReturnValue_t FixedTimeslotTask::startTask() {
|
||||
|
||||
ReturnValue_t FixedTimeslotTask::addSlot(object_id_t componentId,
|
||||
uint32_t slotTimeMs, int8_t executionStep) {
|
||||
pst.addSlot(componentId, slotTimeMs, executionStep, this);
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
if (objectManager->get<ExecutableObjectIF>(componentId) != nullptr) {
|
||||
if(slotTimeMs == 0) {
|
||||
// FreeRTOS throws a sanity error for zero values, so we set
|
||||
// the time to one millisecond.
|
||||
slotTimeMs = 1;
|
||||
}
|
||||
pst.addSlot(componentId, slotTimeMs, executionStep, this);
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
sif::error << "Component " << std::hex << componentId <<
|
||||
" not found, not adding it to pst" << std::endl;
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
|
||||
uint32_t FixedTimeslotTask::getPeriodMs() const {
|
||||
@ -72,10 +82,10 @@ ReturnValue_t FixedTimeslotTask::checkSequence() const {
|
||||
|
||||
void FixedTimeslotTask::taskFunctionality() {
|
||||
// A local iterator for the Polling Sequence Table is created to find the start time for the first entry.
|
||||
std::list<FixedSequenceSlot*>::iterator it = pst.current;
|
||||
auto slotListIter = pst.current;
|
||||
|
||||
//The start time for the first entry is read.
|
||||
uint32_t intervalMs = (*it)->pollingTimeMs;
|
||||
uint32_t intervalMs = slotListIter->pollingTimeMs;
|
||||
TickType_t interval = pdMS_TO_TICKS(intervalMs);
|
||||
|
||||
TickType_t xLastWakeTime;
|
||||
@ -110,4 +120,3 @@ ReturnValue_t FixedTimeslotTask::sleepFor(uint32_t ms) {
|
||||
vTaskDelay(pdMS_TO_TICKS(ms));
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
|
@ -5,8 +5,10 @@
|
||||
#include <framework/tasks/FixedTimeslotTaskIF.h>
|
||||
#include <framework/tasks/Typedef.h>
|
||||
|
||||
#include <FreeRTOS.h>
|
||||
extern "C" {
|
||||
#include "FreeRTOS.h"
|
||||
#include "task.h"
|
||||
}
|
||||
|
||||
class FixedTimeslotTask: public FixedTimeslotTaskIF {
|
||||
public:
|
||||
|
@ -8,7 +8,7 @@ MessageQueue::MessageQueue(size_t message_depth, size_t max_message_size) :
|
||||
defaultDestination(0),lastPartner(0) {
|
||||
handle = xQueueCreate(message_depth, max_message_size);
|
||||
if (handle == NULL) {
|
||||
error << "MessageQueue creation failed" << std::endl;
|
||||
sif::error << "MessageQueue creation failed" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
@ -97,7 +97,8 @@ ReturnValue_t MessageQueue::sendMessageFromMessageQueue(MessageQueueId_t sendTo,
|
||||
bool ignoreFault) {
|
||||
message->setSender(sentFrom);
|
||||
|
||||
BaseType_t result = xQueueSendToBack(reinterpret_cast<void*>(sendTo),reinterpret_cast<const void*>(message->getBuffer()), 0);
|
||||
BaseType_t result = xQueueSendToBack(reinterpret_cast<QueueHandle_t>(sendTo),
|
||||
reinterpret_cast<const void*>(message->getBuffer()), 0);
|
||||
if (result != pdPASS) {
|
||||
if (!ignoreFault) {
|
||||
InternalErrorReporterIF* internalErrorReporter = objectManager->get<InternalErrorReporterIF>(
|
||||
|
@ -10,7 +10,8 @@ PeriodicTask::PeriodicTask(const char *name, TaskPriority setPriority,
|
||||
|
||||
BaseType_t status = xTaskCreate(taskEntryPoint, name, setStack, this, setPriority, &handle);
|
||||
if(status != pdPASS){
|
||||
debug << "PeriodicTask Insufficient heap memory remaining. Status: " << status << std::endl;
|
||||
sif::debug << "PeriodicTask Insufficient heap memory remaining. Status: "
|
||||
<< status << std::endl;
|
||||
}
|
||||
|
||||
}
|
||||
@ -34,7 +35,7 @@ void PeriodicTask::taskEntryPoint(void* argument) {
|
||||
}
|
||||
|
||||
originalTask->taskFunctionality();
|
||||
debug << "Polling task " << originalTask->handle
|
||||
sif::debug << "Polling task " << originalTask->handle
|
||||
<< " returned from taskFunctionality." << std::endl;
|
||||
}
|
||||
|
||||
|
@ -25,8 +25,8 @@ QueueFactory::~QueueFactory() {
|
||||
}
|
||||
|
||||
MessageQueueIF* QueueFactory::createMessageQueue(uint32_t message_depth,
|
||||
uint32_t max_message_size) {
|
||||
return new MessageQueue(message_depth, max_message_size);
|
||||
size_t maxMessageSize) {
|
||||
return new MessageQueue(message_depth, maxMessageSize);
|
||||
}
|
||||
|
||||
void QueueFactory::deleteMessageQueue(MessageQueueIF* queue) {
|
||||
|
@ -1,15 +1,14 @@
|
||||
#include <framework/serviceinterface/ServiceInterfaceStream.h>
|
||||
#include <unistd.h>
|
||||
#include <limits.h>
|
||||
#include <signal.h>
|
||||
#include <errno.h>
|
||||
#include <framework/osal/linux/FixedTimeslotTask.h>
|
||||
|
||||
#include <limits.h>
|
||||
|
||||
uint32_t FixedTimeslotTask::deadlineMissedCount = 0;
|
||||
const size_t PeriodicTaskIF::MINIMUM_STACK_SIZE = PTHREAD_STACK_MIN;
|
||||
|
||||
FixedTimeslotTask::FixedTimeslotTask(const char* name_, int priority_, size_t stackSize_, uint32_t periodMs_):PosixThread(name_,priority_,stackSize_),pst(periodMs_),started(false) {
|
||||
FixedTimeslotTask::FixedTimeslotTask(const char* name_, int priority_,
|
||||
size_t stackSize_, uint32_t periodMs_):
|
||||
PosixThread(name_,priority_,stackSize_),pst(periodMs_),started(false) {
|
||||
}
|
||||
|
||||
FixedTimeslotTask::~FixedTimeslotTask() {
|
||||
@ -21,7 +20,7 @@ void* FixedTimeslotTask::taskEntryPoint(void* arg) {
|
||||
FixedTimeslotTask *originalTask(reinterpret_cast<FixedTimeslotTask*>(arg));
|
||||
//The task's functionality is called.
|
||||
originalTask->taskFunctionality();
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
ReturnValue_t FixedTimeslotTask::startTask() {
|
||||
@ -40,8 +39,14 @@ uint32_t FixedTimeslotTask::getPeriodMs() const {
|
||||
|
||||
ReturnValue_t FixedTimeslotTask::addSlot(object_id_t componentId,
|
||||
uint32_t slotTimeMs, int8_t executionStep) {
|
||||
pst.addSlot(componentId, slotTimeMs, executionStep, this);
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
if (objectManager->get<ExecutableObjectIF>(componentId) != nullptr) {
|
||||
pst.addSlot(componentId, slotTimeMs, executionStep, this);
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
sif::error << "Component " << std::hex << componentId <<
|
||||
" not found, not adding it to pst" << std::endl;
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
|
||||
ReturnValue_t FixedTimeslotTask::checkSequence() const {
|
||||
@ -80,7 +85,7 @@ void FixedTimeslotTask::taskFunctionality() {
|
||||
void FixedTimeslotTask::missedDeadlineCounter() {
|
||||
FixedTimeslotTask::deadlineMissedCount++;
|
||||
if (FixedTimeslotTask::deadlineMissedCount % 10 == 0) {
|
||||
error << "PST missed " << FixedTimeslotTask::deadlineMissedCount
|
||||
<< " deadlines." << std::endl;
|
||||
sif::error << "PST missed " << FixedTimeslotTask::deadlineMissedCount
|
||||
<< " deadlines." << std::endl;
|
||||
}
|
||||
}
|
||||
|
@ -8,7 +8,20 @@
|
||||
|
||||
class FixedTimeslotTask: public FixedTimeslotTaskIF, public PosixThread {
|
||||
public:
|
||||
FixedTimeslotTask(const char* name_, int priority_, size_t stackSize_, uint32_t periodMs_);
|
||||
/**
|
||||
* Create a generic periodic task.
|
||||
* @param name_
|
||||
* Name, maximum allowed size of linux is 16 chars, everything else will
|
||||
* be truncated.
|
||||
* @param priority_
|
||||
* Real-time priority, ranges from 1 to 99 for Linux.
|
||||
* See: https://man7.org/linux/man-pages/man7/sched.7.html
|
||||
* @param stackSize_
|
||||
* @param period_
|
||||
* @param deadlineMissedFunc_
|
||||
*/
|
||||
FixedTimeslotTask(const char* name_, int priority_, size_t stackSize_,
|
||||
uint32_t periodMs_);
|
||||
virtual ~FixedTimeslotTask();
|
||||
|
||||
virtual ReturnValue_t startTask();
|
||||
@ -17,7 +30,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 +49,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 +60,13 @@ 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.
|
||||
*
|
||||
* The void* returnvalue is not used yet but could be used to return
|
||||
* arbitrary data.
|
||||
*/
|
||||
static void* taskEntryPoint(void* arg);
|
||||
FixedSlotSequence pst;
|
||||
|
@ -1,56 +1,37 @@
|
||||
#include <framework/serviceinterface/ServiceInterfaceStream.h>
|
||||
#include <fcntl.h> /* For O_* constants */
|
||||
#include <sys/stat.h> /* For mode constants */
|
||||
#include <mqueue.h>
|
||||
#include <cstring>
|
||||
#include <errno.h>
|
||||
#include <framework/osal/linux/MessageQueue.h>
|
||||
|
||||
#include <fstream>
|
||||
|
||||
MessageQueue::MessageQueue(size_t message_depth, size_t max_message_size) :
|
||||
id(0), lastPartner(0), defaultDestination(NO_QUEUE) {
|
||||
#include <fcntl.h> /* For O_* constants */
|
||||
#include <sys/stat.h> /* For mode constants */
|
||||
#include <cstring>
|
||||
#include <errno.h>
|
||||
|
||||
|
||||
MessageQueue::MessageQueue(uint32_t messageDepth, size_t maxMessageSize):
|
||||
id(MessageQueueIF::NO_QUEUE),lastPartner(MessageQueueIF::NO_QUEUE),
|
||||
defaultDestination(MessageQueueIF::NO_QUEUE) {
|
||||
//debug << "MessageQueue::MessageQueue: Creating a queue" << std::endl;
|
||||
mq_attr attributes;
|
||||
this->id = 0;
|
||||
//Set attributes
|
||||
attributes.mq_curmsgs = 0;
|
||||
attributes.mq_maxmsg = message_depth;
|
||||
attributes.mq_msgsize = max_message_size;
|
||||
attributes.mq_maxmsg = messageDepth;
|
||||
attributes.mq_msgsize = maxMessageSize;
|
||||
attributes.mq_flags = 0; //Flags are ignored on Linux during mq_open
|
||||
//Set the name of the queue. The slash is mandatory!
|
||||
sprintf(name, "/FSFW_MQ%u\n", queueCounter++);
|
||||
|
||||
//Set the name of the queue
|
||||
sprintf(name, "/Q%u\n", queueCounter++);
|
||||
|
||||
//Create a nonblocking queue if the name is available (the queue is Read and writable for the owner as well as the group)
|
||||
mqd_t tempId = mq_open(name, O_NONBLOCK | O_RDWR | O_CREAT | O_EXCL,
|
||||
S_IWUSR | S_IREAD | S_IWGRP | S_IRGRP | S_IROTH | S_IWOTH, &attributes);
|
||||
// Create a nonblocking queue if the name is available (the queue is read
|
||||
// and writable for the owner as well as the group)
|
||||
int oflag = O_NONBLOCK | O_RDWR | O_CREAT | O_EXCL;
|
||||
mode_t mode = S_IWUSR | S_IREAD | S_IWGRP | S_IRGRP | S_IROTH | S_IWOTH;
|
||||
mqd_t tempId = mq_open(name, oflag, mode, &attributes);
|
||||
if (tempId == -1) {
|
||||
//An error occured during open
|
||||
//We need to distinguish if it is caused by an already created queue
|
||||
if (errno == EEXIST) {
|
||||
//There's another queue with the same name
|
||||
//We unlink the other queue
|
||||
int status = mq_unlink(name);
|
||||
if (status != 0) {
|
||||
error << "mq_unlink Failed with status: " << strerror(errno)
|
||||
<< std::endl;
|
||||
} else {
|
||||
//Successful unlinking, try to open again
|
||||
mqd_t tempId = mq_open(name,
|
||||
O_NONBLOCK | O_RDWR | O_CREAT | O_EXCL,
|
||||
S_IWUSR | S_IREAD | S_IWGRP | S_IRGRP, &attributes);
|
||||
if (tempId != -1) {
|
||||
//Successful mq_open
|
||||
this->id = tempId;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
//Failed either the first time or the second time
|
||||
error << "MessageQueue::MessageQueue: Creating Queue " << std::hex
|
||||
<< name << std::dec << " failed with status: "
|
||||
<< strerror(errno) << std::endl;
|
||||
} else {
|
||||
handleError(&attributes, messageDepth);
|
||||
}
|
||||
else {
|
||||
//Successful mq_open call
|
||||
this->id = tempId;
|
||||
}
|
||||
@ -59,14 +40,83 @@ MessageQueue::MessageQueue(size_t message_depth, size_t max_message_size) :
|
||||
MessageQueue::~MessageQueue() {
|
||||
int status = mq_close(this->id);
|
||||
if(status != 0){
|
||||
error << "MessageQueue::Destructor: mq_close Failed with status: " << strerror(errno) <<std::endl;
|
||||
sif::error << "MessageQueue::Destructor: mq_close Failed with status: "
|
||||
<< strerror(errno) <<std::endl;
|
||||
}
|
||||
status = mq_unlink(name);
|
||||
if(status != 0){
|
||||
error << "MessageQueue::Destructor: mq_unlink Failed with status: " << strerror(errno) <<std::endl;
|
||||
sif::error << "MessageQueue::Destructor: mq_unlink Failed with status: "
|
||||
<< strerror(errno) <<std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
ReturnValue_t MessageQueue::handleError(mq_attr* attributes,
|
||||
uint32_t messageDepth) {
|
||||
switch(errno) {
|
||||
case(EINVAL): {
|
||||
sif::error << "MessageQueue::MessageQueue: Invalid name or attributes"
|
||||
" for message size" << std::endl;
|
||||
size_t defaultMqMaxMsg = 0;
|
||||
// Not POSIX conformant, but should work for all UNIX systems.
|
||||
// Just an additional helpful printout :-)
|
||||
if(std::ifstream("/proc/sys/fs/mqueue/msg_max",std::ios::in) >>
|
||||
defaultMqMaxMsg and defaultMqMaxMsg < messageDepth) {
|
||||
// See: https://www.man7.org/linux/man-pages/man3/mq_open.3.html
|
||||
// This happens if the msg_max value is not large enough
|
||||
// It is ignored if the executable is run in privileged mode.
|
||||
// Run the unlockRealtime script or grant the mode manually by using:
|
||||
// sudo setcap 'CAP_SYS_RESOURCE=+ep' <pathToBinary>
|
||||
|
||||
// Persistent solution for session:
|
||||
// echo <newMsgMax> | sudo tee /proc/sys/fs/mqueue/msg_max
|
||||
|
||||
// Permanent solution:
|
||||
// sudo nano /etc/sysctl.conf
|
||||
// Append at end: fs/mqueue/msg_max = <newMsgMaxLen>
|
||||
// Apply changes with: sudo sysctl -p
|
||||
sif::error << "MessageQueue::MessageQueue: Default MQ size "
|
||||
<< defaultMqMaxMsg << " is too small for requested size "
|
||||
<< messageDepth << std::endl;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case(EEXIST): {
|
||||
// An error occured during open
|
||||
// We need to distinguish if it is caused by an already created queue
|
||||
//There's another queue with the same name
|
||||
//We unlink the other queue
|
||||
int status = mq_unlink(name);
|
||||
if (status != 0) {
|
||||
sif::error << "mq_unlink Failed with status: " << strerror(errno)
|
||||
<< std::endl;
|
||||
}
|
||||
else {
|
||||
// Successful unlinking, try to open again
|
||||
mqd_t tempId = mq_open(name,
|
||||
O_NONBLOCK | O_RDWR | O_CREAT | O_EXCL,
|
||||
S_IWUSR | S_IREAD | S_IWGRP | S_IRGRP, attributes);
|
||||
if (tempId != -1) {
|
||||
//Successful mq_open
|
||||
this->id = tempId;
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
// Failed either the first time or the second time
|
||||
sif::error << "MessageQueue::MessageQueue: Creating Queue " << std::hex
|
||||
<< name << std::dec << " failed with status: "
|
||||
<< strerror(errno) << std::endl;
|
||||
|
||||
}
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
ReturnValue_t MessageQueue::sendMessage(MessageQueueId_t sendTo,
|
||||
MessageQueueMessage* message, bool ignoreFault) {
|
||||
return sendMessageFrom(sendTo, message, this->getId(), false);
|
||||
@ -93,7 +143,8 @@ ReturnValue_t MessageQueue::receiveMessage(MessageQueueMessage* message,
|
||||
|
||||
ReturnValue_t MessageQueue::receiveMessage(MessageQueueMessage* message) {
|
||||
unsigned int messagePriority = 0;
|
||||
int status = mq_receive(id,reinterpret_cast<char*>(message->getBuffer()),message->MAX_MESSAGE_SIZE,&messagePriority);
|
||||
int status = mq_receive(id,reinterpret_cast<char*>(message->getBuffer()),
|
||||
message->MAX_MESSAGE_SIZE,&messagePriority);
|
||||
if (status > 0) {
|
||||
this->lastPartner = message->getSender();
|
||||
//Check size of incoming message.
|
||||
@ -105,33 +156,44 @@ ReturnValue_t MessageQueue::receiveMessage(MessageQueueMessage* message) {
|
||||
//Success but no message received
|
||||
return MessageQueueIF::EMPTY;
|
||||
} else {
|
||||
//No message was received. Keep lastPartner anyway, I might send something later.
|
||||
//But still, delete packet content.
|
||||
//No message was received. Keep lastPartner anyway, I might send
|
||||
//something later. But still, delete packet content.
|
||||
memset(message->getData(), 0, message->MAX_DATA_SIZE);
|
||||
switch(errno){
|
||||
case EAGAIN:
|
||||
//O_NONBLOCK or MQ_NONBLOCK was set and there are no messages currently on the specified queue.
|
||||
//O_NONBLOCK or MQ_NONBLOCK was set and there are no messages
|
||||
//currently on the specified queue.
|
||||
return MessageQueueIF::EMPTY;
|
||||
case EBADF:
|
||||
//mqdes doesn't represent a valid queue open for reading.
|
||||
error << "MessageQueue::receive: configuration error " << strerror(errno) << std::endl;
|
||||
sif::error << "MessageQueue::receive: configuration error "
|
||||
<< strerror(errno) << std::endl;
|
||||
/*NO BREAK*/
|
||||
case EINVAL:
|
||||
/*
|
||||
* This value indicates one of the following:
|
||||
* * The pointer to the buffer for storing the received message, msg_ptr, is NULL.
|
||||
* * The number of bytes requested, msg_len is less than zero.
|
||||
* * msg_len is anything other than the mq_msgsize of the specified queue, and the QNX extended option MQ_READBUF_DYNAMIC hasn't been set in the queue's mq_flags.
|
||||
* - The pointer to the buffer for storing the received message,
|
||||
* msg_ptr, is NULL.
|
||||
* - The number of bytes requested, msg_len is less than zero.
|
||||
* - msg_len is anything other than the mq_msgsize of the specified
|
||||
* queue, and the QNX extended option MQ_READBUF_DYNAMIC hasn't
|
||||
* been set in the queue's mq_flags.
|
||||
*/
|
||||
error << "MessageQueue::receive: configuration error " << strerror(errno) << std::endl;
|
||||
sif::error << "MessageQueue::receive: configuration error "
|
||||
<< strerror(errno) << std::endl;
|
||||
/*NO BREAK*/
|
||||
case EMSGSIZE:
|
||||
/*
|
||||
* This value indicates one of the following:
|
||||
* * the QNX extended option MQ_READBUF_DYNAMIC hasn't been set, and the given msg_len is shorter than the mq_msgsize for the given queue.
|
||||
* * the extended option MQ_READBUF_DYNAMIC has been set, but the given msg_len is too short for the message that would have been received.
|
||||
* - the QNX extended option MQ_READBUF_DYNAMIC hasn't been set,
|
||||
* and the given msg_len is shorter than the mq_msgsize for
|
||||
* the given queue.
|
||||
* - the extended option MQ_READBUF_DYNAMIC has been set, but the
|
||||
* given msg_len is too short for the message that would have
|
||||
* been received.
|
||||
*/
|
||||
error << "MessageQueue::receive: configuration error " << strerror(errno) << std::endl;
|
||||
sif::error << "MessageQueue::receive: configuration error "
|
||||
<< strerror(errno) << std::endl;
|
||||
/*NO BREAK*/
|
||||
case EINTR:
|
||||
//The operation was interrupted by a signal.
|
||||
@ -154,7 +216,8 @@ ReturnValue_t MessageQueue::flush(uint32_t* count) {
|
||||
switch(errno){
|
||||
case EBADF:
|
||||
//mqdes doesn't represent a valid message queue.
|
||||
error << "MessageQueue::flush configuration error, called flush with an invalid queue ID" << std::endl;
|
||||
sif::error << "MessageQueue::flush configuration error, "
|
||||
"called flush with an invalid queue ID" << std::endl;
|
||||
/*NO BREAK*/
|
||||
case EINVAL:
|
||||
//mq_attr is NULL
|
||||
@ -169,14 +232,16 @@ ReturnValue_t MessageQueue::flush(uint32_t* count) {
|
||||
switch(errno){
|
||||
case EBADF:
|
||||
//mqdes doesn't represent a valid message queue.
|
||||
error << "MessageQueue::flush configuration error, called flush with an invalid queue ID" << std::endl;
|
||||
sif::error << "MessageQueue::flush configuration error, "
|
||||
"called flush with an invalid queue ID" << std::endl;
|
||||
/*NO BREAK*/
|
||||
case EINVAL:
|
||||
/*
|
||||
* This value indicates one of the following:
|
||||
* * mq_attr is NULL.
|
||||
* * MQ_MULT_NOTIFY had been set for this queue, and the given mq_flags includes a 0 in the MQ_MULT_NOTIFY bit. Once MQ_MULT_NOTIFY has been turned on, it may never be turned off.
|
||||
*
|
||||
* - mq_attr is NULL.
|
||||
* - MQ_MULT_NOTIFY had been set for this queue, and the given
|
||||
* mq_flags includes a 0 in the MQ_MULT_NOTIFY bit. Once
|
||||
* MQ_MULT_NOTIFY has been turned on, it may never be turned off.
|
||||
*/
|
||||
default:
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
@ -225,7 +290,8 @@ ReturnValue_t MessageQueue::sendMessageFromMessageQueue(MessageQueueId_t sendTo,
|
||||
//TODO: Check if we're in ISR.
|
||||
if (result != 0) {
|
||||
if(!ignoreFault){
|
||||
InternalErrorReporterIF* internalErrorReporter = objectManager->get<InternalErrorReporterIF>(
|
||||
InternalErrorReporterIF* internalErrorReporter =
|
||||
objectManager->get<InternalErrorReporterIF>(
|
||||
objects::INTERNAL_ERROR_REPORTER);
|
||||
if (internalErrorReporter != NULL) {
|
||||
internalErrorReporter->queueMessageNotSent();
|
||||
@ -233,27 +299,38 @@ ReturnValue_t MessageQueue::sendMessageFromMessageQueue(MessageQueueId_t sendTo,
|
||||
}
|
||||
switch(errno){
|
||||
case EAGAIN:
|
||||
//The O_NONBLOCK flag was set when opening the queue, or the MQ_NONBLOCK flag was set in its attributes, and the specified queue is full.
|
||||
//The O_NONBLOCK flag was set when opening the queue, or the
|
||||
//MQ_NONBLOCK flag was set in its attributes, and the
|
||||
//specified queue is full.
|
||||
return MessageQueueIF::FULL;
|
||||
case EBADF:
|
||||
//mq_des doesn't represent a valid message queue descriptor, or mq_des wasn't opened for writing.
|
||||
error << "MessageQueue::sendMessage: Configuration error " << strerror(errno) << " in mq_send mqSendTo: " << sendTo << " sent from " << sentFrom << std::endl;
|
||||
//mq_des doesn't represent a valid message queue descriptor,
|
||||
//or mq_des wasn't opened for writing.
|
||||
sif::error << "MessageQueue::sendMessage: Configuration error "
|
||||
<< strerror(errno) << " in mq_send mqSendTo: " << sendTo
|
||||
<< " sent from " << sentFrom << std::endl;
|
||||
/*NO BREAK*/
|
||||
case EINTR:
|
||||
//The call was interrupted by a signal.
|
||||
case EINVAL:
|
||||
/*
|
||||
* This value indicates one of the following:
|
||||
* * msg_ptr is NULL.
|
||||
* * msg_len is negative.
|
||||
* * msg_prio is greater than MQ_PRIO_MAX.
|
||||
* * msg_prio is less than 0.
|
||||
* * MQ_PRIO_RESTRICT is set in the mq_attr of mq_des, and msg_prio is greater than the priority of the calling process.
|
||||
* */
|
||||
error << "MessageQueue::sendMessage: Configuration error " << strerror(errno) << " in mq_send" << std::endl;
|
||||
* - msg_ptr is NULL.
|
||||
* - msg_len is negative.
|
||||
* - msg_prio is greater than MQ_PRIO_MAX.
|
||||
* - msg_prio is less than 0.
|
||||
* - MQ_PRIO_RESTRICT is set in the mq_attr of mq_des, and
|
||||
* msg_prio is greater than the priority of the calling process.
|
||||
*/
|
||||
sif::error << "MessageQueue::sendMessage: Configuration error "
|
||||
<< strerror(errno) << " in mq_send" << std::endl;
|
||||
/*NO BREAK*/
|
||||
case EMSGSIZE:
|
||||
//The msg_len is greater than the msgsize associated with the specified queue.
|
||||
// The msg_len is greater than the msgsize associated with
|
||||
//the specified queue.
|
||||
sif::error << "MessageQueue::sendMessage: Size error [" <<
|
||||
strerror(errno) << "] in mq_send" << std::endl;
|
||||
/*NO BREAK*/
|
||||
default:
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
|
@ -4,21 +4,26 @@
|
||||
#include <framework/internalError/InternalErrorReporterIF.h>
|
||||
#include <framework/ipc/MessageQueueIF.h>
|
||||
#include <framework/ipc/MessageQueueMessage.h>
|
||||
|
||||
#include <mqueue.h>
|
||||
/**
|
||||
* @brief This class manages sending and receiving of message queue messages.
|
||||
* @brief This class manages sending and receiving of message queue messages.
|
||||
*
|
||||
* @details Message queues are used to pass asynchronous messages between processes.
|
||||
* They work like post boxes, where all incoming messages are stored in FIFO
|
||||
* order. This class creates a new receiving queue and provides methods to fetch
|
||||
* received messages. Being a child of MessageQueueSender, this class also provides
|
||||
* methods to send a message to a user-defined or a default destination. In addition
|
||||
* it also provides a reply method to answer to the queue it received its last message
|
||||
* from.
|
||||
* The MessageQueue should be used as "post box" for a single owning object. So all
|
||||
* message queue communication is "n-to-one".
|
||||
* For creating the queue, as well as sending and receiving messages, the class makes
|
||||
* use of the operating system calls provided.
|
||||
* \ingroup message_queue
|
||||
* @details
|
||||
* Message queues are used to pass asynchronous messages between processes.
|
||||
* They work like post boxes, where all incoming messages are stored in FIFO
|
||||
* order. This class creates a new receiving queue and provides methods to fetch
|
||||
* received messages. Being a child of MessageQueueSender, this class also
|
||||
* provides methods to send a message to a user-defined or a default destination.
|
||||
* In addition it also provides a reply method to answer to the queue it
|
||||
* received its last message from.
|
||||
*
|
||||
* The MessageQueue should be used as "post box" for a single owning object.
|
||||
* So all message queue communication is "n-to-one".
|
||||
*
|
||||
* The creation of message queues, as well as sending and receiving messages,
|
||||
* makes use of the operating system calls provided.
|
||||
* @ingroup message_queue
|
||||
*/
|
||||
class MessageQueue : public MessageQueueIF {
|
||||
friend class MessageQueueSenderIF;
|
||||
@ -35,7 +40,8 @@ public:
|
||||
* @param max_message_size With this parameter, the maximum message size can be adjusted.
|
||||
* This should be left default.
|
||||
*/
|
||||
MessageQueue( size_t message_depth = 3, size_t max_message_size = MessageQueueMessage::MAX_MESSAGE_SIZE );
|
||||
MessageQueue(uint32_t messageDepth = 3,
|
||||
size_t maxMessageSize = MessageQueueMessage::MAX_MESSAGE_SIZE );
|
||||
/**
|
||||
* @brief The destructor deletes the formerly created message queue.
|
||||
* @details This is accomplished by using the delete call provided by the operating system.
|
||||
@ -168,6 +174,8 @@ private:
|
||||
char name[5];
|
||||
|
||||
static uint16_t queueCounter;
|
||||
|
||||
ReturnValue_t handleError(mq_attr* attributes, uint32_t messageDepth);
|
||||
};
|
||||
|
||||
#endif /* MESSAGEQUEUE_H_ */
|
||||
|
@ -13,22 +13,22 @@ Mutex::Mutex() {
|
||||
pthread_mutexattr_t mutexAttr;
|
||||
int status = pthread_mutexattr_init(&mutexAttr);
|
||||
if (status != 0) {
|
||||
error << "Mutex: Attribute init failed with: " << strerror(status) << std::endl;
|
||||
sif::error << "Mutex: Attribute init failed with: " << strerror(status) << std::endl;
|
||||
}
|
||||
status = pthread_mutexattr_setprotocol(&mutexAttr, PTHREAD_PRIO_INHERIT);
|
||||
if (status != 0) {
|
||||
error << "Mutex: Attribute set PRIO_INHERIT failed with: " << strerror(status)
|
||||
sif::error << "Mutex: Attribute set PRIO_INHERIT failed with: " << strerror(status)
|
||||
<< std::endl;
|
||||
}
|
||||
status = pthread_mutex_init(&mutex, &mutexAttr);
|
||||
if (status != 0) {
|
||||
error << "Mutex: creation with name, id " << mutex.__data.__count
|
||||
sif::error << "Mutex: creation with name, id " << mutex.__data.__count
|
||||
<< ", " << " failed with " << strerror(status) << std::endl;
|
||||
}
|
||||
//After a mutex attributes object has been used to initialize one or more mutexes, any function affecting the attributes object (including destruction) shall not affect any previously initialized mutexes.
|
||||
status = pthread_mutexattr_destroy(&mutexAttr);
|
||||
if (status != 0) {
|
||||
error << "Mutex: Attribute destroy failed with " << strerror(status) << std::endl;
|
||||
sif::error << "Mutex: Attribute destroy failed with " << strerror(status) << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3,9 +3,10 @@
|
||||
#include <errno.h>
|
||||
#include <framework/osal/linux/PeriodicPosixTask.h>
|
||||
|
||||
PeriodicPosixTask::PeriodicPosixTask(const char* name_, int priority_, size_t stackSize_, uint32_t period_, void(deadlineMissedFunc_)()):PosixThread(name_,priority_,stackSize_),objectList(),started(false),periodMs(period_),deadlineMissedFunc(
|
||||
deadlineMissedFunc_) {
|
||||
|
||||
PeriodicPosixTask::PeriodicPosixTask(const char* name_, int priority_,
|
||||
size_t stackSize_, uint32_t period_, void(deadlineMissedFunc_)()):
|
||||
PosixThread(name_,priority_,stackSize_),objectList(),started(false),
|
||||
periodMs(period_),deadlineMissedFunc(deadlineMissedFunc_) {
|
||||
}
|
||||
|
||||
PeriodicPosixTask::~PeriodicPosixTask() {
|
||||
@ -37,7 +38,8 @@ ReturnValue_t PeriodicPosixTask::sleepFor(uint32_t ms) {
|
||||
|
||||
ReturnValue_t PeriodicPosixTask::startTask(void){
|
||||
started = true;
|
||||
createTask(&taskEntryPoint,this);
|
||||
//sif::info << stackSize << std::endl;
|
||||
PosixThread::createTask(&taskEntryPoint,this);
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
@ -56,9 +58,11 @@ void PeriodicPosixTask::taskFunctionality(void){
|
||||
char name[20] = {0};
|
||||
int status = pthread_getname_np(pthread_self(),name,sizeof(name));
|
||||
if(status==0){
|
||||
error << "ObjectTask: " << name << " Deadline missed." << std::endl;
|
||||
sif::error << "PeriodicPosixTask " << name << ": Deadline "
|
||||
"missed." << std::endl;
|
||||
}else{
|
||||
error << "ObjectTask: X Deadline missed. " << status << std::endl;
|
||||
sif::error << "PeriodicPosixTask X: Deadline missed. " <<
|
||||
status << std::endl;
|
||||
}
|
||||
if (this->deadlineMissedFunc != NULL) {
|
||||
this->deadlineMissedFunc();
|
||||
|
@ -9,8 +9,22 @@
|
||||
|
||||
class PeriodicPosixTask: public PosixThread, public PeriodicTaskIF {
|
||||
public:
|
||||
PeriodicPosixTask(const char* name_, int priority_, size_t stackSize_, uint32_t period_, void(*deadlineMissedFunc_)());
|
||||
/**
|
||||
* Create a generic periodic task.
|
||||
* @param name_
|
||||
* Name, maximum allowed size of linux is 16 chars, everything else will
|
||||
* be truncated.
|
||||
* @param priority_
|
||||
* Real-time priority, ranges from 1 to 99 for Linux.
|
||||
* See: https://man7.org/linux/man-pages/man7/sched.7.html
|
||||
* @param stackSize_
|
||||
* @param period_
|
||||
* @param deadlineMissedFunc_
|
||||
*/
|
||||
PeriodicPosixTask(const char* name_, int priority_, size_t stackSize_,
|
||||
uint32_t period_, void(*deadlineMissedFunc_)());
|
||||
virtual ~PeriodicPosixTask();
|
||||
|
||||
/**
|
||||
* @brief The method to start the task.
|
||||
* @details The method starts the task with the respective system call.
|
||||
|
@ -1,8 +1,13 @@
|
||||
#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_) {
|
||||
name[0] = '\0';
|
||||
std::strncat(name, name_, PTHREAD_MAX_NAMELEN - 1);
|
||||
}
|
||||
|
||||
PosixThread::~PosixThread() {
|
||||
//No deletion and no free of Stack Pointer
|
||||
@ -22,7 +27,8 @@ ReturnValue_t PosixThread::sleep(uint64_t ns) {
|
||||
//The nanosleep() function was interrupted by a signal.
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
case EINVAL:
|
||||
//The rqtp argument specified a nanosecond value less than zero or greater than or equal to 1000 million.
|
||||
//The rqtp argument specified a nanosecond value less than zero or
|
||||
// greater than or equal to 1000 million.
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
default:
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
@ -40,8 +46,8 @@ void PosixThread::suspend() {
|
||||
sigaddset(&waitSignal, SIGUSR1);
|
||||
sigwait(&waitSignal, &caughtSig);
|
||||
if (caughtSig != SIGUSR1) {
|
||||
error << "FixedTimeslotTask: Unknown Signal received: " << caughtSig
|
||||
<< std::endl;
|
||||
sif::error << "FixedTimeslotTask: Unknown Signal received: " <<
|
||||
caughtSig << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
@ -54,10 +60,6 @@ void PosixThread::resume(){
|
||||
pthread_kill(thread,SIGUSR1);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
bool PosixThread::delayUntil(uint64_t* const prevoiusWakeTime_ms,
|
||||
const uint64_t delayTime_ms) {
|
||||
uint64_t nextTimeToWake_ms;
|
||||
@ -112,14 +114,9 @@ uint64_t PosixThread::getCurrentMonotonicTimeMs(){
|
||||
return currentTime_ms;
|
||||
}
|
||||
|
||||
PosixThread::PosixThread(const char* name_, int priority_, size_t stackSize_):thread(0),priority(priority_),stackSize(stackSize_) {
|
||||
strcpy(name,name_);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void PosixThread::createTask(void* (*fnc_)(void*), void* arg_) {
|
||||
debug << "PosixThread::createTask" << std::endl;
|
||||
//sif::debug << "PosixThread::createTask" << std::endl;
|
||||
/*
|
||||
* The attr argument points to a pthread_attr_t structure whose contents
|
||||
are used at thread creation time to determine attributes for the new
|
||||
@ -130,35 +127,51 @@ void PosixThread::createTask(void* (*fnc_)(void*), void* arg_) {
|
||||
pthread_attr_t attributes;
|
||||
int status = pthread_attr_init(&attributes);
|
||||
if(status != 0){
|
||||
error << "Posix Thread attribute init failed with: " << strerror(status) << std::endl;
|
||||
sif::error << "Posix Thread attribute init failed with: " <<
|
||||
strerror(status) << std::endl;
|
||||
}
|
||||
void* sp;
|
||||
status = posix_memalign(&sp, sysconf(_SC_PAGESIZE), stackSize);
|
||||
void* stackPointer;
|
||||
status = posix_memalign(&stackPointer, sysconf(_SC_PAGESIZE), stackSize);
|
||||
if(status != 0){
|
||||
error << "Posix Thread stack init failed with: " << strerror(status) << std::endl;
|
||||
sif::error << "PosixThread::createTask: Stack init failed with: " <<
|
||||
strerror(status) << std::endl;
|
||||
if(errno == ENOMEM) {
|
||||
uint64_t stackMb = stackSize/10e6;
|
||||
sif::error << "PosixThread::createTask: Insufficient memory for"
|
||||
" the requested " << stackMb << " MB" << std::endl;
|
||||
}
|
||||
else if(errno == EINVAL) {
|
||||
sif::error << "PosixThread::createTask: Wrong alignment argument!"
|
||||
<< std::endl;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
status = pthread_attr_setstack(&attributes, sp, stackSize);
|
||||
status = pthread_attr_setstack(&attributes, stackPointer, stackSize);
|
||||
if(status != 0){
|
||||
error << "Posix Thread attribute setStack failed with: " << strerror(status) << std::endl;
|
||||
sif::error << "Posix Thread attribute setStack failed with: " <<
|
||||
strerror(status) << std::endl;
|
||||
}
|
||||
|
||||
status = pthread_attr_setinheritsched(&attributes, PTHREAD_EXPLICIT_SCHED);
|
||||
if(status != 0){
|
||||
error << "Posix Thread attribute setinheritsched failed with: " << strerror(status) << std::endl;
|
||||
sif::error << "Posix Thread attribute setinheritsched failed with: " <<
|
||||
strerror(status) << std::endl;
|
||||
}
|
||||
|
||||
//TODO FIFO -> This needs root privileges for the process
|
||||
// TODO FIFO -> This needs root privileges for the process
|
||||
status = pthread_attr_setschedpolicy(&attributes,SCHED_FIFO);
|
||||
if(status != 0){
|
||||
error << "Posix Thread attribute schedule policy failed with: " << strerror(status) << std::endl;
|
||||
sif::error << "Posix Thread attribute schedule policy failed with: " <<
|
||||
strerror(status) << std::endl;
|
||||
}
|
||||
|
||||
sched_param scheduleParams;
|
||||
scheduleParams.__sched_priority = priority;
|
||||
status = pthread_attr_setschedparam(&attributes, &scheduleParams);
|
||||
if(status != 0){
|
||||
error << "Posix Thread attribute schedule params failed with: " << strerror(status) << std::endl;
|
||||
sif::error << "Posix Thread attribute schedule params failed with: " <<
|
||||
strerror(status) << std::endl;
|
||||
}
|
||||
|
||||
//Set Signal Mask for suspend until startTask is called
|
||||
@ -167,22 +180,36 @@ void PosixThread::createTask(void* (*fnc_)(void*), void* arg_) {
|
||||
sigaddset(&waitSignal, SIGUSR1);
|
||||
status = pthread_sigmask(SIG_BLOCK, &waitSignal, NULL);
|
||||
if(status != 0){
|
||||
error << "Posix Thread sigmask failed failed with: " << strerror(status) << " errno: " << strerror(errno) << std::endl;
|
||||
sif::error << "Posix Thread sigmask failed failed with: " <<
|
||||
strerror(status) << " errno: " << strerror(errno) << std::endl;
|
||||
}
|
||||
|
||||
|
||||
status = pthread_create(&thread,&attributes,fnc_,arg_);
|
||||
if(status != 0){
|
||||
error << "Posix Thread create failed with: " << strerror(status) << std::endl;
|
||||
sif::error << "Posix Thread create failed with: " <<
|
||||
strerror(status) << std::endl;
|
||||
}
|
||||
|
||||
status = pthread_setname_np(thread,name);
|
||||
if(status != 0){
|
||||
error << "Posix Thread setname failed with: " << strerror(status) << std::endl;
|
||||
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);
|
||||
if(status!=0){
|
||||
error << "Posix Thread attribute destroy failed with: " << strerror(status) << std::endl;
|
||||
sif::error << "Posix Thread attribute destroy failed with: " <<
|
||||
strerror(status) << std::endl;
|
||||
}
|
||||
}
|
||||
|
@ -1,15 +1,15 @@
|
||||
#ifndef FRAMEWORK_OSAL_LINUX_POSIXTHREAD_H_
|
||||
#define FRAMEWORK_OSAL_LINUX_POSIXTHREAD_H_
|
||||
|
||||
#include <pthread.h>
|
||||
#include <sched.h>
|
||||
#include <signal.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <framework/returnvalues/HasReturnvaluesIF.h>
|
||||
#include <pthread.h>
|
||||
#include <signal.h>
|
||||
#include <cstdlib>
|
||||
#include <unistd.h>
|
||||
|
||||
class PosixThread {
|
||||
public:
|
||||
static constexpr uint8_t PTHREAD_MAX_NAMELEN = 16;
|
||||
PosixThread(const char* name_, int priority_, size_t stackSize_);
|
||||
virtual ~PosixThread();
|
||||
/**
|
||||
@ -54,21 +54,24 @@ protected:
|
||||
pthread_t thread;
|
||||
|
||||
/**
|
||||
* @brief Function that has to be called by derived class because the derived class pointer has to be valid as argument
|
||||
* @details This function creates a pthread with the given parameters. As the function requires a pointer to the derived object
|
||||
* it has to be called after the this pointer of the derived object is valid. Sets the taskEntryPoint as
|
||||
* function to be called by new a thread.
|
||||
* @param name_ Name of the task
|
||||
* @param priority_ Priority of the task according to POSIX
|
||||
* @param stackSize_ Size of the stack attached to that task
|
||||
* @param arg_ argument of the taskEntryPoint function, needs to be this pointer of derived class
|
||||
* @brief Function that has to be called by derived class because the
|
||||
* derived class pointer has to be valid as argument.
|
||||
* @details
|
||||
* This function creates a pthread with the given parameters. As the
|
||||
* function requires a pointer to the derived object it has to be called
|
||||
* after the this pointer of the derived object is valid.
|
||||
* Sets the taskEntryPoint as function to be called by new a thread.
|
||||
* @param fnc_ Function which will be executed by the thread.
|
||||
* @param arg_
|
||||
* argument of the taskEntryPoint function, needs to be this pointer
|
||||
* of derived class
|
||||
*/
|
||||
void createTask(void* (*fnc_)(void*),void* arg_);
|
||||
|
||||
private:
|
||||
char name[10];
|
||||
char name[PTHREAD_MAX_NAMELEN];
|
||||
int priority;
|
||||
size_t stackSize;
|
||||
size_t stackSize = 0;
|
||||
};
|
||||
|
||||
#endif /* FRAMEWORK_OSAL_LINUX_POSIXTHREAD_H_ */
|
||||
|
@ -5,16 +5,18 @@
|
||||
#include <framework/serviceinterface/ServiceInterfaceStream.h>
|
||||
#include <cstring>
|
||||
|
||||
QueueFactory* QueueFactory::factoryInstance = NULL;
|
||||
QueueFactory* QueueFactory::factoryInstance = nullptr;
|
||||
|
||||
|
||||
ReturnValue_t MessageQueueSenderIF::sendMessage(MessageQueueId_t sendTo,
|
||||
MessageQueueMessage* message, MessageQueueId_t sentFrom,bool ignoreFault) {
|
||||
return MessageQueue::sendMessageFromMessageQueue(sendTo,message,sentFrom,ignoreFault);
|
||||
MessageQueueMessage* message, MessageQueueId_t sentFrom,
|
||||
bool ignoreFault) {
|
||||
return MessageQueue::sendMessageFromMessageQueue(sendTo,message,
|
||||
sentFrom,ignoreFault);
|
||||
}
|
||||
|
||||
QueueFactory* QueueFactory::instance() {
|
||||
if (factoryInstance == NULL) {
|
||||
if (factoryInstance == nullptr) {
|
||||
factoryInstance = new QueueFactory;
|
||||
}
|
||||
return factoryInstance;
|
||||
@ -26,9 +28,9 @@ QueueFactory::QueueFactory() {
|
||||
QueueFactory::~QueueFactory() {
|
||||
}
|
||||
|
||||
MessageQueueIF* QueueFactory::createMessageQueue(uint32_t message_depth,
|
||||
uint32_t max_message_size) {
|
||||
return new MessageQueue(message_depth, max_message_size);
|
||||
MessageQueueIF* QueueFactory::createMessageQueue(uint32_t messageDepth,
|
||||
size_t maxMessageSize) {
|
||||
return new MessageQueue(messageDepth, maxMessageSize);
|
||||
}
|
||||
|
||||
void QueueFactory::deleteMessageQueue(MessageQueueIF* queue) {
|
||||
|
@ -13,12 +13,20 @@ TaskFactory* TaskFactory::instance() {
|
||||
return TaskFactory::factoryInstance;
|
||||
}
|
||||
|
||||
PeriodicTaskIF* TaskFactory::createPeriodicTask(TaskName name_,TaskPriority taskPriority_,TaskStackSize stackSize_,TaskPeriod periodInSeconds_,TaskDeadlineMissedFunction deadLineMissedFunction_) {
|
||||
return static_cast<PeriodicTaskIF*>(new PeriodicPosixTask(name_, taskPriority_,stackSize_,periodInSeconds_ * 1000,deadLineMissedFunction_));
|
||||
PeriodicTaskIF* TaskFactory::createPeriodicTask(TaskName name_,
|
||||
TaskPriority taskPriority_,TaskStackSize stackSize_,
|
||||
TaskPeriod periodInSeconds_,
|
||||
TaskDeadlineMissedFunction deadLineMissedFunction_) {
|
||||
return new PeriodicPosixTask(name_, taskPriority_,stackSize_,
|
||||
periodInSeconds_ * 1000, deadLineMissedFunction_);
|
||||
}
|
||||
|
||||
FixedTimeslotTaskIF* TaskFactory::createFixedTimeslotTask(TaskName name_,TaskPriority taskPriority_,TaskStackSize stackSize_,TaskPeriod periodInSeconds_,TaskDeadlineMissedFunction deadLineMissedFunction_) {
|
||||
return static_cast<FixedTimeslotTaskIF*>(new FixedTimeslotTask(name_, taskPriority_,stackSize_,periodInSeconds_*1000));
|
||||
FixedTimeslotTaskIF* TaskFactory::createFixedTimeslotTask(TaskName name_,
|
||||
TaskPriority taskPriority_,TaskStackSize stackSize_,
|
||||
TaskPeriod periodInSeconds_,
|
||||
TaskDeadlineMissedFunction deadLineMissedFunction_) {
|
||||
return new FixedTimeslotTask(name_, taskPriority_,stackSize_,
|
||||
periodInSeconds_*1000);
|
||||
}
|
||||
|
||||
ReturnValue_t TaskFactory::deleteTask(PeriodicTaskIF* task) {
|
||||
|
@ -9,7 +9,8 @@ Timer::Timer() {
|
||||
sigEvent.sigev_value.sival_ptr = &timerId;
|
||||
int status = timer_create(CLOCK_MONOTONIC, &sigEvent, &timerId);
|
||||
if(status!=0){
|
||||
error << "Timer creation failed with: " << status << " errno: " << errno << std::endl;
|
||||
sif::error << "Timer creation failed with: " << status <<
|
||||
" errno: " << errno << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -66,10 +66,16 @@ ReturnValue_t PollingTask::startTask() {
|
||||
}
|
||||
}
|
||||
|
||||
ReturnValue_t PollingTask::addSlot(object_id_t componentId, uint32_t slotTimeMs,
|
||||
int8_t executionStep) {
|
||||
pst.addSlot(componentId, slotTimeMs, executionStep, this);
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
ReturnValue_t PollingTask::addSlot(object_id_t componentId,
|
||||
uint32_t slotTimeMs, int8_t executionStep) {
|
||||
if (objectManager->get<ExecutableObjectIF>(componentId) != nullptr) {
|
||||
pst.addSlot(componentId, slotTimeMs, executionStep, this);
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
error << "Component " << std::hex << componentId <<
|
||||
" not found, not adding it to pst" << std::endl;
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
|
||||
uint32_t PollingTask::getPeriodMs() const {
|
||||
|
@ -49,9 +49,9 @@ QueueFactory::QueueFactory() {
|
||||
QueueFactory::~QueueFactory() {
|
||||
}
|
||||
|
||||
MessageQueueIF* QueueFactory::createMessageQueue(uint32_t message_depth,
|
||||
uint32_t max_message_size) {
|
||||
return new MessageQueue(message_depth, max_message_size);
|
||||
MessageQueueIF* QueueFactory::createMessageQueue(uint32_t messageDepth,
|
||||
size_t maxMessageSize) {
|
||||
return new MessageQueue(messageDepth, maxMessageSize);
|
||||
}
|
||||
|
||||
void QueueFactory::deleteMessageQueue(MessageQueueIF* queue) {
|
||||
|
Reference in New Issue
Block a user