+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
static void
add_handle (HANDLE h, int pid)
{
-
/* -------------------- critical section -------------------- */
(*Lock_Task) ();
/* -------------------- 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))
break;
}
}
+}
+
+void
+__gnat_win32_remove_handle (HANDLE h, int pid)
+{
+ /* -------------------- critical section -------------------- */
+ (*Lock_Task) ();
+
+ remove_handle(h, pid);
(*Unlock_Task) ();
/* -------------------- critical section -------------------- */
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;