summaryrefslogtreecommitdiffstats
path: root/Source/CTest/cmProcess.cxx
diff options
context:
space:
mode:
authorWouter Klouwen <wouter.klouwen@youview.com>2017-11-20 20:55:13 (GMT)
committerBrad King <brad.king@kitware.com>2017-12-04 15:43:14 (GMT)
commit66419bc04620c5748df77e2b563d65b0e97b623a (patch)
tree0c6e38ba923c4eb95c3d5d829c83a849d58eb52a /Source/CTest/cmProcess.cxx
parent923b8fadd5fe6af56197cf3916a3292b60c0e8db (diff)
downloadCMake-66419bc04620c5748df77e2b563d65b0e97b623a.zip
CMake-66419bc04620c5748df77e2b563d65b0e97b623a.tar.gz
CMake-66419bc04620c5748df77e2b563d65b0e97b623a.tar.bz2
CTest: convert timeouts to std::chrono::duration
This commit continues the refactoring of CTest to adopt std::chrono. After the last sets of changes that introduced std::chrono::steady_clock and std::chrono::system_clock respectively, it makes sense to have all the timeouts be stored as std::chrono::duration. No functional change intended.
Diffstat (limited to 'Source/CTest/cmProcess.cxx')
-rw-r--r--Source/CTest/cmProcess.cxx38
1 files changed, 25 insertions, 13 deletions
diff --git a/Source/CTest/cmProcess.cxx b/Source/CTest/cmProcess.cxx
index c889174..69ffb33 100644
--- a/Source/CTest/cmProcess.cxx
+++ b/Source/CTest/cmProcess.cxx
@@ -5,11 +5,21 @@
#include "cmProcessOutput.h"
#include <iostream>
+void cmsysProcess_SetTimeout(cmsysProcess* process,
+ std::chrono::duration<double> timeout)
+{
+ cmsysProcess_SetTimeout(
+ process,
+ double(
+ std::chrono::duration_cast<std::chrono::milliseconds>(timeout).count()) /
+ 1000.0);
+};
+
cmProcess::cmProcess()
{
this->Process = nullptr;
- this->Timeout = 0;
- this->TotalTime = 0;
+ this->Timeout = std::chrono::duration<double>::zero();
+ this->TotalTime = std::chrono::duration<double>::zero();
this->ExitValue = 0;
this->Id = 0;
this->StartTime = std::chrono::steady_clock::time_point();
@@ -100,10 +110,15 @@ bool cmProcess::Buffer::GetLast(std::string& line)
return false;
}
-int cmProcess::GetNextOutputLine(std::string& line, double timeout)
+int cmProcess::GetNextOutputLine(std::string& line,
+ std::chrono::duration<double> timeout)
{
cmProcessOutput processOutput(cmProcessOutput::UTF8);
std::string strdata;
+ double waitTimeout =
+ double(
+ std::chrono::duration_cast<std::chrono::milliseconds>(timeout).count()) /
+ 1000.0;
for (;;) {
// Look for lines already buffered.
if (this->Output.GetLine(line)) {
@@ -113,7 +128,8 @@ int cmProcess::GetNextOutputLine(std::string& line, double timeout)
// Check for more data from the process.
char* data;
int length;
- int p = cmsysProcess_WaitForData(this->Process, &data, &length, &timeout);
+ int p =
+ cmsysProcess_WaitForData(this->Process, &data, &length, &waitTimeout);
if (p == cmsysProcess_Pipe_Timeout) {
return cmsysProcess_Pipe_Timeout;
}
@@ -136,23 +152,19 @@ int cmProcess::GetNextOutputLine(std::string& line, double timeout)
}
// No more data. Wait for process exit.
- if (!cmsysProcess_WaitForExit(this->Process, &timeout)) {
+ if (!cmsysProcess_WaitForExit(this->Process, &waitTimeout)) {
return cmsysProcess_Pipe_Timeout;
}
// Record exit information.
this->ExitValue = cmsysProcess_GetExitValue(this->Process);
- this->TotalTime =
- static_cast<double>(std::chrono::duration_cast<std::chrono::milliseconds>(
- std::chrono::steady_clock::now() - this->StartTime)
- .count()) /
- 1000.0;
+ this->TotalTime = std::chrono::steady_clock::now() - this->StartTime;
// Because of a processor clock scew the runtime may become slightly
// negative. If someone changed the system clock while the process was
// running this may be even more. Make sure not to report a negative
// duration here.
- if (this->TotalTime <= 0.0) {
- this->TotalTime = 0.0;
+ if (this->TotalTime <= std::chrono::duration<double>::zero()) {
+ this->TotalTime = std::chrono::duration<double>::zero();
}
// std::cerr << "Time to run: " << this->TotalTime << "\n";
return cmsysProcess_Pipe_None;
@@ -225,7 +237,7 @@ int cmProcess::ReportStatus()
return result;
}
-void cmProcess::ChangeTimeout(double t)
+void cmProcess::ChangeTimeout(std::chrono::duration<double> t)
{
this->Timeout = t;
cmsysProcess_SetTimeout(this->Process, this->Timeout);