public inbox for cygwin-cvs@sourceware.org help / color / mirror / Atom feed
From: Ken Brown <kbrown@sourceware.org> To: cygwin-cvs@sourceware.org Subject: [newlib-cygwin] Cygwin: FIFO: introduce a new type, fifo_reader_id_t Date: Fri, 8 May 2020 11:30:07 +0000 (GMT) [thread overview] Message-ID: <20200508113007.81A09396ECFE@sourceware.org> (raw) https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=16e7c1057854728ca7768813c995e6d83f90db67 commit 16e7c1057854728ca7768813c995e6d83f90db67 Author: Ken Brown <kbrown@cornell.edu> 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 ()))
reply other threads:[~2020-05-08 11:30 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20200508113007.81A09396ECFE@sourceware.org \ --to=kbrown@sourceware.org \ --cc=cygwin-cvs@sourceware.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).