Cygwin: serial: use per call OVERLAPPED structs

Sharing the OVERLAPPED struct and event object in there between
read and select calls in the fhandler might have been a nice
optimization way back when, but it is a dangerous, not thread-safe
approach.  Fix this by creating per-fhandler, per-call OVERLAPPED
structs and event objects on demand.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
This commit is contained in:
Corinna Vinschen
2020-03-23 21:06:00 +01:00
parent a1f0585454
commit 2a4b1de773
4 changed files with 56 additions and 81 deletions

View File

@@ -9,6 +9,14 @@ details. */
#ifndef _SELECT_H_
#define _SELECT_H_
struct fh_select_data_serial
{
DWORD event;
OVERLAPPED ov;
fh_select_data_serial () : event (0) { memset (&ov, 0, sizeof ov); }
};
struct select_record
{
int fd;
@@ -25,6 +33,13 @@ struct select_record
int (*verify) (select_record *, fd_set *, fd_set *, fd_set *);
void (*cleanup) (select_record *, class select_stuff *);
struct select_record *next;
/* If an fhandler type needs per-fhandler, per-select data, this union
is the place to add it. First candidate: fhandler_serial. */
union
{
fh_select_data_serial *fh_data_serial;
void *fh_data_union; /* type-agnostic placeholder for constructor */
};
void set_select_errno () {__seterrno (); thread_errno = errno;}
int saw_error () {return thread_errno;}
select_record (int): next (NULL) {}
@@ -34,7 +49,7 @@ struct select_record
except_ready (false), read_selected (false), write_selected (false),
except_selected (false), except_on_write (false),
startup (NULL), peek (NULL), verify (NULL), cleanup (NULL),
next (NULL) {}
next (NULL), fh_data_union (NULL) {}
#ifdef DEBUGGING
void dump_select_record ();
#endif
@@ -83,6 +98,10 @@ public:
bool always_ready, windows_used;
select_record start;
/* If an fhandler type needs a singleton per-select datastructure for all
its objects in the descriptor lists, here's the place to be. This is
mainly used to maintain a single thread for all fhandlers of a single
type in the descriptor lists. */
select_pipe_info *device_specific_pipe;
select_pipe_info *device_specific_ptys;
select_fifo_info *device_specific_fifo;