Re: [PATCH spice-server 02/13] char-device: Pull more code into red_char_device_send_to_client_tokens_absorb

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, May 30, 2019 at 03:22:43PM +0100, Frediano Ziglio wrote:
> The 2 callers red_char_device_send_to_client_tokens_set and
> red_char_device_send_to_client_tokens_add are doing mostly
> the same thing so put common code to
> red_char_device_send_to_client_tokens_absorb.
> 
> Signed-off-by: Frediano Ziglio <fziglio@xxxxxxxxxx>
Acked-by: Victor Toso <victortoso@xxxxxxxxxx>
> ---
>  server/char-device.c | 42 +++++++++++++++++++-----------------------
>  1 file changed, 19 insertions(+), 23 deletions(-)
> 
> diff --git a/server/char-device.c b/server/char-device.c
> index 0f6a29d6f..89581ea42 100644
> --- a/server/char-device.c
> +++ b/server/char-device.c
> @@ -377,10 +377,24 @@ static void red_char_device_client_send_queue_push(RedCharDeviceClient *dev_clie
>      }
>  }
>  
> -static void red_char_device_send_to_client_tokens_absorb(RedCharDeviceClient *dev_client,
> -                                                         uint32_t tokens)
> +static void
> +red_char_device_send_to_client_tokens_absorb(RedCharDevice *dev,
> +                                             RedClient *client,
> +                                             uint32_t tokens,
> +                                             bool reset)
>  {
> -    RedCharDevice *dev = dev_client->dev;
> +    RedCharDeviceClient *dev_client;
> +
> +    dev_client = red_char_device_client_find(dev, client);
> +
> +    if (!dev_client) {
> +        spice_error("client wasn't found dev %p client %p", dev, client);
> +        return;
> +    }
> +
> +    if (reset) {
> +        dev_client->num_send_tokens = 0;
> +    }
>      dev_client->num_send_tokens += tokens;
>  
>      if (g_queue_get_length(dev_client->send_queue)) {
> @@ -403,32 +417,14 @@ void red_char_device_send_to_client_tokens_add(RedCharDevice *dev,
>                                                 RedClient *client,
>                                                 uint32_t tokens)
>  {
> -    RedCharDeviceClient *dev_client;
> -
> -    dev_client = red_char_device_client_find(dev, client);
> -
> -    if (!dev_client) {
> -        spice_error("client wasn't found dev %p client %p", dev, client);
> -        return;
> -    }
> -    red_char_device_send_to_client_tokens_absorb(dev_client, tokens);
> +    red_char_device_send_to_client_tokens_absorb(dev, client, tokens, false);
>  }
>  
>  void red_char_device_send_to_client_tokens_set(RedCharDevice *dev,
>                                                 RedClient *client,
>                                                 uint32_t tokens)
>  {
> -    RedCharDeviceClient *dev_client;
> -
> -    dev_client = red_char_device_client_find(dev, client);
> -
> -    if (!dev_client) {
> -        spice_error("client wasn't found dev %p client %p", dev, client);
> -        return;
> -    }
> -
> -    dev_client->num_send_tokens = 0;
> -    red_char_device_send_to_client_tokens_absorb(dev_client, tokens);
> +    red_char_device_send_to_client_tokens_absorb(dev, client, tokens, true);
>  }
>  
>  /**************************
> -- 
> 2.20.1
> 
> _______________________________________________
> Spice-devel mailing list
> Spice-devel@xxxxxxxxxxxxxxxxxxxxx
> https://lists.freedesktop.org/mailman/listinfo/spice-devel

Attachment: signature.asc
Description: PGP signature

_______________________________________________
Spice-devel mailing list
Spice-devel@xxxxxxxxxxxxxxxxxxxxx
https://lists.freedesktop.org/mailman/listinfo/spice-devel

[Index of Archives]     [Linux Virtualization]     [Linux Virtualization]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]     [Monitors]