From: cgf Date: Sun, 9 Sep 2001 03:34:36 +0000 (+0000) Subject: * fork.cc (fork_parent): Stop malloc activity while fork is in control of the X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=23aa6629d1f88b26c70847ef96d3994a86117d13;p=pf3gnuchains%2Fpf3gnuchains3x.git * fork.cc (fork_parent): Stop malloc activity while fork is in control of the heap. * sigproc.cc (NZOMBIES): Rename from ZOMBIEMAX for clarity. (zombies): Revert to original behavior. Allocating zombie array resulted in performance hit. * winsup.h: Declare malloc lock routines. --- diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index fc7e54bdca..6d9afe096e 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,12 @@ +Sat Sep 8 23:32:18 2001 Christopher Faylor + + * fork.cc (fork_parent): Stop malloc activity while fork is in control + of the heap. + * sigproc.cc (NZOMBIES): Rename from ZOMBIEMAX for clarity. + (zombies): Revert to original behavior. Allocating zombie array + resulted in performance hit. + * winsup.h: Declare malloc lock routines. + Fri Sep 7 21:35:35 2001 Christopher Faylor * cygwin.din: Add gamm*_r function exports. diff --git a/winsup/cygwin/fork.cc b/winsup/cygwin/fork.cc index b72b441dc2..3a63e39010 100644 --- a/winsup/cygwin/fork.cc +++ b/winsup/cygwin/fork.cc @@ -462,6 +462,7 @@ fork_parent (HANDLE& hParent, dll *&first_dll, char sa_buf[1024]; syscall_printf ("CreateProcess (%s, %s, 0, 0, 1, %x, 0, 0, %p, %p)", myself->progname, myself->progname, c_flags, &si, &pi); + __malloc_lock (_reent_clib ()); cygheap_setup_for_child (&ch); rc = CreateProcess (myself->progname, /* image to run */ myself->progname, /* what we send in arg0 */ @@ -557,6 +558,7 @@ fork_parent (HANDLE& hParent, dll *&first_dll, dll_data_start, dll_data_end, dll_bss_start, dll_bss_end, NULL); + __malloc_unlock (_reent_clib ()); MALLOC_CHECK; if (!rc) goto cleanup; diff --git a/winsup/cygwin/malloc_wrapper.cc b/winsup/cygwin/malloc_wrapper.cc index 783fec9563..7aa29f5c6f 100644 --- a/winsup/cygwin/malloc_wrapper.cc +++ b/winsup/cygwin/malloc_wrapper.cc @@ -154,8 +154,7 @@ _strdup_r (struct _reent *, const char *s) /* These routines are used by the application if it doesn't provide its own malloc. */ -extern "C" -void +extern "C" void export_free (void *p) { malloc_printf ("(%p), called by %x", p, ((int *)&p)[-1]); @@ -165,8 +164,7 @@ export_free (void *p) user_data->free (p); } -extern "C" -void * +extern "C" void * export_malloc (int size) { void *res; @@ -179,8 +177,7 @@ export_malloc (int size) return res; } -extern "C" -void * +extern "C" void * export_realloc (void *p, int size) { void *res; @@ -192,8 +189,7 @@ export_realloc (void *p, int size) return res; } -extern "C" -void * +extern "C" void * export_calloc (size_t nmemb, size_t size) { void *res; @@ -234,15 +230,13 @@ malloc_init () } } -extern "C" -void +extern "C" void __malloc_lock (struct _reent *) { mprotect->acquire (); } -extern "C" -void +extern "C" void __malloc_unlock (struct _reent *) { mprotect->release (); diff --git a/winsup/cygwin/sigproc.cc b/winsup/cygwin/sigproc.cc index 39a300bf20..a4b9168e41 100644 --- a/winsup/cygwin/sigproc.cc +++ b/winsup/cygwin/sigproc.cc @@ -46,7 +46,7 @@ details. */ #define no_signals_available() (!hwait_sig || !sig_loop_wait) -#define ZOMBIEMAX 4096 +#define NZOMBIES 4096 /* * Global variables @@ -99,12 +99,12 @@ Static HANDLE wait_sig_inited = NULL; // Control synchronization of /* Used by WaitForMultipleObjects. These are handles to child processes. */ -Static HANDLE events[PSIZE + 1] = {0}; // All my children's handles++ +Static HANDLE events[PSIZE + 1] = {0}; // All my children's handles++ #define hchildren (events + 1) // Where the children handles begin Static pinfo pchildren[PSIZE]; // All my children info Static int nchildren = 0; // Number of active children -static pinfo *zombies; // All my deceased children info -static int nzombies; // Number of deceased children +Static pinfo zombies[NZOMBIES]; // All my deceased children info +Static int nzombies = 0; // Number of deceased children Static waitq waitq_head = {0, 0, 0, 0, 0, 0, 0};// Start of queue for wait'ing threads Static waitq waitq_main; // Storage for main thread @@ -318,7 +318,7 @@ proc_subproc (DWORD what, DWORD val) filled up our table or if we're ignoring SIGCHLD, then we immediately remove the process and move on. Otherwise, this process becomes a zombie which must be reaped by a wait() call. */ - if (nzombies >= ZOMBIEMAX + if (nzombies >= NZOMBIES || myself->getsig (SIGCHLD).sa_handler == (void *) SIG_IGN) { sigproc_printf ("automatically removing zombie %d", thiszombie); @@ -543,11 +543,6 @@ sig_dispatch_pending (int justwake) void __stdcall sigproc_init () { - if (!zombies) - zombies = (pinfo *) malloc (sizeof (pinfo) * ZOMBIEMAX); - else - nzombies = 0; - wait_sig_inited = CreateEvent (&sec_none_nih, TRUE, FALSE, NULL); ProtectHandle (wait_sig_inited); diff --git a/winsup/cygwin/winsup.h b/winsup/cygwin/winsup.h index 1b8c15579b..657aa883e4 100644 --- a/winsup/cygwin/winsup.h +++ b/winsup/cygwin/winsup.h @@ -211,6 +211,9 @@ extern "C" void __api_fatal (const char *, ...) __attribute__ ((noreturn)); extern "C" int __small_sprintf (char *dst, const char *fmt, ...) /*__attribute__ ((regparm (2)))*/; extern "C" int __small_vsprintf (char *dst, const char *fmt, va_list ap) /*__attribute__ ((regparm (3)))*/; +extern "C" void __malloc_lock (struct _reent *); +extern "C" void __malloc_unlock (struct _reent *); + /**************************** Exports ******************************/ extern "C" {