Re: [PATCH v4b] Add functions for handling exponential backoff loops.

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

 



On Fri, Apr 15, 2016 at 12:27:20PM +0200, Andrea Bolognani wrote:
> Having two "whiles" like that looks kinda off... I'd rather
> have something like
> 
>   while (!virTimeBackOffHasExpired(&timeout))
> 
> or preferably something better than what I can come up with :)

The trouble is the function doesn't exactly do that.  It also
performs the delay.

...Wait (suggested elsewhere) was a better idea.

> > +/**
> > + * virTimeBackOffWhile
> > + * @var: Timeout variable (with type virTimeBackOffVar *).
> > + *
> > + * You must initialize @var first by calling the following function,
> > + * which also starts the timer:
> > + *
> > + * if (virTimeBackOffStart(&var, first, timeout) < 0) {
> > + *   // handle errors
> > + * }
> > + *
> > + * Then you use a while loop:
> > + *
> > + * while (virTimeBackOffWhile(&var)) {
> > + *   //...
> > + * }
> > + *
> > + * The while loop that runs the body of the code repeatedly, with an
> > + * exponential backoff.  It first waits for first milliseconds, then
> > + * runs the body, then waits for 2*first ms, then runs the body again.
> > + * Then 4*first ms, and so on.
> > + *
> > + * When timeout milliseconds is reached, the while loop ends.
> > + *
> > + * The body should use "break" or "goto" when whatever condition it is
> > + * testing for succeeds (or there is an unrecoverable error).
> > + */
> > +bool virTimeBackOffWhile(virTimeBackOffVar *var);
> > +
> >  #endif
> 
> API documentation should live in the .c file, like you did
> with virTimeBackOffStart(). I guess it's just a consequence
> of the "a" implementation using a macro for this part :)

OK.

Rich.

-- 
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
virt-df lists disk usage of guests without needing to install any
software inside the virtual machine.  Supports Linux and Windows.
http://people.redhat.com/~rjones/virt-df/

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]