@@ -36,15 +36,26 @@ namespace modm::fiber
36
36
*/
37
37
class Scheduler
38
38
{
39
+ public:
40
+ /// Scheduling options
41
+ enum
42
+ Options : uint8_t
43
+ {
44
+ /// On every fiber start, watermark the fiber stack
45
+ AutoWatermark = 0b1,
46
+ };
47
+
48
+ protected:
49
+ /// @cond
39
50
friend class Task;
40
51
friend void modm::this_fiber::yield();
41
52
friend modm::fiber::id modm::this_fiber::get_id();
42
53
Scheduler(const Scheduler&) = delete;
43
54
Scheduler& operator=(const Scheduler&) = delete;
44
55
45
- protected:
46
56
Task* last{nullptr};
47
57
Task* current{nullptr};
58
+ Options options{0};
48
59
49
60
uintptr_t inline
50
61
get_id() const
@@ -136,6 +147,9 @@ protected:
136
147
void inline
137
148
add(Task* task)
138
149
{
150
+ if (options & Options::AutoWatermark) {
151
+ task->stack_watermark();
152
+ }
139
153
task->scheduler = this;
140
154
if (last == nullptr)
141
155
{
@@ -147,10 +161,17 @@ protected:
147
161
}
148
162
149
163
bool inline
150
- start()
164
+ start(Options options )
151
165
{
166
+ this->options = options;
152
167
if (empty()) return false;
153
168
current = last->next;
169
+ if (options & Options::AutoWatermark) {
170
+ do {
171
+ current->stack_watermark();
172
+ current = current->next;
173
+ } while (current != last->next);
174
+ }
154
175
%% if with_psplim
155
176
modm_context_start(¤t->ctx);
156
177
%% else
@@ -159,6 +180,7 @@ protected:
159
180
%% endif
160
181
return true;
161
182
}
183
+ /// @endcond
162
184
163
185
protected:
164
186
/// Returns the currently active scheduler.
@@ -187,9 +209,9 @@ public:
187
209
188
210
/// Runs the currently active scheduler.
189
211
static inline void
190
- run()
212
+ run(Options options = Options(0) )
191
213
{
192
- instance().start();
214
+ instance().start(options );
193
215
}
194
216
};
195
217
0 commit comments