From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2210) id 81A09396ECFE; Fri, 8 May 2020 11:30:07 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 81A09396ECFE Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Ken Brown To: cygwin-cvs@sourceware.org Subject: [newlib-cygwin] Cygwin: FIFO: introduce a new type, fifo_reader_id_t X-Act-Checkin: newlib-cygwin X-Git-Author: Ken Brown X-Git-Refname: refs/heads/master X-Git-Oldrev: 365818a4a5b0140bbf37b1d91fbf82aa9e376a6b X-Git-Newrev: 16e7c1057854728ca7768813c995e6d83f90db67 Message-Id: <20200508113007.81A09396ECFE@sourceware.org> Date: Fri, 8 May 2020 11:30:07 +0000 (GMT) X-BeenThere: cygwin-cvs@cygwin.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Cygwin core component git logs List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 08 May 2020 11:30:07 -0000 https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=16e7c1057854728ca7768813c995e6d83f90db67 commit 16e7c1057854728ca7768813c995e6d83f90db67 Author: Ken Brown Date: Wed Mar 25 19:22:10 2020 -0400 Cygwin: FIFO: introduce a new type, fifo_reader_id_t This uniquely identifies an fhandler_fifo open for reading in any process. Add a new data member 'me' of this type, which is set in open, dup, fork, and exec. Diff: --- winsup/cygwin/fhandler.h | 23 +++++++++++++++++++++++ winsup/cygwin/fhandler_fifo.cc | 9 ++++++++- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/winsup/cygwin/fhandler.h b/winsup/cygwin/fhandler.h index b2ee7e6b6..65aab4da3 100644 --- a/winsup/cygwin/fhandler.h +++ b/winsup/cygwin/fhandler.h @@ -1300,6 +1300,26 @@ struct fifo_client_handler int pipe_state (); }; +class fhandler_fifo; + +struct fifo_reader_id_t +{ + DWORD winpid; + fhandler_fifo *fh; + + operator bool () const { return winpid != 0 || fh != NULL; } + + friend operator == (const fifo_reader_id_t &l, const fifo_reader_id_t &r) + { + return l.winpid == r.winpid && l.fh == r.fh; + } + + friend operator != (const fifo_reader_id_t &l, const fifo_reader_id_t &r) + { + return l.winpid != r.winpid || l.fh != r.fh; + } +}; + /* Info needed by all readers of a FIFO, stored in named shared memory. */ class fifo_shmem_t { @@ -1329,6 +1349,7 @@ class fhandler_fifo: public fhandler_base af_unix_spinlock_t _fifo_client_lock; bool reader, writer, duplexer; size_t max_atomic_write; + fifo_reader_id_t me; HANDLE shmem_handle; fifo_shmem_t *shmem; @@ -1362,6 +1383,8 @@ public: void fifo_client_lock () { _fifo_client_lock.lock (); } void fifo_client_unlock () { _fifo_client_lock.unlock (); } + fifo_reader_id_t get_me () const { return me; } + int open (int, mode_t); off_t lseek (off_t offset, int whence); int close (); diff --git a/winsup/cygwin/fhandler_fifo.cc b/winsup/cygwin/fhandler_fifo.cc index d87070ac7..5676a2c97 100644 --- a/winsup/cygwin/fhandler_fifo.cc +++ b/winsup/cygwin/fhandler_fifo.cc @@ -65,13 +65,15 @@ STATUS_PIPE_EMPTY simply means there's no data to be read. */ || _s == STATUS_PIPE_NOT_AVAILABLE \ || _s == STATUS_PIPE_BUSY; }) +static NO_COPY fifo_reader_id_t null_fr_id = { .winpid = 0, .fh = NULL }; + fhandler_fifo::fhandler_fifo (): fhandler_base (), read_ready (NULL), write_ready (NULL), writer_opening (NULL), cancel_evt (NULL), thr_sync_evt (NULL), _maybe_eof (false), nhandlers (0), reader (false), writer (false), duplexer (false), max_atomic_write (DEFAULT_PIPEBUFSIZE), - shmem_handle (NULL), shmem (NULL) + me (null_fr_id), shmem_handle (NULL), shmem (NULL) { pipe_name_buf[0] = L'\0'; need_fork_fixup (true); @@ -575,6 +577,8 @@ fhandler_fifo::open (int flags, mode_t) goto err_dec_nreaders; if (!(thr_sync_evt = create_event ())) goto err_close_cancel_evt; + me.winpid = GetCurrentProcessId (); + me.fh = this; new cygthread (fifo_reader_thread, this, "fifo_reader", thr_sync_evt); /* If we're a duplexer, we need a handle for writing. */ @@ -1119,6 +1123,7 @@ fhandler_fifo::dup (fhandler_base *child, int flags) if (!(fhf->thr_sync_evt = create_event ())) goto err_close_cancel_evt; inc_nreaders (); + fhf->me.fh = fhf; new cygthread (fifo_reader_thread, fhf, "fifo_reader", fhf->thr_sync_evt); } return 0; @@ -1164,6 +1169,7 @@ fhandler_fifo::fixup_after_fork (HANDLE parent) if (!(thr_sync_evt = create_event ())) api_fatal ("Can't create reader thread sync event during fork, %E"); inc_nreaders (); + me.winpid = GetCurrentProcessId (); new cygthread (fifo_reader_thread, this, "fifo_reader", thr_sync_evt); } } @@ -1179,6 +1185,7 @@ fhandler_fifo::fixup_after_exec () if (reopen_shmem () < 0) api_fatal ("Can't reopen shared memory during exec, %E"); + me.winpid = GetCurrentProcessId (); if (!(cancel_evt = create_event ())) api_fatal ("Can't create reader thread cancel event during exec, %E"); if (!(thr_sync_evt = create_event ()))