adaint.c (remove_handle): New local routine without a lock.

2014-11-20  Pascal Obry  <obry@adacore.com>

	* adaint.c (remove_handle): New local routine without a lock.
	(win32_wait): fix the critical section to properly protect needed
	code, use new remove_handle.
	(__gnat_win32_remove_handle): refactor code with remove_handle.

From-SVN: r217832
This commit is contained in:
Pascal Obry 2014-11-20 10:47:11 +00:00 committed by Arnaud Charlet
parent 04e9213da7
commit 6654786e8f
2 changed files with 25 additions and 13 deletions

View File

@ -1,3 +1,10 @@
2014-11-20 Pascal Obry <obry@adacore.com>
* adaint.c (remove_handle): New local routine without a lock.
(win32_wait): fix the critical section to properly protect needed
code, use new remove_handle.
(__gnat_win32_remove_handle): refactor code with remove_handle.
2014-11-20 Eric Botcazou <ebotcazou@adacore.com>
* inline.adb (Analyze_Inlined_Bodies): Iterate between loading

View File

@ -2334,7 +2334,6 @@ static int *PID_LIST = NULL, plist_length = 0, plist_max_length = 0;
static void
add_handle (HANDLE h, int pid)
{
/* -------------------- critical section -------------------- */
(*Lock_Task) ();
@ -2355,14 +2354,11 @@ add_handle (HANDLE h, int pid)
/* -------------------- critical section -------------------- */
}
void
__gnat_win32_remove_handle (HANDLE h, int pid)
static void
remove_handle (HANDLE h, int pid)
{
int j;
/* -------------------- critical section -------------------- */
(*Lock_Task) ();
for (j = 0; j < plist_length; j++)
{
if ((HANDLES_LIST[j] == h) || (PID_LIST[j] == pid))
@ -2374,6 +2370,15 @@ __gnat_win32_remove_handle (HANDLE h, int pid)
break;
}
}
}
void
__gnat_win32_remove_handle (HANDLE h, int pid)
{
/* -------------------- critical section -------------------- */
(*Lock_Task) ();
remove_handle(h, pid);
(*Unlock_Task) ();
/* -------------------- critical section -------------------- */
@ -2464,31 +2469,31 @@ win32_wait (int *status)
DWORD res;
int hl_len;
/* -------------------- critical section -------------------- */
(*Lock_Task) ();
if (plist_length == 0)
{
errno = ECHILD;
(*Unlock_Task) ();
return -1;
}
/* -------------------- critical section -------------------- */
(*Lock_Task) ();
hl_len = plist_length;
hl = (HANDLE *) xmalloc (sizeof (HANDLE) * hl_len);
memmove (hl, HANDLES_LIST, sizeof (HANDLE) * hl_len);
(*Unlock_Task) ();
/* -------------------- critical section -------------------- */
res = WaitForMultipleObjects (hl_len, hl, FALSE, INFINITE);
h = hl[res - WAIT_OBJECT_0];
GetExitCodeProcess (h, &exitcode);
pid = PID_LIST [res - WAIT_OBJECT_0];
__gnat_win32_remove_handle (h, -1);
remove_handle (h, -1);
(*Unlock_Task) ();
/* -------------------- critical section -------------------- */
free (hl);
*status = (int) exitcode;