summaryrefslogtreecommitdiffstats
path: root/winsup/cygwin/fhandler.cc
diff options
context:
space:
mode:
authorChristopher Faylor <me@cgf.cx>2011-12-17 00:03:31 +0000
committerChristopher Faylor <me@cgf.cx>2011-12-17 00:03:31 +0000
commitca35d41cec77e095bf08cc48109210295b28cc08 (patch)
tree81c690e5f58612aaa763757d22ada427ff511900 /winsup/cygwin/fhandler.cc
parent6eee66418c285caaf32187332f9e9fb0d7c008ab (diff)
downloadcygnal-ca35d41cec77e095bf08cc48109210295b28cc08.tar.gz
cygnal-ca35d41cec77e095bf08cc48109210295b28cc08.tar.bz2
cygnal-ca35d41cec77e095bf08cc48109210295b28cc08.zip
Implement fhandler reference counting.
* cygheap.h (cygheap_fdmanip::release): Make virtual. (cygheap_fdnew::~cygheap_fdnew): New destructor increments reference count when fd has been allocated. (cygheap_fdget::fh): New (old?) field. (cygheap_fdget::cygheap_fdget): Increment reference count when we've found an active fd. Set fh appropriately. (cygheap_fdget::~cygheap_fdget): Decrement reference count when appropriate. Delete fh if reference count goes to zero. (cygheap_fdget::release): New function. Do more bookkeping on release. * dtable.cc (dtable::release): Change from void to boolean return. Only delete the fhandler when its reference count is <= 0 (this should be a fairly unusual case). Return true if fhandler has been deleted. (cygwin_attach_handle_to_fd): Increment reference count when fh is assigned. (dtable::init_std_file_from_handle): Ditto. * dtable.h (dtable::release): Change return to boolean. * fhandler.cc (fhandler_base::fhandler_base): Set new isclosed flag to false. Set _refcnt to zero. (fhandler_base::close): Simplify paranoid debugging output. Set new isclosed() flag. (fhandler_base_overlapped::wait_overlapped): Use isclosed() flag to avoid querying the exception handle. * fhandler.h (fhandler_base::_refcnt): New field. (fhandler_base::refcnt): New function. (fhandler_base::isclosed): Implement. (fhandler_base::fhandler_base): Set isclosed to false. * syscalls.cc: Remove space after function before parentheses for several strace printfs. (dup): Add standard strace "leaver" code. (dup2): Ditto. (dup3): Ditto. (remove): Ditto. (getpid): Ditto. (getppid): Ditto. (lseek64): Fix strace debugging to correctly use %R. * fhandler_termios.cc (fhandler_termios::tcsetpgrp): Avoid sending signals to other processes if we're debugging since it can cause a deadlock with the calling debugger. * exceptions.cc (_cygtls::call_signal_handler): Add debugging-only strace output.
Diffstat (limited to 'winsup/cygwin/fhandler.cc')
-rw-r--r--winsup/cygwin/fhandler.cc11
1 files changed, 6 insertions, 5 deletions
diff --git a/winsup/cygwin/fhandler.cc b/winsup/cygwin/fhandler.cc
index 5fd416ce2..04499e6e7 100644
--- a/winsup/cygwin/fhandler.cc
+++ b/winsup/cygwin/fhandler.cc
@@ -1148,11 +1148,10 @@ fhandler_base::close ()
res = 0;
else
{
- paranoid_printf ("CloseHandle (%d <%s>) failed", get_handle (),
- get_name ());
-
+ paranoid_printf ("CloseHandle failed, %E");
__seterrno ();
}
+ isclosed (true);
return res;
}
@@ -1485,6 +1484,7 @@ fhandler_base::fhandler_base () :
access (0),
io_handle (NULL),
ino (0),
+ _refcnt (0),
openflags (0),
rabuf (NULL),
ralen (0),
@@ -1495,6 +1495,7 @@ fhandler_base::fhandler_base () :
archetype (NULL),
usecount (0)
{
+ isclosed (false);
}
/* Normal I/O destructor */
@@ -1928,8 +1929,8 @@ fhandler_base_overlapped::wait_overlapped (bool inres, bool writing, DWORD *byte
DWORD wfres = cygwait (get_overlapped ()->hEvent);
HANDLE h = writing ? get_output_handle () : get_handle ();
BOOL wores;
- if (wfres == WAIT_OBJECT_0 + 1 && !get_overlapped ())
- wores = 0;
+ if (isclosed ())
+ wores = 0; /* closed in another thread or via signal handler */
else
{
/* Cancelling here to prevent races. It's possible that the I/O has