From 570243b5d92cc2584f0bf7bc4e506725af143f3c Mon Sep 17 00:00:00 2001 From: Stephen Wilson Date: Wed, 19 Jan 2011 01:37:06 +0000 Subject: [PATCH] Delay sync with the parent thread in ProcessLinux/ProcessMonitor. This patch removes a potential race condition between a process monitor thread and its parent waiting to interrogate the success/failure of the launch. llvm-svn: 123803 --- lldb/source/Plugins/Process/Linux/ProcessMonitor.cpp | 11 +++++++---- lldb/source/Plugins/Process/Linux/ProcessMonitor.h | 2 +- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/lldb/source/Plugins/Process/Linux/ProcessMonitor.cpp b/lldb/source/Plugins/Process/Linux/ProcessMonitor.cpp index 8fe74511108c..2c936386baa6 100644 --- a/lldb/source/Plugins/Process/Linux/ProcessMonitor.cpp +++ b/lldb/source/Plugins/Process/Linux/ProcessMonitor.cpp @@ -607,7 +607,7 @@ ProcessMonitor::OperationThread(void *arg) if (!Launch(args)) return NULL; - ServeOperation(args->m_monitor); + ServeOperation(args); return NULL; } @@ -716,8 +716,6 @@ ProcessMonitor::Launch(LaunchArgs *args) process.SendMessage(ProcessMessage::Trace(pid)); FINISH: - // Sync with our parent thread now that the launch operation is complete. - sem_post(&args->m_semaphore); return args->m_error.Success(); } @@ -819,15 +817,20 @@ ProcessMonitor::MonitorSIGTRAP(ProcessMonitor *monitor, lldb::pid_t pid) } void -ProcessMonitor::ServeOperation(ProcessMonitor *monitor) +ProcessMonitor::ServeOperation(LaunchArgs *args) { int status; pollfd fdset; + ProcessMonitor *monitor = args->m_monitor; fdset.fd = monitor->m_server_fd; fdset.events = POLLIN | POLLPRI; fdset.revents = 0; + // We are finised with the arguments and are ready to go. Sync with the + // parent thread and start serving operations on the inferior. + sem_post(&args->m_semaphore); + for (;;) { if ((status = poll(&fdset, 1, -1)) < 0) diff --git a/lldb/source/Plugins/Process/Linux/ProcessMonitor.h b/lldb/source/Plugins/Process/Linux/ProcessMonitor.h index 86aad235f0b4..c0160199652a 100644 --- a/lldb/source/Plugins/Process/Linux/ProcessMonitor.h +++ b/lldb/source/Plugins/Process/Linux/ProcessMonitor.h @@ -197,7 +197,7 @@ private: EnableIPC(); static void - ServeOperation(ProcessMonitor *monitor); + ServeOperation(LaunchArgs *args); static bool DupDescriptor(const char *path, int fd, int flags);