File tree 1 file changed +83
-0
lines changed
1 file changed +83
-0
lines changed Original file line number Diff line number Diff line change
1
+ #ifndef RBX_THREAD_PHASE_HPP
2
+ #define RBX_THREAD_PHASE_HPP
3
+
4
+ #include " defines.hpp"
5
+ #include " vm.hpp"
6
+ #include " state.hpp"
7
+ #include " thread_nexus.hpp"
8
+
9
+ namespace rubinius {
10
+ /* *
11
+ * Instantiation of an instance of this class causes Ruby execution on all
12
+ * threads to be suspended. Upon destruction of the instance, Ruby execution
13
+ * is resumed.
14
+ */
15
+ class LockPhase {
16
+ State* state_;
17
+
18
+ public:
19
+ LockPhase (STATE)
20
+ : state_(state)
21
+ {
22
+ state->shared ().thread_nexus ()->lock_or_wait (state->vm ());
23
+ }
24
+
25
+ ~LockPhase () {
26
+ state_->shared ().thread_nexus ()->unlock ();
27
+ }
28
+ };
29
+
30
+ class ManagedPhase {
31
+ State* state_;
32
+
33
+ public:
34
+ ManagedPhase (STATE)
35
+ : state_(state)
36
+ {
37
+ state_->vm ()->become_managed ();
38
+ }
39
+
40
+ ~ManagedPhase () {
41
+ state_->vm ()->become_unmanaged ();
42
+ }
43
+
44
+ };
45
+
46
+ class UnmanagedPhase {
47
+ State* state_;
48
+
49
+ public:
50
+ UnmanagedPhase (STATE)
51
+ : state_(state)
52
+ {
53
+ state_->vm ()->become_unmanaged ();
54
+ }
55
+
56
+ ~UnmanagedPhase () {
57
+ state_->vm ()->become_managed ();
58
+ }
59
+ };
60
+
61
+ template <class T >
62
+ class LockUnmanaged : public utilities ::thread::LockGuardTemplate<T> {
63
+ State* state_;
64
+
65
+ public:
66
+ LockUnmanaged (STATE, T& in_lock)
67
+ : utilities::thread::LockGuardTemplate<T>(in_lock, false )
68
+ , state_(state)
69
+ {
70
+ state_->vm ()->become_unmanaged ();
71
+ this ->lock ();
72
+ state_->vm ()->become_managed ();
73
+ }
74
+
75
+ ~LockUnmanaged () {
76
+ this ->unlock ();
77
+ }
78
+ };
79
+
80
+ typedef LockUnmanaged<utilities::thread::Mutex> MutexLockUnmanaged;
81
+ }
82
+
83
+ #endif
You can’t perform that action at this time.
0 commit comments