diff options
author | Mikhail Glushenkov <foldr@codedgers.com> | 2009-09-15 03:39:45 +0000 |
---|---|---|
committer | Mikhail Glushenkov <foldr@codedgers.com> | 2009-09-15 03:39:45 +0000 |
commit | 0adf07eb9e48e30bc2781ff4945845c599c1f1fc (patch) | |
tree | 28232705d1517d2aa5bb4ab82233e3c55ebd2872 /llvm/lib/System/Win32/Program.inc | |
parent | 3413f277d04f3d83c37023bb1babb6ed1875c113 (diff) | |
download | bcm5719-llvm-0adf07eb9e48e30bc2781ff4945845c599c1f1fc.tar.gz bcm5719-llvm-0adf07eb9e48e30bc2781ff4945845c599c1f1fc.zip |
Get rid of GetProcessId in Win32/Program.inc.
GetProcessId was introduced only in XP. As a bonus, this change makes Program
objects copyable, since Program is now basically a PID.
llvm-svn: 81826
Diffstat (limited to 'llvm/lib/System/Win32/Program.inc')
-rw-r--r-- | llvm/lib/System/Win32/Program.inc | 42 |
1 files changed, 17 insertions, 25 deletions
diff --git a/llvm/lib/System/Win32/Program.inc b/llvm/lib/System/Win32/Program.inc index af6cce6de1a..f1faff0ed11 100644 --- a/llvm/lib/System/Win32/Program.inc +++ b/llvm/lib/System/Win32/Program.inc @@ -25,21 +25,6 @@ namespace llvm { using namespace sys; -Program::Program() : Data_(0) {} - -Program::~Program() { - if (Data_) { - HANDLE hProcess = reinterpret_cast<HANDLE>(Data_); - CloseHandle(hProcess); - Data_ = 0; - } -} - -unsigned Program::GetPid() const { - HANDLE hProcess = reinterpret_cast<HANDLE>(Data_); - return GetProcessId(hProcess); -} - // This function just uses the PATH environment variable to find the program. Path Program::FindProgramByName(const std::string& progName) { @@ -137,11 +122,6 @@ Program::Execute(const Path& path, const Path** redirects, unsigned memoryLimit, std::string* ErrMsg) { - if (Data_) { - HANDLE hProcess = reinterpret_cast<HANDLE>(Data_); - CloseHandle(Data_); - Data_ = 0; - } if (!path.canExecute()) { if (ErrMsg) @@ -269,9 +249,10 @@ Program::Execute(const Path& path, path.str() + "'"); return false; } - Data_ = reinterpret_cast<void*>(pi.hProcess); + Pid_ = pi.dwProcessId; // Make sure these get closed no matter what. + AutoHandle hProcess(pi.hProcess); AutoHandle hThread(pi.hThread); // Assign the process to a job if a memory limit is defined. @@ -305,12 +286,17 @@ Program::Execute(const Path& path, int Program::Wait(unsigned secondsToWait, std::string* ErrMsg) { - if (Data_ == 0) { + if (Pid_ == 0) { MakeErrMsg(ErrMsg, "Process not started!"); return -1; } - HANDLE hProcess = reinterpret_cast<HANDLE>(Data_); + HANDLE hOpen = OpenProcess(SYNCHRONIZE, FALSE, Pid_); + if (hOpen == NULL) { + MakeErrMsg(ErrMsg, "OpenProcess failed!"); + return -1; + } + AutoHandle hProcess(hOpen); // Wait for the process to terminate. DWORD millisecondsToWait = INFINITE; @@ -341,12 +327,18 @@ Program::Wait(unsigned secondsToWait, bool Program::Kill(std::string* ErrMsg) { - if (Data_ == 0) { + if (Pid_ == 0) { MakeErrMsg(ErrMsg, "Process not started!"); return true; } - HANDLE hProcess = reinterpret_cast<HANDLE>(Data_); + HANDLE hOpen = OpenProcess(PROCESS_TERMINATE, FALSE, Pid_); + if (hOpen == NULL) { + MakeErrMsg(ErrMsg, "OpenProcess failed!"); + return true; + } + AutoHandle hProcess(hOpen); + if (TerminateProcess(hProcess, 1) == 0) { MakeErrMsg(ErrMsg, "The process couldn't be killed!"); return true; |