From 0e0834ae92291e9857ed01f3cb116240abda642b Mon Sep 17 00:00:00 2001 From: Jacek Caban Date: Mon, 26 Jun 2017 12:17:51 +0200 Subject: [PATCH] server: Close async wait handle when wait is satisfied. Signed-off-by: Jacek Caban Signed-off-by: Alexandre Julliard --- dlls/ntdll/file.c | 1 - server/async.c | 21 ++++++++++++++++----- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/dlls/ntdll/file.c b/dlls/ntdll/file.c index fd5a690b7dd..5329c79f2c3 100644 --- a/dlls/ntdll/file.c +++ b/dlls/ntdll/file.c @@ -589,7 +589,6 @@ static NTSTATUS server_read_file( HANDLE handle, HANDLE event, PIO_APC_ROUTINE a { NtWaitForSingleObject( wait_handle, (options & FILE_SYNCHRONOUS_IO_ALERT), NULL ); status = io->u.Status; - NtClose( wait_handle ); } return status; diff --git a/server/async.c b/server/async.c index 4c6c6a9586c..f50cdc5a45a 100644 --- a/server/async.c +++ b/server/async.c @@ -53,6 +53,7 @@ struct async static void async_dump( struct object *obj, int verbose ); static int async_signaled( struct object *obj, struct wait_queue_entry *entry ); +static void async_satisfied( struct object * obj, struct wait_queue_entry *entry ); static void async_destroy( struct object *obj ); static const struct object_ops async_ops = @@ -63,7 +64,7 @@ static const struct object_ops async_ops = add_queue, /* add_queue */ remove_queue, /* remove_queue */ async_signaled, /* signaled */ - no_satisfied, /* satisfied */ + async_satisfied, /* satisfied */ no_signal, /* signal */ no_get_fd, /* get_fd */ no_map_access, /* map_access */ @@ -132,6 +133,19 @@ static int async_signaled( struct object *obj, struct wait_queue_entry *entry ) return async->signaled; } +static void async_satisfied( struct object *obj, struct wait_queue_entry *entry ) +{ + struct async *async = (struct async *)obj; + assert( obj->ops == &async_ops ); + + /* close wait handle here to avoid extra server round trip */ + if (async->wait_handle) + { + close_handle( async->thread->process, async->wait_handle ); + async->wait_handle = 0; + } +} + static void async_destroy( struct object *obj ) { struct async *async = (struct async *)obj; @@ -300,7 +314,6 @@ struct async *create_request_async( struct thread *thread, const async_data_t *d /* return async object status and wait handle to client */ obj_handle_t async_handoff( struct async *async, int success ) { - obj_handle_t handle; if (!success) { close_handle( async->thread->process, async->wait_handle ); @@ -313,10 +326,8 @@ obj_handle_t async_handoff( struct async *async, int success ) close_handle( async->thread->process, async->wait_handle); async->wait_handle = 0; } - handle = async->wait_handle; - async->wait_handle = 0; set_error( STATUS_PENDING ); - return handle; + return async->wait_handle; } /* set the timeout of an async operation */