diff options
| author | 2020-02-27 16:32:47 -0400 | |
|---|---|---|
| committer | 2020-06-18 16:29:25 -0400 | |
| commit | 137d862d9b275209b3d62a413396a15e9e14b4b4 (patch) | |
| tree | b2cdf3e5ac626e5c054c1df190b9371a11d2d694 /src/tests/common/fibers.cpp | |
| parent | Common/Fiber: Additional corrections to f_context. (diff) | |
| download | yuzu-137d862d9b275209b3d62a413396a15e9e14b4b4.tar.gz yuzu-137d862d9b275209b3d62a413396a15e9e14b4b4.tar.xz yuzu-137d862d9b275209b3d62a413396a15e9e14b4b4.zip | |
Common/Fiber: Implement Rewinding.
Diffstat (limited to 'src/tests/common/fibers.cpp')
| -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 0d3d5153d..12536b6d8 100644 --- a/src/tests/common/fibers.cpp +++ b/src/tests/common/fibers.cpp | |||
| @@ -309,4 +309,50 @@ TEST_CASE("Fibers::StartRace", "[common]") { | |||
| 309 | REQUIRE(test_control.value3 == 1); | 309 | REQUIRE(test_control.value3 == 1); |
| 310 | } | 310 | } |
| 311 | 311 | ||
| 312 | class TestControl4; | ||
| 313 | |||
| 314 | static void WorkControl4(void* control); | ||
| 315 | |||
| 316 | class TestControl4 { | ||
| 317 | public: | ||
| 318 | TestControl4() { | ||
| 319 | fiber1 = std::make_shared<Fiber>(std::function<void(void*)>{WorkControl4}, this); | ||
| 320 | goal_reached = false; | ||
| 321 | rewinded = false; | ||
| 322 | } | ||
| 323 | |||
| 324 | void Execute() { | ||
| 325 | thread_fiber = Fiber::ThreadToFiber(); | ||
| 326 | Fiber::YieldTo(thread_fiber, fiber1); | ||
| 327 | thread_fiber->Exit(); | ||
| 328 | } | ||
| 329 | |||
| 330 | void DoWork() { | ||
| 331 | fiber1->SetRewindPoint(std::function<void(void*)>{WorkControl4}, this); | ||
| 332 | if (rewinded) { | ||
| 333 | goal_reached = true; | ||
| 334 | Fiber::YieldTo(fiber1, thread_fiber); | ||
| 335 | } | ||
| 336 | rewinded = true; | ||
| 337 | fiber1->Rewind(); | ||
| 338 | } | ||
| 339 | |||
| 340 | std::shared_ptr<Common::Fiber> fiber1; | ||
| 341 | std::shared_ptr<Common::Fiber> thread_fiber; | ||
| 342 | bool goal_reached; | ||
| 343 | bool rewinded; | ||
| 344 | }; | ||
| 345 | |||
| 346 | static void WorkControl4(void* control) { | ||
| 347 | auto* test_control = static_cast<TestControl4*>(control); | ||
| 348 | test_control->DoWork(); | ||
| 349 | } | ||
| 350 | |||
| 351 | TEST_CASE("Fibers::Rewind", "[common]") { | ||
| 352 | TestControl4 test_control{}; | ||
| 353 | test_control.Execute(); | ||
| 354 | REQUIRE(test_control.goal_reached); | ||
| 355 | REQUIRE(test_control.rewinded); | ||
| 356 | } | ||
| 357 | |||
| 312 | } // namespace Common | 358 | } // namespace Common |