+2009-08-05 Christopher Faylor <me+cygwin@cgf.cx>
+
+ * 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.
+
2009-08-04 Christopher Faylor <me+cygwin@cgf.cx>
* path.cc (patch_conv::check): Zero path before setting it.
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 ();
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:
void
verify_handle (const char *func, int ln, HANDLE h)
{
+ lock_debug here;
handle_list *hl = find_handle (h);
if (!hl)
return;
void
setclexec (HANDLE oh, HANDLE nh, bool not_inheriting)
{
+ lock_debug here;
handle_list *hl = find_handle (oh);
if (hl)
{
newh ()
{
handle_list *hl;
- lock_debug here;
for (hl = cygheap->debug.freeh; hl < cygheap->debug.freeh + NFREEH; hl++)
if (hl->name == NULL)
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)
{
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;
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);
}
{
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));
}
mark_closed (const char *func, int ln, HANDLE h, const char *name, bool force)
{
handle_list *hl;
- lock_debug here;
if (!cygheap)
return true;
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);
}
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);
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*/