On entry to all calls we currently set the error context in thread-local data. This is somewhat non-trivial, and is wasted effort if set_error is never called. Avoid this if the call guarantees never to call set_error. --- generator/generator | 24 +++++++++++++++--------- lib/aio.c | 12 ++++++------ 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/generator/generator b/generator/generator index f0de6b0..cdae440 100755 --- a/generator/generator +++ b/generator/generator @@ -814,6 +814,11 @@ type call = { * field and does nothing else with the handle. *) is_locked : bool; + (* Most functions can call set_error. For functions which are + * {b guaranteed} never to do that we can save a bit of time by + * setting this to false. + *) + can_set_error : bool; } and arg = | ArrayAndLen of arg * string (* array + number of entries *) @@ -847,7 +852,7 @@ and ret = let default_call = { args = []; ret = RErr; shortdesc = ""; longdesc = ""; - is_locked = true } + is_locked = true; can_set_error = true } (* Calls. * @@ -1679,7 +1684,7 @@ connection is writable."; "aio_is_created", { default_call with - args = []; ret = RBool; is_locked = false; + args = []; ret = RBool; is_locked = false; can_set_error = false; shortdesc = "check if the connection has just been created"; longdesc = "\ Return true if this connection has just been created. This @@ -1690,7 +1695,7 @@ by calling functions such as C<nbd_aio_connect>."; "aio_is_connecting", { default_call with - args = []; ret = RBool; is_locked = false; + args = []; ret = RBool; is_locked = false; can_set_error = false; shortdesc = "check if the connection is connecting or handshaking"; longdesc = "\ Return true if this connection is connecting to the server @@ -1701,7 +1706,7 @@ issue commands (see C<nbd_aio_is_ready>)."; "aio_is_ready", { default_call with - args = []; ret = RBool; is_locked = false; + args = []; ret = RBool; is_locked = false; can_set_error = false; shortdesc = "check if the connection is in the ready state"; longdesc = "\ Return true if this connection is connected to the NBD server, @@ -1712,7 +1717,7 @@ issue commands."; "aio_is_processing", { default_call with - args = []; ret = RBool; is_locked = false; + args = []; ret = RBool; is_locked = false; can_set_error = false; shortdesc = "check if the connection is processing a command"; longdesc = "\ Return true if this connection is connected to the NBD server, @@ -1726,7 +1731,7 @@ is processing them), but libnbd is not processing them."; "aio_is_dead", { default_call with - args = []; ret = RBool; is_locked = false; + args = []; ret = RBool; is_locked = false; can_set_error = false; shortdesc = "check if the connection is dead"; longdesc = "\ Return true if the connection has encountered a fatal @@ -1736,7 +1741,7 @@ There is no way to recover a handle from the dead state."; "aio_is_closed", { default_call with - args = []; ret = RBool; is_locked = false; + args = []; ret = RBool; is_locked = false; can_set_error = false; shortdesc = "check if the connection is closed"; longdesc = "\ Return true if the connection has closed. There is no way to @@ -2661,7 +2666,7 @@ let generate_lib_unlocked_h () = * grab the thread mutex (lock) and do logging. *) let generate_lib_api_c () = - let print_wrapper (name, {args; ret; is_locked}) = + let print_wrapper (name, {args; ret; is_locked; can_set_error}) = (match ret with | RBool | RErr @@ -2687,7 +2692,8 @@ let generate_lib_api_c () = pr "\n"; if is_locked then pr " pthread_mutex_lock (&h->lock);\n"; - pr " nbd_internal_reset_error (\"nbd_%s\");\n" name; + if can_set_error then + pr " nbd_internal_reset_error (\"nbd_%s\");\n" name; pr " ret = nbd_unlocked_%s (h" name; let argnames = List.flatten (List.map name_of_arg args) in List.iter (pr ", %s") argnames; diff --git a/lib/aio.c b/lib/aio.c index 65b1ef3..9e0db68 100644 --- a/lib/aio.c +++ b/lib/aio.c @@ -48,7 +48,7 @@ nbd_unlocked_aio_notify_write (struct nbd_handle *h) return nbd_internal_run (h, notify_write); } -/* NB: is_locked = false. */ +/* NB: is_locked = false, can_set_error = false. */ int nbd_unlocked_aio_is_created (struct nbd_handle *h) { @@ -73,7 +73,7 @@ is_connecting_group (enum state_group group) } } -/* NB: is_locked = false. */ +/* NB: is_locked = false, can_set_error = false. */ int nbd_unlocked_aio_is_connecting (struct nbd_handle *h) { @@ -82,7 +82,7 @@ nbd_unlocked_aio_is_connecting (struct nbd_handle *h) return is_connecting_group (group); } -/* NB: is_locked = false. */ +/* NB: is_locked = false, can_set_error = false. */ int nbd_unlocked_aio_is_ready (struct nbd_handle *h) { @@ -103,7 +103,7 @@ is_processing_group (enum state_group group) } } -/* NB: is_locked = false. */ +/* NB: is_locked = false, can_set_error = false. */ int nbd_unlocked_aio_is_processing (struct nbd_handle *h) { @@ -112,14 +112,14 @@ nbd_unlocked_aio_is_processing (struct nbd_handle *h) return is_processing_group (group); } -/* NB: is_locked = false. */ +/* NB: is_locked = false, can_set_error = false. */ int nbd_unlocked_aio_is_dead (struct nbd_handle *h) { return h->state == STATE_DEAD; } -/* NB: is_locked = false. */ +/* NB: is_locked = false, can_set_error = false. */ int nbd_unlocked_aio_is_closed (struct nbd_handle *h) { -- 2.21.0