Cygwin: FIFO: synchronize the fifo_reader and fifosel threads

The fifo_reader thread function and the function select.cc:peek_fifo()
can both change the state of a fifo_client_handler.  These changes are
made under fifo_client_lock, so there is no race, but the changes can
still be incompatible.

Add code to make sure that only one of these functions can change the
state from its initial fc_listening state.  Whichever function does
this calls the fhandler_fifo::record_connection method, which is now
public so that peek_fifo can call it.

Slightly modify that method to make it suitable for being called by
peek_fifo.

Make a few other small changes to the fifo_reader thread function to
change how it deals with the STATUS_PIPE_CLOSING value that can
(rarely) be returned by NtFsControlFile.

Add commentary to fhandler_fifo.cc to explain fifo_client connect
states and where they can be changed.
This commit is contained in:
Ken Brown
2020-08-03 09:38:08 -04:00
parent 251624a352
commit 0fda55133a
3 changed files with 60 additions and 9 deletions

View File

@ -1413,8 +1413,6 @@ class fhandler_fifo: public fhandler_base
void cleanup_handlers ();
void close_all_handlers ();
void cancel_reader_thread ();
void record_connection (fifo_client_handler&,
fifo_client_connect_state = fc_connected);
int create_shmem (bool only_open = false);
int reopen_shmem ();
@ -1482,6 +1480,8 @@ public:
DWORD fifo_reader_thread_func ();
void fifo_client_lock () { _fifo_client_lock.lock (); }
void fifo_client_unlock () { _fifo_client_lock.unlock (); }
void record_connection (fifo_client_handler&, bool = true,
fifo_client_connect_state = fc_connected);
int take_ownership (DWORD timeout = INFINITE);
void reading_lock () { shmem->reading_lock (); }