@@ -16,11 +16,10 @@ struct scheduled_fn_t
16
16
scheduled_fn_t (): callNow(esp8266::polledTimeout::periodicFastUs::alwaysExpired) { }
17
17
};
18
18
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 ;
21
21
22
- static scheduled_fn_t * sFirstUnused = 0 ;
23
- static scheduled_fn_t * sLastUnused = 0 ;
22
+ static scheduled_fn_t * sUnused = nullptr ;
24
23
25
24
static int sCount = 0 ;
26
25
@@ -29,15 +28,13 @@ static scheduled_fn_t* get_fn_unsafe()
29
28
{
30
29
scheduled_fn_t * result = nullptr ;
31
30
// try to get an item from unused items list
32
- if (sFirstUnused )
31
+ if (sUnused )
33
32
{
34
- result = sFirstUnused ;
35
- sFirstUnused = sFirstUnused ->mNext ;
36
- if (sFirstUnused == nullptr )
37
- sLastUnused = nullptr ;
33
+ result = sUnused ;
34
+ sUnused = sUnused ->mNext ;
38
35
}
39
36
// 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)
41
38
{
42
39
result = new scheduled_fn_t ;
43
40
++sCount ;
@@ -46,16 +43,11 @@ static scheduled_fn_t* get_fn_unsafe()
46
43
return result;
47
44
}
48
45
49
- static void recycle_fn (scheduled_fn_t * fn)
46
+ static void recycle_fn_unsafe (scheduled_fn_t * fn)
50
47
{
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;
59
51
}
60
52
61
53
IRAM_ATTR // called from ISR
@@ -110,16 +102,13 @@ void run_scheduled_functions()
110
102
}
111
103
else
112
104
{
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);
123
112
}
124
113
}
125
114
}
0 commit comments