Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit207bc27

Browse files
committed
ISR safety.
1 parent03713a7 commit207bc27

File tree

1 file changed

+22
-14
lines changed

1 file changed

+22
-14
lines changed

‎cores/esp8266/Schedule.cpp‎

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -119,15 +119,15 @@ bool schedule_recurrent_function_us(const std::function<bool(void)>& fn,
119119
item->mFunc = fn;
120120
item->alarm = alarm;
121121

122+
esp8266::InterruptLock lockAllInterruptsInThisScope;
123+
122124
// prevent new item overwriting an already expired rTarget.
123-
constint32_trRemaining = rTarget -micros();
124-
if (!rFirst || (rRemaining >0 &&static_cast<uint32_t>(rRemaining) > item->callNow.remaining()))
125+
constint32_tremaining = rTarget -micros();
126+
if (!rFirst || (remaining >0 &&static_cast<uint32_t>(remaining) > item->callNow.remaining()))
125127
{
126128
rTarget =micros() + item->callNow.remaining();
127129
}
128130

129-
esp8266::InterruptLock lockAllInterruptsInThisScope;
130-
131131
if (rLast)
132132
{
133133
rLast->mNext = item;
@@ -145,8 +145,8 @@ uint32_t get_scheduled_recurrent_delay_us()
145145
{
146146
if (!rFirst)return ~static_cast<uint32_t>(0);
147147
// handle already expired rTarget.
148-
constint32_trRemaining = rTarget -micros();
149-
return (rRemaining >0) ?static_cast<uint32_t>(rRemaining) :0;
148+
constint32_tremaining = rTarget -micros();
149+
return (remaining >0) ?static_cast<uint32_t>(remaining) :0;
150150
}
151151

152152
voidrun_scheduled_functions()
@@ -209,12 +209,18 @@ void run_scheduled_recurrent_functions()
209209
fence =true;
210210
}
211211

212-
rTarget =micros() + current->callNow.remaining();
212+
decltype(rLast) stop;
213213
recurrent_fn_t* prev =nullptr;
214-
// prevent scheduling of new functions during this run
215-
auto stop = rLast;
216-
217214
bool done;
215+
216+
{
217+
esp8266::InterruptLock lockAllInterruptsInThisScope;
218+
219+
// prevent scheduling of new functions during this run
220+
stop = rLast;
221+
rTarget =micros() + (~static_cast<decltype(micros())>(0) >>1);
222+
}
223+
218224
do
219225
{
220226
done = current == stop;
@@ -246,14 +252,16 @@ void run_scheduled_recurrent_functions()
246252
}
247253
else
248254
{
249-
prev = current;
250-
current = current->mNext;
255+
esp8266::InterruptLock lockAllInterruptsInThisScope;
256+
251257
// prevent current item overwriting an already expired rTarget.
252-
constint32_trRemaining = rTarget -micros();
253-
if (rRemaining >0 &&static_cast<uint32_t>(rRemaining) > current->callNow.remaining())
258+
constint32_tremaining = rTarget -micros();
259+
if (remaining >0 &&static_cast<uint32_t>(remaining) > current->callNow.remaining())
254260
{
255261
rTarget =micros() + current->callNow.remaining();
256262
}
263+
prev = current;
264+
current = current->mNext;
257265
}
258266

259267
if (yieldNow)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp