diff --git a/include/MathFramework.h b/include/MathFramework.h index 96e18c2..6ecdea1 100644 --- a/include/MathFramework.h +++ b/include/MathFramework.h @@ -22,4 +22,18 @@ */ bool att(const TaskInstance& writerTask, const TaskInstance& readerTask); +/** + * @brief Determines if the writer and reader tasks overlap in execution. + * + * The more important “critical function” crit determines if + * (even in case of non-activation time travel) writer and reader + * overlap in execution: + * + * @param writerTask The task instance representing the writer. + * @param readerTask The task instance representing the reader. + * @return true if there is an overlap in execution between writer and reader. + * @return false if there is no overlap in execution. + */ +bool crit(const TaskInstance& writerTask, const TaskInstance& readerTask); + #endif \ No newline at end of file diff --git a/source/MathFramework.cpp b/source/MathFramework.cpp index d54c2e8..7500a39 100644 --- a/source/MathFramework.cpp +++ b/source/MathFramework.cpp @@ -7,3 +7,13 @@ bool att(const TaskInstance& writerTask, const TaskInstance& readerTask) { return false; } + +bool crit(const TaskInstance& writerTask, const TaskInstance& readerTask) { + int writerTaskTerminationTime = writerTask.activationTime + writerTask.wcet; + + if(readerTask.activationTime < writerTaskTerminationTime) { + return true; + } + + return false; +} diff --git a/tests/MathFrameworkTests.cpp b/tests/MathFrameworkTests.cpp index 0d068cb..5829776 100644 --- a/tests/MathFrameworkTests.cpp +++ b/tests/MathFrameworkTests.cpp @@ -18,5 +18,25 @@ TEST(MathFramework, CanDetectWhenThereIsNoTimeTravel) { bool expected = false; bool actual = att(writerTask, readerTask); + EXPECT_EQ(expected, actual); +} + +TEST(MathFramework, CritFunctionCanDetectExecutionOverlap) { + const TaskInstance writerTask(10, 5); + const TaskInstance readerTask(12, 5); + + bool expected = true; + bool actual = crit(writerTask, readerTask); + + EXPECT_EQ(expected, actual); +} + +TEST(MathFramework, CritFunctionCanDetectWhenThereIsNoExecutionOverlap) { + const TaskInstance writerTask(10, 5); + const TaskInstance readerTask(16, 5); + + bool expected = false; + bool actual = crit(writerTask, readerTask); + EXPECT_EQ(expected, actual); } \ No newline at end of file