diff src/os_win32.c @ 10279:c5c15c818bda v8.0.0036

commit https://github.com/vim/vim/commit/97792de2762cc79cc365a8a0b858f27753179577 Author: Bram Moolenaar <Bram@vim.org> Date: Sat Oct 15 18:36:49 2016 +0200 patch 8.0.0036 Problem: Detecting that a job has finished may take a while. Solution: Check for a finished job more often (Ozaki Kiichi)
author Christian Brabandt <cb@256bit.org>
date Sat, 15 Oct 2016 18:45:04 +0200
parents c036c0f636d5
children 179794481db4
line wrap: on
line diff
--- a/src/os_win32.c
+++ b/src/os_win32.c
@@ -4973,13 +4973,53 @@ mch_job_status(job_T *job)
     if (!GetExitCodeProcess(job->jv_proc_info.hProcess, &dwExitCode)
 	    || dwExitCode != STILL_ACTIVE)
     {
-	job->jv_status = JOB_ENDED;
 	job->jv_exitval = (int)dwExitCode;
+	if (job->jv_status != JOB_ENDED)
+	{
+	    ch_log(job->jv_channel, "Job ended");
+	    job->jv_status = JOB_ENDED;
+	}
 	return "dead";
     }
     return "run";
 }
 
+    job_T *
+mch_detect_ended_job(job_T *job_list)
+{
+    HANDLE jobHandles[MAXIMUM_WAIT_OBJECTS];
+    job_T *jobArray[MAXIMUM_WAIT_OBJECTS];
+    job_T *job = job_list;
+
+    while (job != NULL)
+    {
+	DWORD n;
+	DWORD result;
+
+	for (n = 0; n < MAXIMUM_WAIT_OBJECTS
+				       && job != NULL; job = job->jv_next)
+	{
+	    if (job->jv_status == JOB_STARTED)
+	    {
+		jobHandles[n] = job->jv_proc_info.hProcess;
+		jobArray[n] = job;
+		++n;
+	    }
+	}
+	if (n == 0)
+	    continue;
+	result = WaitForMultipleObjects(n, jobHandles, FALSE, 0);
+	if (result >= WAIT_OBJECT_0 && result < WAIT_OBJECT_0 + n)
+	{
+	    job_T *wait_job = jobArray[result - WAIT_OBJECT_0];
+
+	    if (STRCMP(mch_job_status(wait_job), "dead") == 0)
+		return wait_job;
+	}
+    }
+    return NULL;
+}
+
     int
 mch_stop_job(job_T *job, char_u *how)
 {