summaryrefslogtreecommitdiff
path: root/src/tests/common/fibers.cpp
diff options
context:
space:
mode:
authorGravatar Fernando Sahmkow2020-02-27 16:32:47 -0400
committerGravatar Fernando Sahmkow2020-06-18 16:29:25 -0400
commit137d862d9b275209b3d62a413396a15e9e14b4b4 (patch)
treeb2cdf3e5ac626e5c054c1df190b9371a11d2d694 /src/tests/common/fibers.cpp
parentCommon/Fiber: Additional corrections to f_context. (diff)
downloadyuzu-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.cpp46
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
312class TestControl4;
313
314static void WorkControl4(void* control);
315
316class TestControl4 {
317public:
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
346static void WorkControl4(void* control) {
347 auto* test_control = static_cast<TestControl4*>(control);
348 test_control->DoWork();
349}
350
351TEST_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