Commit 6654786e by Pascal Obry Committed by Arnaud Charlet

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
parent 04e9213d
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> 2014-11-20 Eric Botcazou <ebotcazou@adacore.com>
* inline.adb (Analyze_Inlined_Bodies): Iterate between loading * inline.adb (Analyze_Inlined_Bodies): Iterate between loading
......
...@@ -2334,7 +2334,6 @@ static int *PID_LIST = NULL, plist_length = 0, plist_max_length = 0; ...@@ -2334,7 +2334,6 @@ static int *PID_LIST = NULL, plist_length = 0, plist_max_length = 0;
static void static void
add_handle (HANDLE h, int pid) add_handle (HANDLE h, int pid)
{ {
/* -------------------- critical section -------------------- */ /* -------------------- critical section -------------------- */
(*Lock_Task) (); (*Lock_Task) ();
...@@ -2355,14 +2354,11 @@ add_handle (HANDLE h, int pid) ...@@ -2355,14 +2354,11 @@ add_handle (HANDLE h, int pid)
/* -------------------- critical section -------------------- */ /* -------------------- critical section -------------------- */
} }
void static void
__gnat_win32_remove_handle (HANDLE h, int pid) remove_handle (HANDLE h, int pid)
{ {
int j; int j;
/* -------------------- critical section -------------------- */
(*Lock_Task) ();
for (j = 0; j < plist_length; j++) for (j = 0; j < plist_length; j++)
{ {
if ((HANDLES_LIST[j] == h) || (PID_LIST[j] == pid)) if ((HANDLES_LIST[j] == h) || (PID_LIST[j] == pid))
...@@ -2374,6 +2370,15 @@ __gnat_win32_remove_handle (HANDLE h, int pid) ...@@ -2374,6 +2370,15 @@ __gnat_win32_remove_handle (HANDLE h, int pid)
break; break;
} }
} }
}
void
__gnat_win32_remove_handle (HANDLE h, int pid)
{
/* -------------------- critical section -------------------- */
(*Lock_Task) ();
remove_handle(h, pid);
(*Unlock_Task) (); (*Unlock_Task) ();
/* -------------------- critical section -------------------- */ /* -------------------- critical section -------------------- */
...@@ -2464,31 +2469,31 @@ win32_wait (int *status) ...@@ -2464,31 +2469,31 @@ win32_wait (int *status)
DWORD res; DWORD res;
int hl_len; int hl_len;
/* -------------------- critical section -------------------- */
(*Lock_Task) ();
if (plist_length == 0) if (plist_length == 0)
{ {
errno = ECHILD; errno = ECHILD;
(*Unlock_Task) ();
return -1; return -1;
} }
/* -------------------- critical section -------------------- */
(*Lock_Task) ();
hl_len = plist_length; hl_len = plist_length;
hl = (HANDLE *) xmalloc (sizeof (HANDLE) * hl_len); hl = (HANDLE *) xmalloc (sizeof (HANDLE) * hl_len);
memmove (hl, HANDLES_LIST, sizeof (HANDLE) * hl_len); memmove (hl, HANDLES_LIST, sizeof (HANDLE) * hl_len);
(*Unlock_Task) ();
/* -------------------- critical section -------------------- */
res = WaitForMultipleObjects (hl_len, hl, FALSE, INFINITE); res = WaitForMultipleObjects (hl_len, hl, FALSE, INFINITE);
h = hl[res - WAIT_OBJECT_0]; h = hl[res - WAIT_OBJECT_0];
GetExitCodeProcess (h, &exitcode); GetExitCodeProcess (h, &exitcode);
pid = PID_LIST [res - WAIT_OBJECT_0]; pid = PID_LIST [res - WAIT_OBJECT_0];
__gnat_win32_remove_handle (h, -1); remove_handle (h, -1);
(*Unlock_Task) ();
/* -------------------- critical section -------------------- */
free (hl); free (hl);
*status = (int) exitcode; *status = (int) exitcode;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment