4
0
mirror of git://sourceware.org/git/newlib-cygwin.git synced 2025-02-13 04:29:09 +08:00

Cygwin: fhandler: move "isclosed" status flag into fhandler_pipe_fifo

The isclosed flag is only used in pipe and FIFO code, so move the
flag down into the fhandler_pipe_fifo class.

Note that such a flag is not sufficient to avoid evil, like closing
an already closing fhandler from another thread.  If we ever need this,
it has to be implemented threadsafe.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
This commit is contained in:
Corinna Vinschen 2025-01-28 16:07:22 +01:00
parent 6baa8484db
commit c7eb1a1f52
6 changed files with 16 additions and 7 deletions

View File

@ -1579,7 +1579,6 @@ fhandler_base::fhandler_base () :
ra.raixget = 0;
ra.raixput = 0;
ra.rabuflen = 0;
isclosed (false);
}
/* Normal I/O destructor */

View File

@ -1524,6 +1524,7 @@ fhandler_fifo::cancel_reader_thread ()
int
fhandler_fifo::close ()
{
isclosed (true);
if (select_sem)
{
release_select_sem ("close");

View File

@ -31,7 +31,10 @@ STATUS_PIPE_EMPTY simply means there's no data to be read. */
|| _s == STATUS_PIPE_EMPTY; })
fhandler_pipe_fifo::fhandler_pipe_fifo ()
: fhandler_base (), pipe_buf_size (DEFAULT_PIPEBUFSIZE), pipe_mtx (NULL)
: fhandler_base (),
status (),
pipe_buf_size (DEFAULT_PIPEBUFSIZE),
pipe_mtx (NULL)
{
}
@ -758,6 +761,7 @@ fhandler_pipe::dup (fhandler_base *child, int flags)
int
fhandler_pipe::close ()
{
isclosed (true);
if (select_sem)
{
release_select_sem ("close");

View File

@ -179,14 +179,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. */
unsigned mandatory_locking : 1; /* Windows mandatory locking */
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), isclosed (0), mandatory_locking (0)
need_fork_fixup (0), mandatory_locking (0)
{}
} status, open_status;
@ -290,7 +289,6 @@ 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)
IMPLEMENT_STATUS_FLAG (bool, mandatory_locking)
int get_default_fmode (int flags);
@ -1195,11 +1193,20 @@ class fhandler_socket_unix : public fhandler_socket
/* A parent of fhandler_pipe and fhandler_fifo. */
class fhandler_pipe_fifo: public fhandler_base
{
struct status_flags
{
unsigned isclosed : 1; /* Set when pipe/FIFO fhandler is closed. */
public:
status_flags () : isclosed (0) {}
} status;
protected:
size_t pipe_buf_size;
HANDLE pipe_mtx; /* Used only in the pipe case */
virtual void release_select_sem (const char *) {};
IMPLEMENT_STATUS_FLAG (bool, isclosed)
public:
fhandler_pipe_fifo ();

View File

@ -333,7 +333,6 @@ mq_close (mqd_t mqd)
if (mq_notify (mqd, NULL)) /* unregister calling process */
__leave;
fd->isclosed (true);
fd->close ();
fd.release ();
return 0;

View File

@ -1692,7 +1692,6 @@ close (int fd)
res = -1;
else
{
cfd->isclosed (true);
res = cfd->close_with_arch ();
cfd.release ();
}