Skip to content

Commit

Permalink
const improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
vovatrykoz committed Dec 28, 2024
1 parent b1dd59f commit a184752
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 25 deletions.
3 changes: 1 addition & 2 deletions source/Analysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ std::multiset<TimedPath> analysis::removePathsProducingDublicateValues(
const std::multiset<TimedPath>& pathSet) {
std::multiset<TimedPath> output;

int totalTaskCount = pathSet.size();
for (const auto& currentPath : pathSet) {
bool isDuplicate = false;

Expand Down Expand Up @@ -63,7 +62,7 @@ std::multiset<TimedPath> analysis::removePathsProducingDublicateValues(
// set.
std::optional<TimedPath> analysis::getPathWithMaximumLatency(
const std::multiset<TimedPath>& pathSet) {
auto maxLatencyIt =
const auto maxLatencyIt =
std::max_element(pathSet.begin(), pathSet.end(),
[](const TimedPath& a, const TimedPath& b) {
return a.endToEndDelay() < b.endToEndDelay();
Expand Down
16 changes: 8 additions & 8 deletions source/MathFramework.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ bool mathframework::att(const PeriodicTaskInstance& writerTaskInstance,
// writer's worst-case response time (wcrt).
bool mathframework::crit(const PeriodicTaskInstance& writerTaskInstance,
const PeriodicTaskInstance& readerTaskInstance) {
int writerTaskTerminationTime =
const int writerTaskTerminationTime =
writerTaskInstance.activationTime + writerTaskInstance.baseTask.wcrt;

if (readerTaskInstance.activationTime < writerTaskTerminationTime) {
Expand All @@ -41,11 +41,11 @@ bool mathframework::wait(const PeriodicTask& writerTask,
// time travel, criticality, and priority.
bool mathframework::forw(const PeriodicTaskInstance& writerTaskInstance,
const PeriodicTaskInstance& readerTaskInstance) {
bool instancesDoNotTimeTravel =
const bool instancesDoNotTimeTravel =
!att(writerTaskInstance, readerTaskInstance);
bool instancesAreNonCritical =
const bool instancesAreNonCritical =
!crit(writerTaskInstance, readerTaskInstance);
bool readerHasToWait =
const bool readerHasToWait =
wait(writerTaskInstance.baseTask, readerTaskInstance.baseTask);

if (instancesDoNotTimeTravel &&
Expand All @@ -61,9 +61,9 @@ bool mathframework::forw(const PeriodicTaskInstance& writerTaskInstance,
bool mathframework::reach(const PeriodicTaskInstance& currentWriterTaskInstance,
const PeriodicTaskInstance& readerTaskInstance,
const PeriodicTaskInstance& nextWriterTaskInstance) {
bool readerInstanceIsReachable =
const bool readerInstanceIsReachable =
forw(currentWriterTaskInstance, readerTaskInstance);
bool nextWriterInstanceCannotReachReaderInstance =
const bool nextWriterInstanceCannotReachReaderInstance =
!forw(nextWriterTaskInstance, readerTaskInstance);

if (readerInstanceIsReachable &&
Expand All @@ -82,13 +82,13 @@ bool mathframework::pathReach(
return false;
}

std::size_t pathSize = timedPath.size();
const std::size_t pathSize = timedPath.size();
if (pathSize == 1) {
return true;
}

for (std::size_t i = 0; i < pathSize - 1; i++) {
bool pathIsNotReachable =
const bool pathIsNotReachable =
!reach(timedPath[i], timedPath[i + 1], timedPath[i].nextInstance());

if (pathIsNotReachable) {
Expand Down
2 changes: 1 addition & 1 deletion source/PeriodicTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ using namespace e2e;
// Calculate the next instance's activation time based on the current activation
// time and the task's period.
PeriodicTaskInstance PeriodicTaskInstance::nextInstance() const {
int nextActivationTime = this->activationTime + this->baseTask.period;
const int nextActivationTime = this->activationTime + this->baseTask.period;
return PeriodicTaskInstance(this->baseTask, nextActivationTime);
}
10 changes: 5 additions & 5 deletions source/TimedPath.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ int TimedPath::endToEndDelay() const {
return 0;
}

std::size_t size = this->tasks.size();
const std::size_t size = this->tasks.size();
if (size == 1) {
return this->tasks[0].baseTask.wcrt;
}
Expand All @@ -42,19 +42,19 @@ int TimedPath::lastTaskActivationTime() const {
return 0;
}

std::size_t lastElementIndex = this->tasks.size() - 1;
const std::size_t lastElementIndex = this->tasks.size() - 1;
return this->tasks[lastElementIndex].activationTime;
}

bool TimedPath::succeeds(const TimedPath& other) const {
int thisPathPeriod = this->calculatePathPeriod();
int otherPathPeriod = other.calculatePathPeriod();
const int thisPathPeriod = this->calculatePathPeriod();
const int otherPathPeriod = other.calculatePathPeriod();

if (thisPathPeriod != otherPathPeriod) {
return false;
}

int otherPathInstanceResetTime =
const int otherPathInstanceResetTime =
other.firstTaskActivationTime() + otherPathPeriod;

return this->firstTaskActivationTime() == otherPathInstanceResetTime;
Expand Down
2 changes: 1 addition & 1 deletion source/io/reader/ConsoleTaskReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ using namespace e2e::io;
std::vector<NamedTask> ConsoleTaskReader::readTaskChain() const {
std::vector<NamedTask> result;
std::string name;
int numOfChains = readInt("How many tasks should be in the system: ");
const int numOfChains = readInt("How many tasks should be in the system: ");

for (int i = 0; i < numOfChains; i++) {
NamedTask task = this->readTask();
Expand Down
18 changes: 10 additions & 8 deletions source/io/reader/TaskInstanceInputReader.cpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
#include "io/reader/ConsoleTaskInstanceReader.h"

#include <iostream>
#include <limits>

#include "io/reader/ConsoleTaskInstanceReader.h"

using namespace e2e;
using namespace e2e::io;

std::multiset<TimedPath> ConsoleTaskInstanceReader::readPathsSet() const {
std::multiset<TimedPath> result;
std::string name;
int numOfChains = readInt("How many task chains do you want to analyse: ");
const int numOfChains =
readInt("How many task chains do you want to analyse: ");

for (int i = 0; i < numOfChains; i++) {
std::cout << "Enter task chain name: ";
Expand Down Expand Up @@ -46,10 +47,11 @@ int ConsoleTaskInstanceReader::readInt(const std::string& message) const {
}

PeriodicTaskInstance ConsoleTaskInstanceReader::readTaskInstance() const {
int period = readInt("Enter task period: ");
int wcrt = readInt("Enter worst case response time for the task: ");
int priority = readInt("Enter task priority: ");
int activationTime = readInt("Enter task activation time or offset: ");
const int period = readInt("Enter task period: ");
const int wcrt = readInt("Enter worst case response time for the task: ");
const int priority = readInt("Enter task priority: ");
const int activationTime =
readInt("Enter task activation time or offset: ");

return PeriodicTaskInstance(PeriodicTask(period, wcrt, priority),
activationTime);
Expand All @@ -59,7 +61,7 @@ TimedPath ConsoleTaskInstanceReader::readTimedPath(
const std::string& name) const {
TimedPath timedPath(name);

int numOfTasks = readInt("How many tasks should be in the chain: ");
const int numOfTasks = readInt("How many tasks should be in the chain: ");

for (int i = 0; i < numOfTasks; i++) {
std::cout << "Reading Task " << i + 1 << std::endl;
Expand Down

0 comments on commit a184752

Please sign in to comment.