summaryrefslogtreecommitdiffstats
path: root/lldb
diff options
context:
space:
mode:
Diffstat (limited to 'lldb')
-rw-r--r--lldb/source/Host/macosx/Host.mm54
1 files changed, 33 insertions, 21 deletions
diff --git a/lldb/source/Host/macosx/Host.mm b/lldb/source/Host/macosx/Host.mm
index 7f559fd79b8..69d9d6ab3f7 100644
--- a/lldb/source/Host/macosx/Host.mm
+++ b/lldb/source/Host/macosx/Host.mm
@@ -1448,8 +1448,6 @@ Host::ShellExpandArguments (ProcessLaunchInfo &launch_info)
return error;
}
-#include <thread>
-
HostThread
Host::StartMonitoringChildProcess(Host::MonitorChildProcessCallback callback, void *callback_baton, lldb::pid_t pid, bool monitor_signals)
{
@@ -1460,20 +1458,30 @@ Host::StartMonitoringChildProcess(Host::MonitorChildProcessCallback callback, vo
Log *log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_HOST | LIBLLDB_LOG_PROCESS));
+ dispatch_source_t source = ::dispatch_source_create (DISPATCH_SOURCE_TYPE_PROC,
+ pid,
+ mask,
+ ::dispatch_get_global_queue (DISPATCH_QUEUE_PRIORITY_DEFAULT,0));
+
if (log)
- log->Printf ("Host::StartMonitoringChildProcess (callback=%p, baton=%p, pid=%i, monitor_signals=%i)\n",
- callback,
- callback_baton,
- (int)pid,
- monitor_signals);
-
- std::thread GrimReaper([callback, pid, log, callback_baton]() {
- int status= 0;
- int wait_pid = 0;
- bool cancel = false;
- bool exited = false;
- while(!exited)
- {
+ log->Printf ("Host::StartMonitoringChildProcess (callback=%p, baton=%p, pid=%i, monitor_signals=%i) source = %p\n",
+ callback,
+ callback_baton,
+ (int)pid,
+ monitor_signals,
+ source);
+
+ if (source)
+ {
+ ::dispatch_source_set_cancel_handler (source, ^{
+ ::dispatch_release (source);
+ });
+ ::dispatch_source_set_event_handler (source, ^{
+
+ int status= 0;
+ int wait_pid = 0;
+ bool cancel = false;
+ bool exited = false;
do
{
wait_pid = ::waitpid (pid, &status, 0);
@@ -1515,15 +1523,19 @@ Host::StartMonitoringChildProcess(Host::MonitorChildProcessCallback callback, vo
status_cstr,
signal,
exit_status);
-
+
if (callback)
cancel = callback (callback_baton, pid, exited, signal, exit_status);
+
+ if (exited || cancel)
+ {
+ ::dispatch_source_cancel(source);
+ }
}
- }
- });
-
- GrimReaper.detach();
-
+ });
+
+ ::dispatch_resume (source);
+ }
return HostThread();
}
OpenPOWER on IntegriCloud