Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher Faylor <me@cgf.cx>2009-08-05 08:44:27 +0400
committerChristopher Faylor <me@cgf.cx>2009-08-05 08:44:27 +0400
commita99345591f51350eee9f52fab5163412edef1804 (patch)
treed66784de8d41dca15517d79f14cc78b0593fa7e1 /winsup/cygwin/debug.cc
parent7f01964f06effba5278ce060ebf55b7e080c59a8 (diff)
* cygheap.h (cygheap_debug::endh): Delete.
* debug.cc (lock_debug::acquired): Delete. (lock_debug::lock_debug): Simplify. (lock_debug::unlock): Ditto. (find_handle): Don't set endh here. (add_handle): Add new handle to beginning of the list rather than trying to maintain an end list pointer. (delete_handle): Minor optimization. (mark_closed): Make logic clearer. (verify_handle): Lock handle list before scanning. (setclexec): Ditto. (modify_handle): Ditto. (newh): Don't lock handle list here. Assume caller did this. (mark_closed): Ditto. (close_handle): Remove unneeded #if. * dtable.cc (dtable::dup2): Tweak debug output.
Diffstat (limited to 'winsup/cygwin/debug.cc')
-rw-r--r--winsup/cygwin/debug.cc34
1 files changed, 12 insertions, 22 deletions
diff --git a/winsup/cygwin/debug.cc b/winsup/cygwin/debug.cc
index 232a7b838..bea256cae 100644
--- a/winsup/cygwin/debug.cc
+++ b/winsup/cygwin/debug.cc
@@ -27,20 +27,14 @@ details. */
class lock_debug
{
static muto locker;
- bool acquired;
public:
- lock_debug () : acquired (0)
+ lock_debug ()
{
- if (locker.name && !exit_state)
- acquired = !!locker.acquire (INFINITE);
+ locker.acquire (INFINITE);
}
void unlock ()
{
- if (locker.name && acquired)
- {
- locker.release ();
- acquired = false;
- }
+ locker.release ();
}
~lock_debug () {unlock ();}
friend void debug_init ();
@@ -64,7 +58,6 @@ find_handle (HANDLE h)
for (hl = &cygheap->debug.starth; hl->next != NULL; hl = hl->next)
if (hl->next->h == h)
goto out;
- cygheap->debug.endh = hl;
hl = NULL;
out:
@@ -74,6 +67,7 @@ out:
void
verify_handle (const char *func, int ln, HANDLE h)
{
+ lock_debug here;
handle_list *hl = find_handle (h);
if (!hl)
return;
@@ -86,6 +80,7 @@ verify_handle (const char *func, int ln, HANDLE h)
void
setclexec (HANDLE oh, HANDLE nh, bool not_inheriting)
{
+ lock_debug here;
handle_list *hl = find_handle (oh);
if (hl)
{
@@ -100,7 +95,6 @@ static handle_list * __stdcall
newh ()
{
handle_list *hl;
- lock_debug here;
for (hl = cygheap->debug.freeh; hl < cygheap->debug.freeh + NFREEH; hl++)
if (hl->name == NULL)
@@ -112,6 +106,7 @@ newh ()
void __stdcall
modify_handle (const char *func, int ln, HANDLE h, const char *name, bool inh)
{
+ lock_debug here;
handle_list *hl = find_handle (h);
if (!hl)
{
@@ -128,11 +123,11 @@ void __stdcall
add_handle (const char *func, int ln, HANDLE h, const char *name, bool inh)
{
handle_list *hl;
- lock_debug here;
if (!cygheap)
return;
+ lock_debug here;
if ((hl = find_handle (h)))
{
hl = hl->next;
@@ -156,11 +151,10 @@ add_handle (const char *func, int ln, HANDLE h, const char *name, bool inh)
hl->name = name;
hl->func = func;
hl->ln = ln;
- hl->next = NULL;
hl->inherited = inh;
hl->pid = GetCurrentProcessId ();
- cygheap->debug.endh->next = hl;
- cygheap->debug.endh = hl;
+ hl->next = cygheap->debug.starth.next;
+ cygheap->debug.starth.next = hl;
SetHandleInformation (h, HANDLE_FLAG_PROTECT_FROM_CLOSE, HANDLE_FLAG_PROTECT_FROM_CLOSE);
debug_printf ("protecting handle '%s'(%p), inherited flag %d", hl->name, hl->h, hl->inherited);
}
@@ -170,7 +164,7 @@ delete_handle (handle_list *hl)
{
handle_list *hnuke = hl->next;
debug_printf ("nuking handle '%s' (%p)", hnuke->name, hnuke->h);
- hl->next = hl->next->next;
+ hl->next = hnuke->next;
memset (hnuke, 0, sizeof (*hnuke));
}
@@ -190,7 +184,6 @@ static bool __stdcall
mark_closed (const char *func, int ln, HANDLE h, const char *name, bool force)
{
handle_list *hl;
- lock_debug here;
if (!cygheap)
return true;
@@ -198,7 +191,6 @@ mark_closed (const char *func, int ln, HANDLE h, const char *name, bool force)
if ((hl = find_handle (h)) && !force)
{
hl = hl->next;
- here.unlock (); // race here
system_printf ("attempt to close protected handle %s:%d(%s<%p>) winpid %d",
hl->func, hl->ln, hl->name, hl->h, hl->pid);
system_printf (" by %s:%d(%s<%p>)", func, ln, name, h);
@@ -206,7 +198,7 @@ mark_closed (const char *func, int ln, HANDLE h, const char *name, bool force)
}
handle_list *hln;
- if (hl && (hln = hl->next) && strcmp (name, hln->name))
+ if (hl && (hln = hl->next) && strcmp (name, hln->name) != 0)
{
system_printf ("closing protected handle %s:%d(%s<%p>)",
hln->func, hln->ln, hln->name, hln->h);
@@ -225,18 +217,16 @@ bool __stdcall
close_handle (const char *func, int ln, HANDLE h, const char *name, bool force)
{
bool ret;
- lock_debug here;
+ lock_debug here;
if (!mark_closed (func, ln, h, name, force))
return false;
SetHandleInformation (h, HANDLE_FLAG_PROTECT_FROM_CLOSE, 0);
ret = CloseHandle (h);
-#if 1 /* Uncomment to see CloseHandle failures */
if (!ret)
small_printf ("CloseHandle(%s<%p>) failed %s:%d, %E\n", name, h, func, ln);
-#endif
return ret;
}
#endif /*DEBUGGING*/