From: Jacek Caban Subject: [PATCH 4/9] server: Allow queuing already created async objects. Message-Id: <9dbeee9c-51d5-cb2d-8c2f-01e446e91f40@codeweavers.com> Date: Fri, 10 Feb 2017 16:08:17 +0100 Signed-off-by: Jacek Caban --- server/async.c | 2 +- server/change.c | 2 +- server/device.c | 2 +- server/fd.c | 11 +++++++---- server/file.h | 3 ++- server/mailslot.c | 2 +- server/named_pipe.c | 4 ++-- server/serial.c | 2 +- 8 files changed, 16 insertions(+), 12 deletions(-) diff --git a/server/async.c b/server/async.c index c61b8c6..8ff0a87 100644 --- a/server/async.c +++ b/server/async.c @@ -231,7 +231,7 @@ void free_async_queue( struct async_queue *queue ) release_object( queue ); } -static void queue_async( struct async_queue *queue, struct async *async ) +void queue_async( struct async_queue *queue, struct async *async ) { async->queue = (struct async_queue *)grab_object( queue ); diff --git a/server/change.c b/server/change.c index d7ebf3b..bdc73e1 100644 --- a/server/change.c +++ b/server/change.c @@ -1246,7 +1246,7 @@ DECL_HANDLER(read_directory_changes) return; /* requests don't timeout */ - if (!(async = fd_queue_async( dir->fd, &req->async, NULL, ASYNC_TYPE_WAIT ))) goto end; + if (!(async = fd_queue_async( dir->fd, NULL, &req->async, NULL, ASYNC_TYPE_WAIT ))) goto end; /* assign it once */ if (!dir->filter) diff --git a/server/device.c b/server/device.c index a7dce3b..dbbfb1a 100644 --- a/server/device.c +++ b/server/device.c @@ -475,7 +475,7 @@ static obj_handle_t queue_irp( struct device_file *file, struct irp_call *irp, if (blocking && !(handle = alloc_handle( current->process, irp, SYNCHRONIZE, 0 ))) return 0; - if (!(irp->async = fd_queue_async( file->fd, async_data, irp->iosb, ASYNC_TYPE_WAIT ))) + if (!(irp->async = fd_queue_async( file->fd, NULL, async_data, irp->iosb, ASYNC_TYPE_WAIT ))) { if (handle) close_handle( current->process, handle ); return 0; diff --git a/server/fd.c b/server/fd.c index 732a5b7..086f9ea 100644 --- a/server/fd.c +++ b/server/fd.c @@ -2030,10 +2030,9 @@ void default_poll_event( struct fd *fd, int event ) else if (!fd->inode) set_fd_events( fd, fd->fd_ops->get_poll_events( fd ) ); } -struct async *fd_queue_async( struct fd *fd, const async_data_t *data, struct iosb *iosb, int type ) +struct async *fd_queue_async( struct fd *fd, struct async *async, const async_data_t *data, struct iosb *iosb, int type ) { struct async_queue *queue; - struct async *async; switch (type) { @@ -2054,7 +2053,11 @@ struct async *fd_queue_async( struct fd *fd, const async_data_t *data, struct io assert(0); } - if ((async = create_async( current, queue, data, iosb )) && type != ASYNC_TYPE_WAIT) + if (async) grab_object( async); + else if(!(async = create_async( current, NULL, data, iosb ))) return NULL; + queue_async( queue, async ); + + if (async && type != ASYNC_TYPE_WAIT) { if (!fd->inode) set_fd_events( fd, fd->fd_ops->get_poll_events( fd ) ); @@ -2096,7 +2099,7 @@ void default_fd_queue_async( struct fd *fd, const async_data_t *data, int type, { struct async *async; - if ((async = fd_queue_async( fd, data, NULL, type ))) + if ((async = fd_queue_async( fd, NULL, data, NULL, type ))) { release_object( async ); set_error( STATUS_PENDING ); diff --git a/server/file.h b/server/file.h index c5867a6..30baef4 100644 --- a/server/file.h +++ b/server/file.h @@ -97,7 +97,7 @@ extern int default_fd_signaled( struct object *obj, struct wait_queue_entry *ent extern unsigned int default_fd_map_access( struct object *obj, unsigned int access ); extern int default_fd_get_poll_events( struct fd *fd ); extern void default_poll_event( struct fd *fd, int event ); -extern struct async *fd_queue_async( struct fd *fd, const async_data_t *data, struct iosb *iosb, int type ); +extern struct async *fd_queue_async( struct fd *fd, struct async *async, const async_data_t *data, struct iosb *iosb, int type ); extern void fd_async_wake_up( struct fd *fd, int type, unsigned int status ); extern void fd_reselect_async( struct fd *fd, struct async_queue *queue ); extern obj_handle_t no_fd_read( struct fd *fd, const async_data_t *async, int blocking, file_pos_t pos, @@ -179,6 +179,7 @@ extern struct async_queue *create_async_queue( struct fd *fd ); extern void free_async_queue( struct async_queue *queue ); extern struct async *create_async( struct thread *thread, struct async_queue *queue, const async_data_t *data, struct iosb *iosb ); +extern void queue_async( struct async_queue *queue, struct async *async ); extern void async_set_timeout( struct async *async, timeout_t timeout, unsigned int status ); extern void async_set_result( struct object *obj, unsigned int status, apc_param_t total, client_ptr_t apc, client_ptr_t apc_arg ); diff --git a/server/mailslot.c b/server/mailslot.c index 783b28b..829ed2a 100644 --- a/server/mailslot.c +++ b/server/mailslot.c @@ -332,7 +332,7 @@ static void mailslot_queue_async( struct fd *fd, const async_data_t *data, int t assert(mailslot->obj.ops == &mailslot_ops); - if ((async = fd_queue_async( fd, data, NULL, type ))) + if ((async = fd_queue_async( fd, NULL, data, NULL, type ))) { async_set_timeout( async, mailslot->read_timeout ? mailslot->read_timeout : -1, STATUS_IO_TIMEOUT ); diff --git a/server/named_pipe.c b/server/named_pipe.c index 3245688..5a3b375 100644 --- a/server/named_pipe.c +++ b/server/named_pipe.c @@ -555,7 +555,7 @@ static obj_handle_t pipe_server_flush( struct fd *fd, const async_data_t *async_ if (!pipe_data_remaining( server )) return 0; - if ((async = fd_queue_async( server->fd, async_data, NULL, ASYNC_TYPE_WAIT ))) + if ((async = fd_queue_async( server->fd, NULL, async_data, NULL, ASYNC_TYPE_WAIT ))) { /* there's no unix way to be alerted when a pipe becomes empty, so resort to polling */ if (!server->flush_poll) @@ -602,7 +602,7 @@ static obj_handle_t pipe_server_ioctl( struct fd *fd, ioctl_code_t code, const a { case ps_idle_server: case ps_wait_connect: - if ((async = fd_queue_async( server->ioctl_fd, async_data, NULL, ASYNC_TYPE_WAIT ))) + if ((async = fd_queue_async( server->ioctl_fd, NULL, async_data, NULL, ASYNC_TYPE_WAIT ))) { if (blocking) wait_handle = alloc_handle( current->process, async, SYNCHRONIZE, 0 ); set_server_state( server, ps_wait_open ); diff --git a/server/serial.c b/server/serial.c index 6f9cc24..08bb755 100644 --- a/server/serial.c +++ b/server/serial.c @@ -201,7 +201,7 @@ static void serial_queue_async( struct fd *fd, const async_data_t *data, int typ break; } - if ((async = fd_queue_async( fd, data, NULL, type ))) + if ((async = fd_queue_async( fd, NULL, data, NULL, type ))) { if (timeout) async_set_timeout( async, timeout * -10000, STATUS_TIMEOUT ); release_object( async );