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

Frediano Ziglio fziglio at redhat.com
Thu Aug 1 16:21:19 UTC 2019


ping

> 
> ping
> 
> > 
> > ping
> > 
> > > 
> > > ping
> > > 
> > > > 
> > > > ping
> > > > 
> > > > > 
> > > > > 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>
> > > > > ---
> > > > >  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);
> > > > >  }
> > > > >  
> > > > >  /**************************
> _______________________________________________
> 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