Browse Source

v3.8.4 - git bugs 180,181,182

Anatoli Arkhipenko 2 years ago
parent
commit
4e31208dba

+ 1 - 1
README.md

@@ -1,6 +1,6 @@
 # Task Scheduler
 ### Cooperative multitasking for Arduino, ESPx, STM32 and other microcontrollers
-#### Version 3.8.3: 2023-09-29 [Latest updates](https://github.com/arkhipenko/TaskScheduler/wiki/Latest-Updates)
+#### Version 3.8.4: 2024-01-13 [Latest updates](https://github.com/arkhipenko/TaskScheduler/wiki/Latest-Updates)
 
 [![arduino-library-badge](https://www.ardu-badge.com/badge/TaskScheduler.svg?)](https://www.ardu-badge.com/TaskScheduler)[![xscode](https://img.shields.io/badge/Available%20on-xs%3Acode-blue?style=?style=plastic&logo=appveyor&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAMAAACdt4HsAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAAZQTFRF////////VXz1bAAAAAJ0Uk5T/wDltzBKAAAAlUlEQVR42uzXSwqAMAwE0Mn9L+3Ggtgkk35QwcnSJo9S+yGwM9DCooCbgn4YrJ4CIPUcQF7/XSBbx2TEz4sAZ2q1RAECBAiYBlCtvwN+KiYAlG7UDGj59MViT9hOwEqAhYCtAsUZvL6I6W8c2wcbd+LIWSCHSTeSAAECngN4xxIDSK9f4B9t377Wd7H5Nt7/Xz8eAgwAvesLRjYYPuUAAAAASUVORK5CYII=)](https://xscode.com/arkhipenko/TaskScheduler)
 

+ 10 - 1
examples/Scheduler_example19_Dynamic_Tasks_SelfDestruct/Scheduler_example19_Dynamic_Tasks_SelfDestruct.ino

@@ -4,6 +4,7 @@
       Main task runs every 100 milliseconds 100 times and in 50% cases generates a task object
       which runs 1 to 10 times with 100 ms to 5 s interval, and then destroyed.
       Self-destruct feature takes care of the task deletion after tasks complete
+      Last 5 tasks are deleted with disableAll() scheduler method as a test
 
       This sketch uses the following libraries:
        - FreeMemory library: https://github.com/McNeight/MemoryFree
@@ -47,6 +48,7 @@ bool OnEnable();
 void OnDisable();
 
 int noOfTasks = 0;
+long maxIterations = 0;
 
 void MainLoop() {
   Serial.print(millis()); Serial.print("\t");
@@ -58,6 +60,7 @@ void MainLoop() {
     // Generating another task
     long p = random(100, 5001); // from 100 ms to 5 seconds
     long j = random(1, 11); // from 1 to 10 iterations)
+    maxIterations = ( j > maxIterations ) ? j : maxIterations;
     Task *t = new Task(p, j, Iteration, &ts, false, OnEnable, OnDisable, true); // enable self-destruct
 
     Serial.print(F("Generated a new task:\t")); Serial.print(t->getId()); Serial.print(F("\tInt, Iter = \t"));
@@ -79,6 +82,11 @@ void Iteration() {
   Serial.print("Task N"); Serial.print(t.getId()); Serial.print(F("\tcurrent iteration: "));
   int i = t.getRunCounter();
   Serial.println(i);
+  
+  if (i >= maxIterations) {
+    t.disable();
+    maxIterations *= 2; // self-disable exactly one task
+  }
 }
 
 bool OnEnable() {
@@ -114,7 +122,8 @@ void setup() {
 
 void loop() {
   ts.execute();
-  if ( millis() > 5000 && noOfTasks == 0 ) {
+  if ( millis() > 5000 && noOfTasks <= 5 ) {
+      ts.disableAll();
       Serial.print(F("\tFree mem=")); Serial.println(freeMemory());
       while(1);
   }

+ 1 - 1
library.json

@@ -16,7 +16,7 @@
       "maintainer": true
     }
   ],
-  "version": "3.8.3",
+  "version": "3.8.4",
   "frameworks": "arduino",
   "platforms": "*"
 }

+ 1 - 1
library.properties

@@ -1,5 +1,5 @@
 name=TaskScheduler
-version=3.8.3
+version=3.8.4
 author=Anatoli Arkhipenko <arkhipenko@hotmail.com>
 maintainer=Anatoli Arkhipenko <arkhipenko@hotmail.com>
 sentence=Cooperative multitasking for Arduino, ESPx, STM32 and other microcontrollers.

+ 10 - 2
src/TaskScheduler.h

@@ -236,6 +236,11 @@ v3.8.3:
    2023-09-29 - feature: _TASK_TICKLESS - change in approach for backwards compatibility
               - feature: added scheduler stats for total/active/invoked tasks per each pass
 
+v3.8.4:
+   2024-01-13 - bug: (git issue #180): the variables tStart and tFinish are required if sleep support is enabled, 
+                independent of _TASK_TIMECRITICAL. however, they were guarded by _TASK_TIMECRITICAL as well.
+              - bug: (git issue #181): delete manually disable tasks with self-destruct flag
+              - bug: (git issue #182): correct deletion of self-destruct 'current' task in disableAll()
 */
 
 
@@ -1190,7 +1195,7 @@ void Scheduler::disableAll() {
         next = current->iNext;
         current->disable();
 #ifdef _TASK_SELF_DESTRUCT
-        if ( current->iStatus.sd_request ) delete iCurrent;
+        if ( current->iStatus.sd_request ) delete current;
 #endif  //  #ifdef _TASK_SELF_DESTRUCT
         current = next;
     }
@@ -1344,6 +1349,7 @@ bool Scheduler::execute() {
 #if defined(_TASK_TIMECRITICAL)
     unsigned long tPassStart;
     unsigned long tTaskStart, tTaskFinish;
+#endif  // _TASK_TIMECRITICAL
 
 #ifdef _TASK_SLEEP_ON_IDLE_RUN
     unsigned long tFinish;
@@ -1351,7 +1357,6 @@ bool Scheduler::execute() {
     unsigned long tIdleStart = 0;
 #endif  // _TASK_SLEEP_ON_IDLE_RUN
 
-#endif  // _TASK_TIMECRITICAL
 
     Task *nextTask;     // support for deleting the task in the onDisable method
     iCurrent = iFirst;
@@ -1547,6 +1552,9 @@ bool Scheduler::execute() {
 #endif  // _TASK_TIMECRITICAL
 
             }
+#ifdef _TASK_SELF_DESTRUCT
+            else if ( iCurrent->iStatus.sd_request ) delete iCurrent;
+#endif  //  #ifdef _TASK_SELF_DESTRUCT
         } while (0);    //guaranteed single run - allows use of "break" to exit
 
         iCurrent = nextTask;