|
15 | 15 | using namespace std::chrono_literals;
|
16 | 16 | using namespace SystematicTesting;
|
17 | 17 |
|
18 |
| -namespace |
| 18 | +template<typename ResultType> |
| 19 | +class ControlledTaskBase |
19 | 20 | {
|
20 |
| - template<typename ResultType> |
21 |
| - class ControlledTaskBase |
| 21 | +public: |
| 22 | + explicit ControlledTaskBase(std::function<ResultType()> func) : |
| 23 | + m_test_engine(GetTestEngine()), |
| 24 | + m_thread(), |
| 25 | + m_func(func), |
| 26 | + m_result(std::nullopt) |
22 | 27 | {
|
23 |
| - public: |
24 |
| - explicit ControlledTaskBase(std::function<ResultType()> func) : |
25 |
| - m_test_engine(GetTestEngine()), |
26 |
| - m_thread(), |
27 |
| - m_func(func), |
28 |
| - m_result(std::nullopt) |
29 |
| - { |
30 |
| - |
31 |
| - } |
| 28 | + |
| 29 | + } |
32 | 30 |
|
33 |
| - virtual ~ControlledTaskBase() |
| 31 | + virtual ~ControlledTaskBase() |
| 32 | + { |
| 33 | + if (m_thread->joinable()) |
34 | 34 | {
|
35 |
| - if (m_thread->joinable()) |
36 |
| - { |
37 |
| - m_thread->join(); |
38 |
| - } |
| 35 | + m_thread->join(); |
39 | 36 | }
|
| 37 | + } |
40 | 38 |
|
41 |
| - void start() |
| 39 | + void start() |
| 40 | + { |
| 41 | + size_t op_id = m_test_engine->create_next_operation().value(); |
| 42 | + m_thread = std::make_unique<std::thread>([this, op_id]() |
42 | 43 | {
|
43 |
| - size_t op_id = m_test_engine->create_next_operation().value(); |
44 |
| - m_thread = std::make_unique<std::thread>([this, op_id]() |
45 |
| - { |
46 |
| - m_test_engine->start_operation(op_id); |
47 |
| - execute(m_func, op_id); |
48 |
| - m_test_engine->complete_current_operation(); |
49 |
| - }); |
50 |
| - |
51 |
| - m_test_engine->schedule_next_operation(); |
52 |
| - } |
| 44 | + m_test_engine->start_operation(op_id); |
| 45 | + execute(m_func, op_id); |
| 46 | + m_test_engine->complete_current_operation(); |
| 47 | + }); |
53 | 48 |
|
54 |
| - void wait() |
55 |
| - { |
56 |
| - m_test_engine->pause_operation_until_condition([this]() { |
57 |
| - return m_result.has_value(); |
58 |
| - }); |
59 |
| - } |
| 49 | + m_test_engine->schedule_next_operation(); |
| 50 | + } |
| 51 | + |
| 52 | + void wait() |
| 53 | + { |
| 54 | + m_test_engine->pause_operation_until_condition([this]() { |
| 55 | + return m_result.has_value(); |
| 56 | + }); |
| 57 | + } |
60 | 58 |
|
61 |
| - protected: |
62 |
| - std::optional<std::any> m_result; |
| 59 | +protected: |
| 60 | + std::optional<std::any> m_result; |
63 | 61 |
|
64 |
| - virtual void execute(std::function<ResultType()>& func, size_t op_id) = 0; |
| 62 | + virtual void execute(std::function<ResultType()>& func, size_t op_id) = 0; |
65 | 63 |
|
66 |
| - private: |
67 |
| - TestEngine* m_test_engine; |
68 |
| - std::unique_ptr<std::thread> m_thread; |
69 |
| - std::function<ResultType()> m_func; |
70 |
| - }; |
71 |
| -} |
| 64 | +private: |
| 65 | + TestEngine* m_test_engine; |
| 66 | + std::unique_ptr<std::thread> m_thread; |
| 67 | + std::function<ResultType()> m_func; |
| 68 | +}; |
72 | 69 |
|
73 | 70 | template<typename ResultType>
|
74 | 71 | class ControlledTask final : public ControlledTaskBase<ResultType>
|
|
0 commit comments