summaryrefslogtreecommitdiff
path: root/src/common/fiber.h
diff options
context:
space:
mode:
authorGravatar Fernando Sahmkow2020-02-04 15:06:23 -0400
committerGravatar Fernando Sahmkow2020-06-18 16:29:14 -0400
commitbc266a9d98f38f6fd1006f1ca52bd57e6a7f37d3 (patch)
treebd18475a7b939fa4a9a23538b7e1359fb7f11792 /src/common/fiber.h
parentCommon: Implement a basic SpinLock class (diff)
downloadyuzu-bc266a9d98f38f6fd1006f1ca52bd57e6a7f37d3.tar.gz
yuzu-bc266a9d98f38f6fd1006f1ca52bd57e6a7f37d3.tar.xz
yuzu-bc266a9d98f38f6fd1006f1ca52bd57e6a7f37d3.zip
Common: Implement a basic Fiber class.
Diffstat (limited to 'src/common/fiber.h')
-rw-r--r--src/common/fiber.h55
1 files changed, 55 insertions, 0 deletions
diff --git a/src/common/fiber.h b/src/common/fiber.h
new file mode 100644
index 000000000..ab44905cf
--- /dev/null
+++ b/src/common/fiber.h
@@ -0,0 +1,55 @@
1// Copyright 2020 yuzu Emulator Project
2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included.
4
5#pragma once
6
7#include <functional>
8#include <memory>
9
10#include "common/common_types.h"
11#include "common/spin_lock.h"
12
13namespace Common {
14
15class Fiber {
16public:
17 Fiber(std::function<void(void*)>&& entry_point_func, void* start_parameter);
18 ~Fiber();
19
20 Fiber(const Fiber&) = delete;
21 Fiber& operator=(const Fiber&) = delete;
22
23 Fiber(Fiber&&) = default;
24 Fiber& operator=(Fiber&&) = default;
25
26 /// Yields control from Fiber 'from' to Fiber 'to'
27 /// Fiber 'from' must be the currently running fiber.
28 static void YieldTo(std::shared_ptr<Fiber> from, std::shared_ptr<Fiber> to);
29 static std::shared_ptr<Fiber> ThreadToFiber();
30
31 /// Only call from main thread's fiber
32 void Exit();
33
34 /// Used internally but required to be public, Shall not be used
35 void _start(void* parameter);
36
37 /// Changes the start parameter of the fiber. Has no effect if the fiber already started
38 void SetStartParameter(void* new_parameter) {
39 start_parameter = new_parameter;
40 }
41
42private:
43 Fiber();
44
45 struct FiberImpl;
46
47 SpinLock guard;
48 std::function<void(void*)> entry_point;
49 void* start_parameter;
50 std::shared_ptr<Fiber> previous_fiber;
51 std::unique_ptr<FiberImpl> impl;
52 bool is_thread_fiber{};
53};
54
55} // namespace Common