[PATCH v8 1/7] server: Generalise async completion callback to be called on synchronous failure.

Jinoh Kang jinoh.kang.kr at gmail.com
Wed Mar 23 12:25:04 CDT 2022


Today, async_set_completion_callback() is used to register a function
that is called when the async I/O is completed.  It is assumed that the
async will eventually be queued when such callback is registered.

However, this incurs extra complexity in future code that needs the
completion logic to be invoked even if the async is never actually
queued (e.g. when the I/O failed synchronously before async_handoff).

Generalise async completion callback by calling it in async_handoff()
when the I/O status indicates failure.

Signed-off-by: Jinoh Kang <jinoh.kang.kr at gmail.com>
---

Notes:
    v6 -> v7: new patch
    v7 -> v8: edit commit message as per feedback (thanks zf)

 server/async.c | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/server/async.c b/server/async.c
index a92798fcd39..a4c9090fa73 100644
--- a/server/async.c
+++ b/server/async.c
@@ -322,6 +322,13 @@ void async_wake_obj( struct async *async )
     }
 }
 
+static void async_call_completion_callback( struct async *async )
+{
+    if (async->completion_callback)
+        async->completion_callback( async->completion_callback_private );
+    async->completion_callback = NULL;
+}
+
 /* return async object status and wait handle to client */
 obj_handle_t async_handoff( struct async *async, data_size_t *result, int force_blocking )
 {
@@ -363,6 +370,8 @@ obj_handle_t async_handoff( struct async *async, data_size_t *result, int force_
 
     if (!async->pending && NT_ERROR( get_error() ))
     {
+        async_call_completion_callback( async );
+
         close_handle( async->thread->process, async->wait_handle );
         async->wait_handle = 0;
         return 0;
@@ -528,9 +537,7 @@ void async_set_result( struct object *obj, unsigned int status, apc_param_t tota
             wake_up( &async->obj, 0 );
         }
 
-        if (async->completion_callback)
-            async->completion_callback( async->completion_callback_private );
-        async->completion_callback = NULL;
+        async_call_completion_callback( async );
 
         if (async->queue)
         {
-- 
2.34.1




More information about the wine-devel mailing list