From 6654786e8fcc06afd500494533b0400138241b98 Mon Sep 17 00:00:00 2001 From: Pascal Obry Date: Thu, 20 Nov 2014 10:47:11 +0000 Subject: [PATCH] adaint.c (remove_handle): New local routine without a lock. 2014-11-20 Pascal Obry * 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 --- gcc/ada/ChangeLog | 7 +++++++ gcc/ada/adaint.c | 31 ++++++++++++++++++------------- 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog index 610203b6066..e12e368833f 100644 --- a/gcc/ada/ChangeLog +++ b/gcc/ada/ChangeLog @@ -1,3 +1,10 @@ +2014-11-20 Pascal Obry + + * 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 * inline.adb (Analyze_Inlined_Bodies): Iterate between loading diff --git a/gcc/ada/adaint.c b/gcc/ada/adaint.c index 0acaa74d3ab..4820677d40d 100644 --- a/gcc/ada/adaint.c +++ b/gcc/ada/adaint.c @@ -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; -- 2.30.2