Cygwin: FIFO: keep track of the number of readers

Add data and methods to the shared memory that keep track of the
number of open readers.

Increment this number in open, dup, fork, and exec.  Decrement it in
close.  Reset read_ready if there are no readers left.
This commit is contained in:
Ken Brown
2020-03-27 09:43:30 -04:00
parent 878eb22462
commit 365818a4a5
2 changed files with 22 additions and 8 deletions

View File

@ -1303,6 +1303,11 @@ struct fifo_client_handler
/* Info needed by all readers of a FIFO, stored in named shared memory. */
class fifo_shmem_t
{
LONG _nreaders;
public:
int inc_nreaders () { return (int) InterlockedIncrement (&_nreaders); }
int dec_nreaders () { return (int) InterlockedDecrement (&_nreaders); }
};
class fhandler_fifo: public fhandler_base
@ -1342,6 +1347,9 @@ class fhandler_fifo: public fhandler_base
int create_shmem ();
int reopen_shmem ();
int inc_nreaders () { return shmem->inc_nreaders (); }
int dec_nreaders () { return shmem->dec_nreaders (); }
public:
fhandler_fifo ();
bool hit_eof ();