[Spice-devel] [PATCH spice-server 08/10] red-channel-client: Simplify red_channel_client_wait_pipe_item_sent loop

Christophe Fergeau cfergeau at redhat.com
Mon Sep 11 15:52:57 UTC 2017


On Mon, Sep 11, 2017 at 11:15:45AM +0100, Frediano Ziglio wrote:
> Avoid repeating the same code twice.
> red_channel_client_receive and red_channel_client_send already
> check if client is blocked, no need to check manually.
> Put the check for the loop inside it to avoid this duplication.

Not immediatly obvious that red_channel_client_receive and
red_channel_client_send are checking if the client is blocked, I would
detail it a bit more in the commit log.

Christophe

> 
> Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
> ---
>  server/red-channel-client.c | 15 ++++++---------
>  1 file changed, 6 insertions(+), 9 deletions(-)
> 
> diff --git a/server/red-channel-client.c b/server/red-channel-client.c
> index de3ac27cb..f0a25ecfd 100644
> --- a/server/red-channel-client.c
> +++ b/server/red-channel-client.c
> @@ -1781,18 +1781,15 @@ bool red_channel_client_wait_pipe_item_sent(RedChannelClient *rcc,
>      red_pipe_item_ref(&mark_item->base);
>      red_channel_client_pipe_add_after_pos(rcc, &mark_item->base, item_pos);
>  
> -    if (red_channel_client_is_blocked(rcc)) {
> -        red_channel_client_receive(rcc);
> -        red_channel_client_send(rcc);
> -    }
> -    red_channel_client_push(rcc);
> -
> -    while (mark_item->item_in_pipe &&
> -           (timeout == -1 || spice_get_monotonic_time_ns() < end_time)) {
> -        usleep(CHANNEL_BLOCKED_SLEEP_DURATION);
> +    for (;;) {
>          red_channel_client_receive(rcc);
>          red_channel_client_send(rcc);
>          red_channel_client_push(rcc);
> +        if (!mark_item->item_in_pipe ||
> +            (timeout != -1 && spice_get_monotonic_time_ns() >= end_time)) {
> +            break;
> +        }
> +        usleep(CHANNEL_BLOCKED_SLEEP_DURATION);
>      }
>  
>      item_in_pipe = mark_item->item_in_pipe;
> -- 
> 2.13.5
> 
> _______________________________________________
> Spice-devel mailing list
> Spice-devel at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/spice-devel


More information about the Spice-devel mailing list