In qemu-nbd and other NBD server setups where parallel clients are supported, it is common that the caller will re-register the same callback function as long as it has not reached its limit on simultaneous clients. In that case, there is no need to tear down and reinstall GSource watches in the GMainContext.
In practice, all existing callers currently pass NULL for notify, and no caller ever changes context across calls (for async uses, either the caller consistently uses qio_net_listener_set_client_func_full with the same context, or the caller consistently uses only qio_net_listener_set_client_func which always uses the global context); but the time spent checking these two fields in addition to the more important func and data is still less than the savings of not churning through extra GSource manipulations when the result will be unchanged. Signed-off-by: Eric Blake <[email protected]> Reviewed-by: Daniel P. Berrangé <[email protected]> --- v2: move later in series, also ensure notify and context are the same v3: rebase to mutex, R-b kept --- io/net-listener.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/io/net-listener.c b/io/net-listener.c index f70acdfc5ce..93100a2d253 100644 --- a/io/net-listener.c +++ b/io/net-listener.c @@ -169,6 +169,11 @@ void qio_net_listener_set_client_func_full(QIONetListener *listener, size_t i; QEMU_LOCK_GUARD(&listener->lock); + if (listener->io_func == func && listener->io_data == data && + listener->io_notify == notify && listener->context == context) { + return; + } + trace_qio_net_listener_unwatch(listener, listener->io_func, listener->context, "set_client_func"); -- 2.51.1
