修订版 | a8271af2f8913c1486fdf754cc13eb54e3ecf28f (tree) |
---|---|
时间 | 2020-11-22 21:17:24 |
作者 | Alexander Larin <scalar438@gmai...> |
Commiter | Alexander Larin |
Run async_checker
@@ -6,7 +6,7 @@ | ||
6 | 6 | { |
7 | 7 | |
8 | 8 | enum ProcessStatus; |
9 | -class ProcessExecuteParameters; | |
9 | +struct ProcessExecuteParameters; | |
10 | 10 | |
11 | 11 | namespace details |
12 | 12 | { |
@@ -31,9 +31,6 @@ | ||
31 | 31 | |
32 | 32 | [[nodiscard]] virtual bool is_abnormal_exit() const = 0; |
33 | 33 | |
34 | - // Start the process | |
35 | - virtual void start(const ProcessExecuteParameters &) = 0; | |
36 | - | |
37 | 34 | /// Peak memory usage, in bytes for the process |
38 | 35 | [[nodiscard]] virtual int peak_memory_usage() = 0; |
39 | 36 |
@@ -91,6 +91,12 @@ | ||
91 | 91 | // Сколько процессорного времени израсходовал процесс |
92 | 92 | int cpu_time() override; |
93 | 93 | |
94 | + bool is_abnormal_exit() const override | |
95 | + { | |
96 | + // FIXME: not implemented yet | |
97 | + return true; | |
98 | + } | |
99 | + | |
94 | 100 | void reset(); |
95 | 101 | |
96 | 102 | Limits getLimits() const; |
@@ -20,14 +20,19 @@ | ||
20 | 20 | // Platform-dependent process wrapper |
21 | 21 | std::unique_ptr<details::IProcess> process; |
22 | 22 | |
23 | + std::future<void> async_checker_fut; | |
24 | + | |
23 | 25 | ProcessExecuteParameters parameters; |
24 | 26 | }; |
25 | 27 | |
26 | 28 | checklib::Process::Process(ProcessExecuteParameters params) : pimpl(new Pimpl) |
27 | 29 | { |
28 | 30 | pimpl->parameters = std::move(params); |
29 | - pimpl->process = details::IProcess::create(); | |
30 | - pimpl->process->start(pimpl->parameters); | |
31 | + auto process = std::make_unique<details::RestrictedProcessImpl>(pimpl->parameters); | |
32 | + process->start(); | |
33 | + pimpl->process = std::move(process); | |
34 | + pimpl->async_checker_fut = | |
35 | + std::async(details::async_checker, pimpl->process.get(), pimpl->parameters.limits, nullptr); | |
31 | 36 | } |
32 | 37 | |
33 | 38 | checklib::Process::Process() : pimpl(new Pimpl) |
@@ -100,7 +105,7 @@ | ||
100 | 105 | // Запуск процесса |
101 | 106 | void checklib::Process::start() |
102 | 107 | { |
103 | - pimpl->process->start(pimpl->parameters); | |
108 | + // TODO: remove this method | |
104 | 109 | } |
105 | 110 | |
106 | 111 | // Завершает процесс вручную. Тип завершения становится etTerminated |