From d3f58c88db7a13510b018d4a714d3bd3e9adefff Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Niccol=C3=B2=20Betto?= <niccolo.betto@skywarder.eu>
Date: Wed, 28 Dec 2022 16:28:24 +0100
Subject: [PATCH] [TaskScheduler] Remove the ability to remove task after the
 scheduler had started

---
 src/shared/scheduler/TaskScheduler.cpp     | 20 --------------------
 src/shared/scheduler/TaskScheduler.h       |  8 --------
 src/tests/scheduler/test-taskscheduler.cpp |  2 --
 3 files changed, 30 deletions(-)

diff --git a/src/shared/scheduler/TaskScheduler.cpp b/src/shared/scheduler/TaskScheduler.cpp
index b92b9a642..c236dcc5d 100644
--- a/src/shared/scheduler/TaskScheduler.cpp
+++ b/src/shared/scheduler/TaskScheduler.cpp
@@ -87,26 +87,6 @@ size_t TaskScheduler::addTask(function_t function, uint32_t period,
     return id;
 }
 
-bool TaskScheduler::removeTask(size_t id)
-{
-    Lock<FastMutex> lock(mutex);
-
-    // Check if the task is actually present
-    if ((*tasks)[id].valid == false)
-    {
-        // Unlock the mutex for expensive operation
-        Unlock<FastMutex> unlock(mutex);
-
-        LOG_ERR(logger, "Attempting to remove a task not registered");
-        return false;
-    }
-
-    // Set the validity of the task to false
-    (*tasks)[id].valid = false;
-
-    return true;
-}
-
 bool TaskScheduler::start()
 {
     // This check is necessary to prevent task normalization if the scheduler is
diff --git a/src/shared/scheduler/TaskScheduler.h b/src/shared/scheduler/TaskScheduler.h
index cca462797..0130a6dee 100644
--- a/src/shared/scheduler/TaskScheduler.h
+++ b/src/shared/scheduler/TaskScheduler.h
@@ -119,14 +119,6 @@ public:
                    Policy policy     = Policy::SKIP,
                    int64_t startTick = miosix::getTick());
 
-    /**
-     * @brief Removes the task identified by the given id if it exists.
-     *
-     * @param id Id of the task to remove.
-     * @return true if the task was removed.
-     */
-    bool removeTask(size_t id);
-
     bool start() override;
 
     void stop() override;
diff --git a/src/tests/scheduler/test-taskscheduler.cpp b/src/tests/scheduler/test-taskscheduler.cpp
index b7501d468..1ac40adbd 100644
--- a/src/tests/scheduler/test-taskscheduler.cpp
+++ b/src/tests/scheduler/test-taskscheduler.cpp
@@ -112,8 +112,6 @@ int main()
     Thread::sleep(4 * 1000);
 
     signalPin5();
-    scheduler.removeTask(1);
-    scheduler.removeTask(3);
     printf("Removed tasks 1 (2Hz) and 3 (500Hz)\n");
 
     Thread::sleep(4 * 1000);
-- 
GitLab