Skip to content

Commit ce80535

Browse files
committed
[fiber] Reset stop token on fiber restart
1 parent 65ac765 commit ce80535

3 files changed

Lines changed: 13 additions & 0 deletions

File tree

src/modm/processing/fiber/stop_token.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,13 @@ class stop_state
5252
return not requested.exchange(true, std::memory_order_relaxed);
5353
}
5454

55+
/// @note This function can be called from an interrupt.
56+
void inline
57+
reset()
58+
{
59+
requested.store(false, std::memory_order_relaxed);
60+
}
61+
5562
constexpr stop_source
5663
get_source();
5764

src/modm/processing/fiber/task_impl.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ Task::start()
6767
{
6868
if (isRunning()) return false;
6969
modm_context_reset(&ctx);
70+
stop.reset();
7071
Scheduler::instance().add(this);
7172
return true;
7273
}

test/modm/processing/fiber/fiber_test.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,11 @@ FiberTest::testStopToken()
270270
TEST_ASSERT_EQUALS(state++, 6u);
271271
});
272272
modm::fiber::Scheduler::run();
273+
// repeat the same test exactly the same
274+
state = 0;
275+
fiber1.start();
276+
fiber2.start();
277+
modm::fiber::Scheduler::run();
273278
}
274279

275280
void

0 commit comments

Comments
 (0)