Skip to content

Commit e54eaf2

Browse files
committed
Fixed uint32_t overflow timing bug
1 parent 44f65da commit e54eaf2

7 files changed

Lines changed: 9 additions & 5 deletions

File tree

src/ProcessScheduler.h

100644100755
File mode changed.

src/ProcessScheduler/Config.h

100644100755
File mode changed.

src/ProcessScheduler/Includes.h

100644100755
File mode changed.

src/ProcessScheduler/Process.cpp

100644100755
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,9 @@
5959

6060
bool Process::needsServicing(uint32_t start)
6161
{
62-
return (isEnabled() && (_force ||
63-
((getPeriod() == SERVICE_CONSTANTLY || start - getScheduledTS() >= getPeriod()) &&
62+
return (isEnabled() &&
63+
(_force ||
64+
((getPeriod() == SERVICE_CONSTANTLY || timeToNextRun(start) <= 0) &&
6465
(getIterations() == RUNTIME_FOREVER || getIterations() > 0))));
6566
}
6667

src/ProcessScheduler/Process.h

100644100755
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,9 @@ class Process
8484
*
8585
* @return: int32_t time offset
8686
*/
87-
inline int32_t timeToNextRun() { return (_scheduledTS + _period) - _scheduler.getCurrTS(); }
87+
inline int32_t timeToNextRun() { return timeToNextRun(_scheduler.getCurrTS()); }
88+
89+
inline int32_t timeToNextRun(uint32_t curr) { return (int32_t)((_scheduledTS + _period) - curr); }
8890

8991

9092
/*

src/ProcessScheduler/Scheduler.cpp

100644100755
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ uint8_t Scheduler::countProcesses(int priority, bool enabledOnly)
133133
return count;
134134
}
135135

136+
136137
int Scheduler::run()
137138
{
138139
// Already running in another call frame
@@ -157,7 +158,7 @@ int Scheduler::run()
157158
while(tmp) {
158159
if (tmp->needsServicing(start)) {
159160
if (torun) { //Compare which one needs to run more
160-
_active = Process::runWhich(torun, tmp);
161+
torun = Process::runWhich(torun, tmp);
161162
} else { //torun is NULL so this is the best one to run
162163
torun = tmp;
163164
}
@@ -213,7 +214,7 @@ int Scheduler::run()
213214
disable(*_active);
214215
}
215216
_active = NULL; //done!
216-
217+
217218
count++; // incr counter
218219
processQueue();
219220
delay(0); // For esp8266

src/ProcessScheduler/Scheduler.h

100644100755
File mode changed.

0 commit comments

Comments
 (0)