@@ -63,38 +63,36 @@ bool HostProcessWindows::IsRunning() const {
63
63
return (code == STILL_ACTIVE);
64
64
}
65
65
66
+ static lldb::thread_result_t
67
+ MonitorThread (const Host::MonitorChildProcessCallback &callback,
68
+ HANDLE process_handle) {
69
+ DWORD exit_code;
70
+
71
+ ::WaitForSingleObject (process_handle, INFINITE);
72
+ ::GetExitCodeProcess (process_handle, &exit_code);
73
+ callback (::GetProcessId (process_handle), true , 0 , exit_code);
74
+ ::CloseHandle (process_handle);
75
+ return {};
76
+ }
77
+
66
78
llvm::Expected<HostThread> HostProcessWindows::StartMonitoring (
67
79
const Host::MonitorChildProcessCallback &callback, bool monitor_signals) {
68
- MonitorInfo *info = new MonitorInfo;
69
- info->callback = callback;
80
+ HANDLE process_handle;
70
81
71
82
// Since the life of this HostProcessWindows instance and the life of the
72
83
// process may be different, duplicate the handle so that the monitor thread
73
84
// can have ownership over its own copy of the handle.
74
85
if (::DuplicateHandle (GetCurrentProcess (), m_process, GetCurrentProcess (),
75
- &info->process_handle , 0 , FALSE , DUPLICATE_SAME_ACCESS)) {
76
- return ThreadLauncher::LaunchThread (" ChildProcessMonitor" ,
77
- HostProcessWindows::MonitorThread,
78
- info);
86
+ &process_handle, 0 , FALSE , DUPLICATE_SAME_ACCESS)) {
87
+ return ThreadLauncher::LaunchThread (
88
+ " ChildProcessMonitor" , [callback, process_handle] {
89
+ return MonitorThread (callback, process_handle);
90
+ });
79
91
} else {
80
92
return llvm::errorCodeToError (llvm::mapWindowsError (GetLastError ()));
81
93
}
82
94
}
83
95
84
- lldb::thread_result_t HostProcessWindows::MonitorThread (void *thread_arg) {
85
- DWORD exit_code;
86
-
87
- MonitorInfo *info = static_cast <MonitorInfo *>(thread_arg);
88
- if (info) {
89
- ::WaitForSingleObject (info->process_handle, INFINITE);
90
- ::GetExitCodeProcess (info->process_handle, &exit_code);
91
- info->callback (::GetProcessId (info->process_handle ), true , 0 , exit_code);
92
- ::CloseHandle (info->process_handle);
93
- delete (info);
94
- }
95
- return {};
96
- }
97
-
98
96
void HostProcessWindows::Close () {
99
97
if (m_owns_handle && m_process != LLDB_INVALID_PROCESS)
100
98
::CloseHandle (m_process);
0 commit comments