Skip to content

Commit 7982a7f

Browse files
committed
fix per review #6 (1/2)
1 parent 16c7e62 commit 7982a7f

File tree

1 file changed

+18
-29
lines changed

1 file changed

+18
-29
lines changed

cores/esp8266/Schedule.cpp

Lines changed: 18 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,10 @@ struct scheduled_fn_t
1616
scheduled_fn_t(): callNow(esp8266::polledTimeout::periodicFastUs::alwaysExpired) { }
1717
};
1818

19-
static scheduled_fn_t* sFirst = 0;
20-
static scheduled_fn_t* sLast = 0;
19+
static scheduled_fn_t* sFirst = nullptr;
20+
static scheduled_fn_t* sLast = nullptr;
2121

22-
static scheduled_fn_t* sFirstUnused = 0;
23-
static scheduled_fn_t* sLastUnused = 0;
22+
static scheduled_fn_t* sUnused = nullptr;
2423

2524
static int sCount = 0;
2625

@@ -29,15 +28,13 @@ static scheduled_fn_t* get_fn_unsafe()
2928
{
3029
scheduled_fn_t* result = nullptr;
3130
// try to get an item from unused items list
32-
if (sFirstUnused)
31+
if (sUnused)
3332
{
34-
result = sFirstUnused;
35-
sFirstUnused = sFirstUnused->mNext;
36-
if (sFirstUnused == nullptr)
37-
sLastUnused = nullptr;
33+
result = sUnused;
34+
sUnused = sUnused->mNext;
3835
}
3936
// if no unused items, and count not too high, allocate a new one
40-
else if (sCount != SCHEDULED_FN_MAX_COUNT)
37+
else if (sCount < SCHEDULED_FN_MAX_COUNT)
4138
{
4239
result = new scheduled_fn_t;
4340
++sCount;
@@ -46,16 +43,11 @@ static scheduled_fn_t* get_fn_unsafe()
4643
return result;
4744
}
4845

49-
static void recycle_fn(scheduled_fn_t* fn)
46+
static void recycle_fn_unsafe(scheduled_fn_t* fn)
5047
{
51-
InterruptLock lockAllInterruptsInThisScope;
52-
53-
if (sLastUnused)
54-
sLastUnused->mNext = fn;
55-
else
56-
sFirstUnused = fn;
57-
fn->mNext = nullptr;
58-
sLastUnused = fn;
48+
fn->mFunc = mFuncT();
49+
fn->mNext = sUnused;
50+
sUnused = fn;
5951
}
6052

6153
IRAM_ATTR // called from ISR
@@ -110,16 +102,13 @@ void run_scheduled_functions()
110102
}
111103
else
112104
{
113-
{
114-
InterruptLock lockAllInterruptsInThisScope;
115-
if (sFirst == item)
116-
sFirst = sFirst->mNext;
117-
if (sLast == item)
118-
sLast = lastRecurring;
119-
}
120-
121-
item->mFunc = mFuncT();
122-
recycle_fn(item);
105+
InterruptLock lockAllInterruptsInThisScope;
106+
if (sFirst == item)
107+
sFirst = sFirst->mNext;
108+
if (sLast == item)
109+
sLast = lastRecurring;
110+
111+
recycle_fn_unsafe(item);
123112
}
124113
}
125114
}

0 commit comments

Comments
 (0)