Skip to content

Commit b9da2e0

Browse files
committed
Revert compute_scheduled_recurrent_grain
1 parent 521ae60 commit b9da2e0

File tree

3 files changed

+2
-53
lines changed

3 files changed

+2
-53
lines changed

cores/esp8266/Schedule.cpp

-35
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
*/
1818

1919
#include <assert.h>
20-
#include <numeric>
2120

2221
#include "Schedule.h"
2322
#include "PolledTimeout.h"
@@ -35,7 +34,6 @@ static scheduled_fn_t* sFirst = nullptr;
3534
static scheduled_fn_t* sLast = nullptr;
3635
static scheduled_fn_t* sUnused = nullptr;
3736
static int sCount = 0;
38-
static uint32_t recurrent_max_grain_mS = 0;
3937

4038
typedef std::function<bool(void)> mRecFuncT;
4139
struct recurrent_fn_t
@@ -132,39 +130,9 @@ bool schedule_recurrent_function_us(const std::function<bool(void)>& fn,
132130
}
133131
rLast = item;
134132

135-
// grain needs to be recomputed
136-
recurrent_max_grain_mS = 0;
137-
138133
return true;
139134
}
140135

141-
uint32_t compute_scheduled_recurrent_grain ()
142-
{
143-
if (recurrent_max_grain_mS == 0)
144-
{
145-
if (rFirst)
146-
{
147-
uint32_t recurrent_max_grain_uS = rFirst->callNow.getTimeout();
148-
for (auto it = rFirst->mNext; it; it = it->mNext)
149-
recurrent_max_grain_uS = std::gcd(recurrent_max_grain_uS, it->callNow.getTimeout());
150-
if (recurrent_max_grain_uS)
151-
// round to the upper millis
152-
recurrent_max_grain_mS = recurrent_max_grain_uS <= 1000? 1: (recurrent_max_grain_uS + 999) / 1000;
153-
}
154-
155-
#ifdef DEBUG_ESP_CORE
156-
static uint32_t last_grain = 0;
157-
if (recurrent_max_grain_mS != last_grain)
158-
{
159-
::printf(":rsf %u->%u\n", last_grain, recurrent_max_grain_mS);
160-
last_grain = recurrent_max_grain_mS;
161-
}
162-
#endif
163-
}
164-
165-
return recurrent_max_grain_mS;
166-
}
167-
168136
void run_scheduled_functions()
169137
{
170138
// prevent scheduling of new functions during this run
@@ -258,9 +226,6 @@ void run_scheduled_recurrent_functions()
258226
}
259227

260228
delete(to_ditch);
261-
262-
// grain needs to be recomputed
263-
recurrent_max_grain_mS = 0;
264229
}
265230
else
266231
{

cores/esp8266/Schedule.h

-5
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,6 @@
3939
// scheduled function happen more often: every yield() (vs every loop()),
4040
// and time resolution is microsecond (vs millisecond). Details are below.
4141

42-
// compute_scheduled_recurrent_grain() is used by delay() to give a chance to
43-
// all recurrent functions to run per their timing requirement.
44-
45-
uint32_t compute_scheduled_recurrent_grain ();
46-
4742
// scheduled functions called once:
4843
//
4944
// * internal queue is FIFO.

cores/esp8266/core_esp8266_main.cpp

+2-13
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,6 @@
2222

2323
//This may be used to change user task stack size:
2424
//#define CONT_STACKSIZE 4096
25-
26-
#include <numeric>
27-
2825
#include <Arduino.h>
2926
#include "Schedule.h"
3027
extern "C" {
@@ -170,16 +167,8 @@ bool esp_try_delay(const uint32_t start_ms, const uint32_t timeout_ms, const uin
170167
if (expired >= timeout_ms) {
171168
return true; // expired
172169
}
173-
174-
// compute greatest chunked delay with respect to scheduled recurrent functions
175-
uint32_t grain_ms = std::gcd(intvl_ms, compute_scheduled_recurrent_grain());
176-
177-
// recurrent scheduled functions will be called from esp_delay()->esp_suspend()
178-
esp_delay(grain_ms > 0 ?
179-
std::min((timeout_ms - expired), grain_ms):
180-
(timeout_ms - expired));
181-
182-
return false; // expiration must be checked again
170+
esp_delay(std::min((timeout_ms - expired), intvl_ms));
171+
return false;
183172
}
184173

185174
extern "C" void __yield() {

0 commit comments

Comments
 (0)