diff options
| author | Stefan Boberg <[email protected]> | 2021-08-09 21:07:25 +0200 |
|---|---|---|
| committer | Stefan Boberg <[email protected]> | 2021-08-09 21:07:25 +0200 |
| commit | dabba4b1e7b567e768204a7665bc75ade586a391 (patch) | |
| tree | f8119489786b2c2754f58219cb832ac5d2c8a19e /zencore/thread.cpp | |
| parent | clang-format fixes (diff) | |
| download | zen-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.cpp | 27 |
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) { |