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: lock fixes Date: Tue, 4 Aug 2020 15:29:16 +0000 (GMT) [thread overview] Message-ID: <20200804152916.9E39A385ED4B@sourceware.org> (raw) https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=e319fd0e627292f2083d7c8365186d175a7578fd commit e319fd0e627292f2083d7c8365186d175a7578fd Author: Ken Brown <kbrown@cornell.edu> Date: Fri Jul 31 13:55:17 2020 -0400 Cygwin: FIFO: lock fixes Add some missing locks and remove one extra unlock. Clarify for some functions whether caller or callee acquires lock, and add appropriate comments. Diff: --- winsup/cygwin/fhandler_fifo.cc | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/winsup/cygwin/fhandler_fifo.cc b/winsup/cygwin/fhandler_fifo.cc index e9d0187d4..ee7f47c0c 100644 --- a/winsup/cygwin/fhandler_fifo.cc +++ b/winsup/cygwin/fhandler_fifo.cc @@ -316,6 +316,7 @@ fhandler_fifo::wait_open_pipe (HANDLE& ph) return status; } +/* Always called with fifo_client_lock in place. */ int fhandler_fifo::add_client_handler (bool new_pipe_instance) { @@ -345,6 +346,7 @@ fhandler_fifo::add_client_handler (bool new_pipe_instance) return 0; } +/* Always called with fifo_client_lock in place. */ void fhandler_fifo::delete_client_handler (int i) { @@ -354,7 +356,8 @@ fhandler_fifo::delete_client_handler (int i) (nhandlers - i) * sizeof (fc_handler[i])); } -/* Delete handlers that we will never read from. */ +/* Delete handlers that we will never read from. Always called with + fifo_client_lock in place. */ void fhandler_fifo::cleanup_handlers () { @@ -369,6 +372,7 @@ fhandler_fifo::cleanup_handlers () } } +/* Always called with fifo_client_lock in place. */ void fhandler_fifo::record_connection (fifo_client_handler& fc, fifo_client_connect_state s) @@ -398,6 +402,7 @@ fhandler_fifo::update_my_handlers () if (!prev_proc) api_fatal ("Can't open process of previous owner, %E"); + fifo_client_lock (); for (int i = 0; i < get_shared_nhandlers (); i++) { if (add_client_handler (false) < 0) @@ -419,10 +424,12 @@ fhandler_fifo::update_my_handlers () fc.last_read = shared_fc_handler[i].last_read; } } + fifo_client_unlock (); set_prev_owner (null_fr_id); return ret; } +/* Always called with fifo_client_lock and owner_lock in place. */ int fhandler_fifo::update_shared_handlers () { @@ -435,9 +442,7 @@ fhandler_fifo::update_shared_handlers () set_shared_nhandlers (nhandlers); memcpy (shared_fc_handler, fc_handler, nhandlers * sizeof (fc_handler[0])); shared_fc_handler_updated (true); - owner_lock (); set_prev_owner (me); - owner_unlock (); return 0; } @@ -509,7 +514,6 @@ fhandler_fifo::fifo_reader_thread_func () if (update_my_handlers () < 0) debug_printf ("error updating my handlers, %E"); owner_found (); - owner_unlock (); /* Fall through to owner_listen. */ } } @@ -602,8 +606,13 @@ owner_listen: } if (ph) NtClose (ph); - if (update && update_shared_handlers () < 0) - api_fatal ("Can't update shared handlers, %E"); + if (update) + { + owner_lock (); + if (get_owner () == me && update_shared_handlers () < 0) + api_fatal ("Can't update shared handlers, %E"); + owner_unlock (); + } fifo_client_unlock (); if (cancel) goto canceled; @@ -1402,9 +1411,11 @@ fhandler_fifo::fstatvfs (struct statvfs *sfs) void fhandler_fifo::close_all_handlers () { + fifo_client_lock (); for (int i = 0; i < nhandlers; i++) fc_handler[i].close (); nhandlers = 0; + fifo_client_unlock (); } fifo_client_connect_state
reply other threads:[~2020-08-04 15:29 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=20200804152916.9E39A385ED4B@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).