Skip to content

Commit

Permalink
AuxTaskRT: if the desired queue parameters do not work, try with syst…
Browse files Browse the repository at this point in the history
…em defaults. This helps when running with stock max limits on popular distros. Also do not cleanup queues if not properly created)
  • Loading branch information
giuliomoro committed Jun 1, 2024
1 parent 4d699c1 commit 8502912
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 15 deletions.
54 changes: 39 additions & 15 deletions core/AuxTaskRT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,58 @@
#include <stdlib.h>
#include <vector>
#include <string.h>

AuxTaskRT::~AuxTaskRT()
{
lShouldStop = true;
struct timespec absoluteTimeout = {0, 0};
// non blocking write, so if the queue is full it won't fail
char c = 0;
int ret = BELA_RT_WRAP(mq_timedsend(queueDesc, &c, sizeof(c), 0, &absoluteTimeout));
if(ret)
fprintf(stderr, "Error mq_timedsend: %d %s\n", errno, strerror(errno));
if(queueValid)
{
struct timespec absoluteTimeout = {0, 0};
// non blocking write, so if the queue is full it won't fail
char c = 0;
int ret = BELA_RT_WRAP(mq_timedsend(queueDesc, &c, sizeof(c), 0, &absoluteTimeout));
if(ret)
fprintf(stderr, "Error mq_timedsend: %d %s\n", errno, strerror(errno));
}
join();
ret = BELA_RT_WRAP(mq_close(queueDesc));
if(ret)
fprintf(stderr, "Error closing queueDesc: %d %s\n", errno, strerror(errno));
ret = BELA_RT_WRAP(mq_unlink(queueName.c_str()));
if(ret)
fprintf(stderr, "Error unlinking queue: %d %s\n", errno, strerror(errno));
if(queueValid)
{
int ret = BELA_RT_WRAP(mq_close(queueDesc));
if(ret)
fprintf(stderr, "Error closing queueDesc: %d %s\n", errno, strerror(errno));
ret = BELA_RT_WRAP(mq_unlink(queueName.c_str()));
if(ret)
fprintf(stderr, "Error unlinking queue: %d %s\n", errno, strerror(errno));
}
}

int AuxTaskRT::commsInit()
{
// create a queue, with prefixed name
queueName = std::string("/q_") + name;
queueName = std::string("/q_") + name + std::to_string((long long unsigned)(this));
struct mq_attr attr;
attr.mq_maxmsg = 100;
attr.mq_msgsize = 100000;
queueDesc = BELA_RT_WRAP(mq_open(queueName.c_str(), O_CREAT | O_RDWR, 0644, &attr));
if((mqd_t)-1 == queueDesc)
// first try with our desired queue properties, failing that try with the system defaults
for(auto& ptr : {&attr, (struct mq_attr*)nullptr})
{
queueDesc = BELA_RT_WRAP(mq_open(queueName.c_str(), O_CREAT | O_RDWR, 0644, ptr));
queueValid = ((mqd_t)-1 != queueDesc);
if(queueValid)
{
break;
} else {
if(&attr == ptr)
{
fprintf(stderr, "Opening queue %s with desired settings failed, trying with system defaults\n", queueName.c_str());
}
}
}
if(!queueValid)
{
fprintf(stderr, "Error creating queue %s: %d %s\n", queueName.c_str(), errno, strerror(errno));
return 1;
}
return 0;
}

Expand Down
1 change: 1 addition & 0 deletions include/AuxTaskRT.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@ class AuxTaskRT : public SchedulableThread
int commsSend(const void* buf, size_t size);
ssize_t commsReceive(char* buf, size_t size);
mqd_t queueDesc;
bool queueValid = false;
std::string queueName;
};

0 comments on commit 8502912

Please sign in to comment.