* sync.h (new_muto): Just accept an argument which denotes the name of the

muto.  Use this argument to construct static storage.
* cygheap.cc (cygheap_init): Reflect above change.
* exceptions.cc (events_init): Ditto.
* malloc.cc (malloc_init): Ditto.
* path.cc (cwdstuff::init): Ditto.
* cygheap.h (cwdstuff): Change name of lock element to make it less generic.
* path.cc (cwdstuff::get_hash): Ditto.
(cwdstuff::get_initial): Ditto.
(cwdstuff::set): Ditto.
(cwdstuff::get): Ditto.
* sigproc.cc (proc_subproc): Ditto.
* debug.cc (lock_debug): Change to method.  Use method rather than macro
throughout.
* tty.h (tty_min::kill_pgrp): Declare new method.
* fhandler_termios.cc (tty_min::kill_pgrp): New method.
(fhandler_termios::line_edit): Use new method for killing process.
* dcrt0.cc (do_exit): Ditto.
* dtable.cc (dtable::get_debugger_info): New method for inheriting dtable info
from a debugger.
* tty.cc (tty_init): Attempt to grab file handle info from parent debugger, if
appropriate.  # dtable.cc (dtable::stdio_init): Make this a method.
(dtable::init_std_file_from_handle): Don't set fd unless it's not open.
(dtable::build_fhandler_from_name): Move name setting to
dtable::build_fhandler.
(dtable::build_fhandler): Add win32 name parameter.
* dcrt0.cc (dll_crt0_1): Change to use dtable stdio_init.
* dtable.h (dtable): Reflect build_fhandler parameter change.
* mmap.cc (mmap_record::alloc_fh): Don't set name parameter in build_fhandler.
* net.cc (fdsock): Remove set_name call since it is now handled by
build_fhandler.
* sigproc.cc (proc_subproc): Release muto as early as possible.
This commit is contained in:
Christopher Faylor
2002-02-22 19:33:41 +00:00
parent a6790c5f11
commit 083abe5428
18 changed files with 192 additions and 84 deletions

View File

@ -37,7 +37,7 @@ static NO_COPY thread_info threads[32] = {{0, NULL}}; // increase as necessary
void
threadname_init ()
{
threadname_lock = new_muto ("threadname_lock");
new_muto (threadname_lock);
}
void __stdcall
@ -184,18 +184,19 @@ static handle_list NO_COPY freeh[1000] = {{0, NULL, NULL, NULL, 0, 0, NULL}};
static muto NO_COPY *debug_lock = NULL;
#define lock_debug() \
do {if (debug_lock) debug_lock->acquire (INFINITE); } while (0)
#define unlock_debug() \
do {if (debug_lock) debug_lock->release (); } while (0)
struct lock_debug
{
lock_debug () {if (debug_lock) debug_lock->acquire (INFINITE);}
void unlock () {if (debug_lock) debug_lock->release ();}
~lock_debug () {unlock ();}
};
static bool __stdcall mark_closed (const char *, int, HANDLE, const char *, BOOL);
void
debug_init ()
{
debug_lock = new_muto ("debug_lock");
new_muto (debug_lock);
}
/* Find a registered handle in the linked list of handles. */
@ -229,7 +230,8 @@ static handle_list * __stdcall
newh ()
{
handle_list *hl;
lock_debug ();
lock_debug here;
for (hl = freeh; hl < freeh + NFREEH; hl++)
if (hl->name == NULL)
goto out;
@ -242,7 +244,6 @@ newh ()
}
out:
unlock_debug ();
return hl;
}
@ -251,7 +252,7 @@ void __stdcall
add_handle (const char *func, int ln, HANDLE h, const char *name)
{
handle_list *hl;
lock_debug ();
lock_debug here;
if ((hl = find_handle (h)))
{
@ -260,12 +261,12 @@ add_handle (const char *func, int ln, HANDLE h, const char *name)
ln, name, h);
system_printf (" previously allocated by %s:%d(%s<%p>)",
hl->func, hl->ln, hl->name, hl->h);
goto out; /* Already did this once */
return;
}
if ((hl = newh ()) == NULL)
{
unlock_debug ();
here.unlock ();
system_printf ("couldn't allocate memory for %s(%d): %s(%p)",
func, ln, name, h);
return;
@ -278,8 +279,7 @@ add_handle (const char *func, int ln, HANDLE h, const char *name)
endh->next = hl;
endh = hl;
out:
unlock_debug ();
return;
}
static void __stdcall
@ -306,11 +306,12 @@ static bool __stdcall
mark_closed (const char *func, int ln, HANDLE h, const char *name, BOOL force)
{
handle_list *hl;
lock_debug ();
lock_debug here;
if ((hl = find_handle (h)) && !force)
{
hl = hl->next;
unlock_debug (); // race here
here.unlock (); // race here
system_printf ("attempt to close protected handle %s:%d(%s<%p>)",
hl->func, hl->ln, hl->name, hl->h);
system_printf (" by %s:%d(%s<%p>)", func, ln, name, h);
@ -328,7 +329,6 @@ mark_closed (const char *func, int ln, HANDLE h, const char *name, BOOL force)
if (hl)
delete_handle (hl);
unlock_debug ();
return TRUE;
}
@ -338,14 +338,13 @@ BOOL __stdcall
close_handle (const char *func, int ln, HANDLE h, const char *name, BOOL force)
{
BOOL ret;
lock_debug ();
lock_debug here;
if (!mark_closed (func, ln, h, name, force))
return FALSE;
ret = CloseHandle (h);
unlock_debug ();
#if 0 /* Uncomment to see CloseHandle failures */
if (!ret)
small_printf ("CloseHandle(%s) failed %s:%d\n", name, func, ln);
@ -353,7 +352,6 @@ close_handle (const char *func, int ln, HANDLE h, const char *name, BOOL force)
return ret;
}
/* Add a handle to the linked list of known handles. */
int __stdcall
__set_errno (const char *func, int ln, int val)
{