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.
This commit is contained in:
@@ -142,12 +142,13 @@ class fhandler_base
|
||||
read or write access */
|
||||
unsigned close_on_exec : 1; /* close-on-exec */
|
||||
unsigned need_fork_fixup : 1; /* Set if need to fixup after fork. */
|
||||
unsigned isclosed : 1; /* Set when fhandler is closed. */
|
||||
|
||||
public:
|
||||
status_flags () :
|
||||
rbinary (0), rbinset (0), wbinary (0), wbinset (0), nohandle (0),
|
||||
did_lseek (0), query_open (no_query), close_on_exec (0),
|
||||
need_fork_fixup (0)
|
||||
need_fork_fixup (0), isclosed (0)
|
||||
{}
|
||||
} status, open_status;
|
||||
|
||||
@@ -158,6 +159,7 @@ class fhandler_base
|
||||
HANDLE io_handle;
|
||||
|
||||
__ino64_t ino; /* file ID or hashed filename, depends on FS. */
|
||||
long _refcnt;
|
||||
|
||||
protected:
|
||||
/* File open flags from open () and fcntl () calls */
|
||||
@@ -176,6 +178,7 @@ class fhandler_base
|
||||
HANDLE read_state;
|
||||
|
||||
public:
|
||||
long refcnt(long i = 0) {return _refcnt += i;}
|
||||
class fhandler_base *archetype;
|
||||
int usecount;
|
||||
|
||||
@@ -239,6 +242,7 @@ class fhandler_base
|
||||
IMPLEMENT_STATUS_FLAG (query_state, query_open)
|
||||
IMPLEMENT_STATUS_FLAG (bool, close_on_exec)
|
||||
IMPLEMENT_STATUS_FLAG (bool, need_fork_fixup)
|
||||
IMPLEMENT_STATUS_FLAG (bool, isclosed)
|
||||
|
||||
int get_default_fmode (int flags);
|
||||
|
||||
|
Reference in New Issue
Block a user