This repository was archived by the owner on Aug 8, 2023. It is now read-only.
Commit aaab24c 1 parent dc57cc2 commit aaab24c Copy full SHA for aaab24c
File tree 2 files changed +23
-18
lines changed
2 files changed +23
-18
lines changed Original file line number Diff line number Diff line change 9
9
#include < mbgl/util/run_loop.hpp>
10
10
#include < mbgl/util/thread_context.hpp>
11
11
#include < mbgl/util/platform.hpp>
12
+ #include < mbgl/util/util.hpp>
12
13
13
14
#include < cassert>
14
15
@@ -57,6 +58,8 @@ class Thread {
57
58
}
58
59
59
60
void pause () {
61
+ MBGL_VERIFY_THREAD (tid);
62
+
60
63
assert (!paused);
61
64
62
65
paused = std::make_unique<std::promise<void >>();
@@ -74,6 +77,8 @@ class Thread {
74
77
}
75
78
76
79
void resume () {
80
+ MBGL_VERIFY_THREAD (tid);
81
+
77
82
assert (paused);
78
83
79
84
resumed->set_value ();
@@ -83,6 +88,8 @@ class Thread {
83
88
}
84
89
85
90
private:
91
+ MBGL_STORE_THREAD (tid);
92
+
86
93
Thread (const Thread&) = delete ;
87
94
Thread (Thread&&) = delete ;
88
95
Thread& operator =(const Thread&) = delete ;
Original file line number Diff line number Diff line change @@ -129,32 +129,30 @@ TEST(Thread, context) {
129
129
loop.run ();
130
130
}
131
131
132
- TEST (Thread, pause ) {
132
+ TEST (Thread, PauseThenResume ) {
133
133
const std::thread::id tid = std::this_thread::get_id ();
134
134
135
- RunLoop loop ;
135
+ RunLoop loop1 ;
136
136
std::vector<std::unique_ptr<mbgl::AsyncRequest>> requests;
137
137
138
- Thread<TestObject> thread ({" Test " }, tid);
139
- Thread<TestObject> unpausedThread ({" UnpausedTest " }, tid);
138
+ Thread<TestObject> thread1 ({" Test1 " }, tid);
139
+ Thread<TestObject> thread2 ({" Test2 " }, tid);
140
140
141
- loop.invoke ([&] {
142
- thread.pause ();
141
+ thread1.pause ();
143
142
144
- requests.push_back (thread .invokeWithCallback (&TestObject::fn2, [&] (int result) {
145
- EXPECT_EQ (tid, std::this_thread::get_id ());
146
- EXPECT_EQ (result, 1 );
147
- loop .stop ();
148
- }));
143
+ requests.push_back (thread1 .invokeWithCallback (&TestObject::fn2, [&] (int result) {
144
+ EXPECT_EQ (tid, std::this_thread::get_id ());
145
+ EXPECT_EQ (result, 1 );
146
+ loop1 .stop ();
147
+ }));
149
148
150
- requests.push_back (unpausedThread.invokeWithCallback (&TestObject::transferOut, [&] (std::unique_ptr<int > result) {
151
- EXPECT_EQ (tid, std::this_thread::get_id ());
152
- EXPECT_EQ (*result, 1 );
153
- thread.resume ();
154
- }));
155
- });
149
+ requests.push_back (thread2.invokeWithCallback (&TestObject::transferOut, [&] (std::unique_ptr<int > result) {
150
+ EXPECT_EQ (tid, std::this_thread::get_id ());
151
+ EXPECT_EQ (*result, 1 );
152
+ thread1.resume ();
153
+ }));
156
154
157
- loop .run ();
155
+ loop1 .run ();
158
156
}
159
157
160
158
class TestWorker {
You can’t perform that action at this time.
0 commit comments