summaryrefslogtreecommitdiffstats
path: root/src/tests/common/fibers.cpp
diff options
context:
space:
mode:
authorFernando Sahmkow <fsahmkow27@gmail.com>2020-02-27 21:32:47 +0100
committerFernando Sahmkow <fsahmkow27@gmail.com>2020-06-18 22:29:25 +0200
commit137d862d9b275209b3d62a413396a15e9e14b4b4 (patch)
treeb2cdf3e5ac626e5c054c1df190b9371a11d2d694 /src/tests/common/fibers.cpp
parentCommon/Fiber: Additional corrections to f_context. (diff)
downloadyuzu-137d862d9b275209b3d62a413396a15e9e14b4b4.tar
yuzu-137d862d9b275209b3d62a413396a15e9e14b4b4.tar.gz
yuzu-137d862d9b275209b3d62a413396a15e9e14b4b4.tar.bz2
yuzu-137d862d9b275209b3d62a413396a15e9e14b4b4.tar.lz
yuzu-137d862d9b275209b3d62a413396a15e9e14b4b4.tar.xz
yuzu-137d862d9b275209b3d62a413396a15e9e14b4b4.tar.zst
yuzu-137d862d9b275209b3d62a413396a15e9e14b4b4.zip
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]") {
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