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>2011-12-17 04:03:31 +0400
committerChristopher Faylor <me@cgf.cx>2011-12-17 04:03:31 +0400
commitca35d41cec77e095bf08cc48109210295b28cc08 (patch)
tree81c690e5f58612aaa763757d22ada427ff511900 /winsup/cygwin/cygheap.h
parent6eee66418c285caaf32187332f9e9fb0d7c008ab (diff)
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/cygheap.h')
-rw-r--r--winsup/cygwin/cygheap.h34
1 files changed, 29 insertions, 5 deletions
diff --git a/winsup/cygwin/cygheap.h b/winsup/cygwin/cygheap.h
index 204ebe2f8..5d7b93dcc 100644
--- a/winsup/cygwin/cygheap.h
+++ b/winsup/cygwin/cygheap.h
@@ -328,10 +328,7 @@ class cygheap_fdmanip
if (locked)
cygheap->fdtab.unlock ();
}
- void release ()
- {
- cygheap->fdtab.release (fd);
- }
+ virtual void release () { cygheap->fdtab.release (fd); }
operator int &() {return fd;}
operator fhandler_base* &() {return cygheap->fdtab[fd];}
operator fhandler_socket* () const {return reinterpret_cast<fhandler_socket *> (cygheap->fdtab[fd]);}
@@ -368,12 +365,18 @@ class cygheap_fdnew : public cygheap_fdmanip
locked = false;
}
}
+ ~cygheap_fdnew ()
+ {
+ if (cygheap->fdtab[fd])
+ cygheap->fdtab[fd]->refcnt (1);
+ }
void operator = (fhandler_base *fh) {cygheap->fdtab[fd] = fh;}
};
class cygheap_fdget : public cygheap_fdmanip
{
- public:
+ fhandler_base *fh;
+public:
cygheap_fdget (int fd, bool lockit = false, bool do_set_errno = true)
{
if (lockit)
@@ -382,6 +385,8 @@ class cygheap_fdget : public cygheap_fdmanip
{
this->fd = fd;
locked = lockit;
+ fh = cygheap->fdtab[fd];
+ fh->refcnt (1);
}
else
{
@@ -391,8 +396,27 @@ class cygheap_fdget : public cygheap_fdmanip
if (lockit)
cygheap->fdtab.unlock ();
locked = false;
+ fh = NULL;
}
}
+ ~cygheap_fdget ()
+ {
+ if (!fh)
+ /* nothing to do */;
+ else if (fh->refcnt (-1) > 0)
+ debug_only_printf ("fh %p, %s, refcnt %ld", fh, fh->get_name (), fh->refcnt ());
+ else
+ {
+ debug_only_printf ("deleting fh %p, %s, refcnt %ld", fh, fh->get_name (), fh->refcnt ());
+ delete fh;
+ }
+ }
+ void release ()
+ {
+ fh = cygheap->fdtab[fd];
+ if (cygheap->fdtab.release (fd))
+ fh = NULL;
+ }
};
class cygheap_fdenum : public cygheap_fdmanip