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

Victor Toso victortoso at redhat.com
Fri Aug 2 09:28:44 UTC 2019


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 at redhat.com>
Acked-by: Victor Toso <victortoso at redhat.com>
> ---
>  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 at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/spice-devel
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <https://lists.freedesktop.org/archives/spice-devel/attachments/20190802/87c9f7e3/attachment.sig>


More information about the Spice-devel mailing list