• R/O
  • SSH

提交

标签
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Commit MetaInfo

修订版2a31e8a0640f732d292880d743ada02fdbf895be (tree)
时间2021-02-07 20:43:08
作者Alexander Larin <scalar438@gmai...>
CommiterAlexander Larin

Log Message

Send status_sender into async checker

更改概述

差异

diff -r 29c07966e40a -r 2a31e8a0640f libs/checklib/impl/check_stats.cpp
--- a/libs/checklib/impl/check_stats.cpp Sat Feb 06 22:01:54 2021 +0300
+++ b/libs/checklib/impl/check_stats.cpp Sun Feb 07 14:43:08 2021 +0300
@@ -1,13 +1,11 @@
11 #include "check_stats.hpp"
2-
3-#include "process_events.hpp"
42 #include "i_process.hpp"
53 #include "i_status_updater.hpp"
6-
7-#include <atomic>
4+#include "process_events.hpp"
85
96 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)
119 {
1210 constexpr int ms_delay = 100;
1311 constexpr int idle_count_limit = 20;
diff -r 29c07966e40a -r 2a31e8a0640f libs/checklib/impl/i_status_updater.hpp
--- a/libs/checklib/impl/i_status_updater.hpp Sat Feb 06 22:01:54 2021 +0300
+++ b/libs/checklib/impl/i_status_updater.hpp Sun Feb 07 14:43:08 2021 +0300
@@ -11,7 +11,7 @@
1111 class IStatusUpdater
1212 {
1313 public:
14- virtual ~IStatusUpdater() = 0;
14+ virtual ~IStatusUpdater() {}
1515
1616 virtual void set_status(ProcessStatus status) = 0;
1717
diff -r 29c07966e40a -r 2a31e8a0640f libs/checklib/impl/process.cpp
--- a/libs/checklib/impl/process.cpp Sat Feb 06 22:01:54 2021 +0300
+++ b/libs/checklib/impl/process.cpp Sun Feb 07 14:43:08 2021 +0300
@@ -10,8 +10,26 @@
1010 #include "i_process.hpp"
1111 #include "internal_watcher.hpp"
1212 #include "process_execute_parameters.hpp"
13+#include "i_status_updater.hpp"
14+#include <future>
1315
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
1533
1634 struct checklib::Process::Pimpl
1735 {
@@ -27,6 +45,8 @@
2745 std::shared_ptr<std::atomic_bool> force_exit;
2846
2947 ProcessExecuteParameters parameters;
48+
49+ Status m_status;
3050 };
3151
3252 checklib::Process::Process(ProcessExecuteParameters params) : pimpl(new Pimpl)
@@ -37,7 +57,7 @@
3757 process->start();
3858 pimpl->process = std::move(process);
3959 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);
4161 }
4262
4363 checklib::Process::Process() : pimpl(new Pimpl)
@@ -147,8 +167,7 @@
147167 // Тип завершения программы
148168 checklib::ProcessStatus checklib::RestrictedProcess::processStatus() const
149169 {
150- // FIXME: this is temporal
151- return ProcessStatus::psTerminated;//pimpl->process->processStatus();
170+ return pimpl->m_status.m_status;
152171 }
153172
154173 // Пиковое значение потребляемой памяти
diff -r 29c07966e40a -r 2a31e8a0640f libs/checklib/include/checklib/checklib.h
--- a/libs/checklib/include/checklib/checklib.h Sat Feb 06 22:01:54 2021 +0300
+++ b/libs/checklib/include/checklib/checklib.h Sun Feb 07 14:43:08 2021 +0300
@@ -1,6 +1,6 @@
11 #pragma once
22
3+#include "checklib/checklib_exception.h"
34 #include "checklib/rp.h"
4-#include "checklib/checklib_exception.h"
55 #include "checklib/rp_consts.h"
66 #include "checklib/rp_types.h"