diff options
| author | Fernando Sahmkow <fsahmkow27@gmail.com> | 2020-02-27 16:32:47 -0400 |
|---|---|---|
| committer | Fernando Sahmkow <fsahmkow27@gmail.com> | 2020-06-18 16:29:25 -0400 |
| commit | 1460bdc5ab1ed6e33c005b652635dc5626ffe9f3 (patch) | |
| tree | b2cdf3e5ac626e5c054c1df190b9371a11d2d694 /src/tests | |
| parent | a42b226559b3330edc5491a098a37953af537c95 (diff) | |
Common/Fiber: Implement Rewinding.
Diffstat (limited to 'src/tests')
| -rw-r--r-- | src/tests/common/fibers.cpp | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/src/tests/common/fibers.cpp b/src/tests/common/fibers.cpp index 0d3d5153d6..12536b6d88 100644 --- a/src/tests/common/fibers.cpp +++ b/src/tests/common/fibers.cpp @@ -309,4 +309,50 @@ TEST_CASE("Fibers::StartRace", "[common]") { REQUIRE(test_control.value3 == 1); } +class TestControl4; + +static void WorkControl4(void* control); + +class TestControl4 { +public: + TestControl4() { + fiber1 = std::make_shared<Fiber>(std::function<void(void*)>{WorkControl4}, this); + goal_reached = false; + rewinded = false; + } + + void Execute() { + thread_fiber = Fiber::ThreadToFiber(); + Fiber::YieldTo(thread_fiber, fiber1); + thread_fiber->Exit(); + } + + void DoWork() { + fiber1->SetRewindPoint(std::function<void(void*)>{WorkControl4}, this); + if (rewinded) { + goal_reached = true; + Fiber::YieldTo(fiber1, thread_fiber); + } + rewinded = true; + fiber1->Rewind(); + } + + std::shared_ptr<Common::Fiber> fiber1; + std::shared_ptr<Common::Fiber> thread_fiber; + bool goal_reached; + bool rewinded; +}; + +static void WorkControl4(void* control) { + auto* test_control = static_cast<TestControl4*>(control); + test_control->DoWork(); +} + +TEST_CASE("Fibers::Rewind", "[common]") { + TestControl4 test_control{}; + test_control.Execute(); + REQUIRE(test_control.goal_reached); + REQUIRE(test_control.rewinded); +} + } // namespace Common |
