aboutsummaryrefslogtreecommitdiff
path: root/zencore/thread.cpp
diff options
context:
space:
mode:
authorStefan Boberg <[email protected]>2021-08-09 21:07:25 +0200
committerStefan Boberg <[email protected]>2021-08-09 21:07:25 +0200
commitdabba4b1e7b567e768204a7665bc75ade586a391 (patch)
treef8119489786b2c2754f58219cb832ac5d2c8a19e /zencore/thread.cpp
parentclang-format fixes (diff)
downloadzen-dabba4b1e7b567e768204a7665bc75ade586a391.tar.xz
zen-dabba4b1e7b567e768204a7665bc75ade586a391.zip
Added ProcessHandle::Reset and added some diagnostics for ProcessHandle::Initialize for the case when OpenProcess fails
Diffstat (limited to 'zencore/thread.cpp')
-rw-r--r--zencore/thread.cpp27
1 files changed, 21 insertions, 6 deletions
diff --git a/zencore/thread.cpp b/zencore/thread.cpp
index 9445682be..fa9da0258 100644
--- a/zencore/thread.cpp
+++ b/zencore/thread.cpp
@@ -2,6 +2,7 @@
#include <zencore/thread.h>
+#include <fmt/format.h>
#include <zencore/except.h>
#include <zencore/string.h>
#include <zencore/windows.h>
@@ -151,11 +152,7 @@ ProcessHandle::Initialize(void* ProcessHandle)
ProcessHandle::~ProcessHandle()
{
- if (IsValid())
- {
- CloseHandle(m_ProcessHandle);
- m_ProcessHandle = nullptr;
- }
+ Reset();
}
void
@@ -163,7 +160,15 @@ ProcessHandle::Initialize(int Pid)
{
ZEN_ASSERT(m_ProcessHandle == nullptr);
m_ProcessHandle = OpenProcess(PROCESS_QUERY_INFORMATION | SYNCHRONIZE, FALSE, Pid);
- m_Pid = Pid;
+
+ using namespace fmt::literals;
+
+ if (!m_ProcessHandle)
+ {
+ ThrowLastError("ProcessHandle::Initialize(pid: {}) failed"_format(Pid));
+ }
+
+ m_Pid = Pid;
}
bool
@@ -197,6 +202,16 @@ ProcessHandle::Terminate(int ExitCode)
}
}
+void
+ProcessHandle::Reset()
+{
+ if (IsValid())
+ {
+ CloseHandle(m_ProcessHandle);
+ m_ProcessHandle = nullptr;
+ }
+}
+
bool
ProcessHandle::Wait(int TimeoutMs)
{