修订版 | 2a31e8a0640f732d292880d743ada02fdbf895be (tree) |
---|---|
时间 | 2021-02-07 20:43:08 |
作者 | Alexander Larin <scalar438@gmai...> |
Commiter | Alexander Larin |
Send status_sender into async checker
@@ -1,13 +1,11 @@ | ||
1 | 1 | #include "check_stats.hpp" |
2 | - | |
3 | -#include "process_events.hpp" | |
4 | 2 | #include "i_process.hpp" |
5 | 3 | #include "i_status_updater.hpp" |
6 | - | |
7 | -#include <atomic> | |
4 | +#include "process_events.hpp" | |
8 | 5 | |
9 | 6 | void checklib::details::async_checker(IProcess *process, Limits limits, |
10 | - IStatusUpdater *status_sender, std::shared_ptr<std::atomic_bool> force_exit) | |
7 | + IStatusUpdater *status_sender, | |
8 | + std::shared_ptr<std::atomic_bool> force_exit) | |
11 | 9 | { |
12 | 10 | constexpr int ms_delay = 100; |
13 | 11 | constexpr int idle_count_limit = 20; |
@@ -11,7 +11,7 @@ | ||
11 | 11 | class IStatusUpdater |
12 | 12 | { |
13 | 13 | public: |
14 | - virtual ~IStatusUpdater() = 0; | |
14 | + virtual ~IStatusUpdater() {} | |
15 | 15 | |
16 | 16 | virtual void set_status(ProcessStatus status) = 0; |
17 | 17 |
@@ -10,8 +10,26 @@ | ||
10 | 10 | #include "i_process.hpp" |
11 | 11 | #include "internal_watcher.hpp" |
12 | 12 | #include "process_execute_parameters.hpp" |
13 | +#include "i_status_updater.hpp" | |
14 | +#include <future> | |
13 | 15 | |
14 | -#include <future> | |
16 | +namespace | |
17 | +{ | |
18 | +struct Status final : public checklib::details::IStatusUpdater | |
19 | +{ | |
20 | + Status() { m_status = checklib::ProcessStatus::psNotRunning; } | |
21 | + | |
22 | + void set_status(checklib::ProcessStatus status) override { m_status = status; } | |
23 | + | |
24 | + void set_cpu_time(int cpu_time) override { m_cpu_time = cpu_time; } | |
25 | + | |
26 | + void set_peak_memory(int memory) override { m_peak_memory = memory; } | |
27 | + | |
28 | + std::atomic<int> m_cpu_time; | |
29 | + std::atomic<int> m_peak_memory; | |
30 | + std::atomic<checklib::ProcessStatus> m_status; | |
31 | +}; | |
32 | +} // namespace | |
15 | 33 | |
16 | 34 | struct checklib::Process::Pimpl |
17 | 35 | { |
@@ -27,6 +45,8 @@ | ||
27 | 45 | std::shared_ptr<std::atomic_bool> force_exit; |
28 | 46 | |
29 | 47 | ProcessExecuteParameters parameters; |
48 | + | |
49 | + Status m_status; | |
30 | 50 | }; |
31 | 51 | |
32 | 52 | checklib::Process::Process(ProcessExecuteParameters params) : pimpl(new Pimpl) |
@@ -37,7 +57,7 @@ | ||
37 | 57 | process->start(); |
38 | 58 | pimpl->process = std::move(process); |
39 | 59 | pimpl->async_checker_fut = std::async(details::async_checker, pimpl->process.get(), |
40 | - pimpl->parameters.limits, nullptr, pimpl->force_exit); | |
60 | + pimpl->parameters.limits, &pimpl->m_status, pimpl->force_exit); | |
41 | 61 | } |
42 | 62 | |
43 | 63 | checklib::Process::Process() : pimpl(new Pimpl) |
@@ -147,8 +167,7 @@ | ||
147 | 167 | // Тип завершения программы |
148 | 168 | checklib::ProcessStatus checklib::RestrictedProcess::processStatus() const |
149 | 169 | { |
150 | - // FIXME: this is temporal | |
151 | - return ProcessStatus::psTerminated;//pimpl->process->processStatus(); | |
170 | + return pimpl->m_status.m_status; | |
152 | 171 | } |
153 | 172 | |
154 | 173 | // Пиковое значение потребляемой памяти |
@@ -1,6 +1,6 @@ | ||
1 | 1 | #pragma once |
2 | 2 | |
3 | +#include "checklib/checklib_exception.h" | |
3 | 4 | #include "checklib/rp.h" |
4 | -#include "checklib/checklib_exception.h" | |
5 | 5 | #include "checklib/rp_consts.h" |
6 | 6 | #include "checklib/rp_types.h" |