aboutsummaryrefslogtreecommitdiff
path: root/src/common/SubProcess.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/common/SubProcess.cpp')
-rw-r--r--src/common/SubProcess.cpp38
1 files changed, 18 insertions, 20 deletions
diff --git a/src/common/SubProcess.cpp b/src/common/SubProcess.cpp
index eea83acd..ae1c5375 100644
--- a/src/common/SubProcess.cpp
+++ b/src/common/SubProcess.cpp
@@ -5,7 +5,7 @@
namespace cru {
PlatformSubProcessBase::PlatformSubProcessBase(
- const PlatformSubProcessStartInfo& start_info)
+ const SubProcessStartInfo& start_info)
: start_info_(start_info), process_lock_(process_mutex_, std::defer_lock) {}
PlatformSubProcessBase::~PlatformSubProcessBase() {}
@@ -13,28 +13,28 @@ PlatformSubProcessBase::~PlatformSubProcessBase() {}
void PlatformSubProcessBase::Start() {
std::lock_guard lock_guard(process_lock_);
- if (status_ != PlatformSubProcessStatus::Prepare) {
+ if (status_ != SubProcessStatus::Prepare) {
throw SubProcessException(u"The process has already tried to start.");
}
try {
PlatformCreateProcess();
- status_ = PlatformSubProcessStatus::Running;
+ status_ = SubProcessStatus::Running;
process_thread_ = std::thread([this] {
auto exit_result = PlatformWaitForProcess();
{
std::lock_guard lock_guard(process_lock_);
exit_result_ = std::move(exit_result);
- status_ = PlatformSubProcessStatus::Exited;
+ status_ = SubProcessStatus::Exited;
}
this->process_condition_variable_.notify_all();
});
process_thread_.detach();
} catch (const std::exception& e) {
- status_ = PlatformSubProcessStatus::FailedToStart;
+ status_ = SubProcessStatus::FailedToStart;
throw SubProcessFailedToStartException(u"Sub-process failed to start. " +
String::FromUtf8(e.what()));
}
@@ -44,23 +44,21 @@ void PlatformSubProcessBase::Wait(
std::optional<std::chrono::milliseconds> wait_time) {
std::lock_guard lock_guard(process_lock_);
- if (status_ == PlatformSubProcessStatus::Prepare) {
+ if (status_ == SubProcessStatus::Prepare) {
throw SubProcessException(
u"The process does not start. Can't wait for it.");
}
- if (status_ == PlatformSubProcessStatus::FailedToStart) {
+ if (status_ == SubProcessStatus::FailedToStart) {
throw SubProcessException(
u"The process failed to start. Can't wait for it.");
}
- if (status_ == PlatformSubProcessStatus::Exited) {
+ if (status_ == SubProcessStatus::Exited) {
return;
}
- auto predicate = [this] {
- return status_ == PlatformSubProcessStatus::Exited;
- };
+ auto predicate = [this] { return status_ == SubProcessStatus::Exited; };
if (wait_time) {
process_condition_variable_.wait_for(process_lock_, *wait_time, predicate);
@@ -70,42 +68,42 @@ void PlatformSubProcessBase::Wait(
}
void PlatformSubProcessBase::Kill() {
- auto status = GetStatus();
+ std::lock_guard data_lock_guard(process_lock_);
- if (status == PlatformSubProcessStatus::Prepare) {
+ if (status_ == SubProcessStatus::Prepare) {
throw SubProcessException(u"The process does not start. Can't kill it.");
}
- if (status == PlatformSubProcessStatus::FailedToStart) {
+ if (status_ == SubProcessStatus::FailedToStart) {
throw SubProcessException(u"The process failed to start. Can't kill it.");
}
- if (status == PlatformSubProcessStatus::Exited) {
+ if (status_ == SubProcessStatus::Exited) {
return;
}
PlatformKillProcess();
}
-PlatformSubProcessStatus PlatformSubProcessBase::GetStatus() {
+SubProcessStatus PlatformSubProcessBase::GetStatus() {
std::lock_guard data_lock_guard(process_lock_);
return status_;
}
-PlatformSubProcessExitResult PlatformSubProcessBase::GetExitResult() {
+SubProcessExitResult PlatformSubProcessBase::GetExitResult() {
std::lock_guard lock_guard(process_lock_);
- if (status_ == PlatformSubProcessStatus::Prepare) {
+ if (status_ == SubProcessStatus::Prepare) {
throw SubProcessException(
u"The process does not start. Can't get exit result.");
}
- if (status_ == PlatformSubProcessStatus::FailedToStart) {
+ if (status_ == SubProcessStatus::FailedToStart) {
throw SubProcessException(
u"The process failed to start. Can't get exit result.");
}
- if (status_ == PlatformSubProcessStatus::Running) {
+ if (status_ == SubProcessStatus::Running) {
throw SubProcessException(
u"The process is running. Can't get exit result.");
}