aboutsummaryrefslogtreecommitdiff
path: root/zencore/thread.cpp
diff options
context:
space:
mode:
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)
{