<div dir="ltr"><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"><br></div><div class="gmail_extra"><br><div class="gmail_quote">Richard Palethorpe <span dir="ltr"><<a href="mailto:rpalethorpe@suse.de" target="_blank">rpalethorpe@suse.de</a>></span> wrote:</div><div class="gmail_quote"><span class="gmail-"></span><br><span class="gmail-"></span><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><span class="gmail-">
</span>How about:<br>
<br>
/**<br>
* TST_RETRY_FUNC() - Repeatedly retry a function with an increasing delay.<br>
* @FUNC - The function which will be retried<br>
* @ERET - The value returned from @FUNC on success<br>
*<br>
* This macro will call @FUNC in a loop with a delay between retries. If @FUNC<br>
* returns @ERET then the loop exits. The delay between retries starts at one<br>
* micro second and is then doubled each iteration until it exceeds one second<br>
* (the total time sleeping will be aproximately one second as well). When the<br>
* delay exceeds one second tst_brk() is called.<br>
*/<br></blockquote><div><div style="font-family:arial,helvetica,sans-serif" class="gmail_default"></div><div style="font-family:arial,helvetica,sans-serif" class="gmail_default">I like this description.</div></div><div style="font-family:arial,helvetica,sans-serif" class="gmail_default"></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<span class="gmail-"><br>
> + * @FUNC: the function which will be retried<br>
> + * @ERET: an expected return value from the FUNC<br>
> + */<br>
> +#define TST_RETRY_FUNC(FUNC, ERET) \<br>
> + TST_RETRY_FN_EXP_BACKOFF(FUNC, ERET, 1)<br>
> +<br>
> +#define TST_RETRY_FN_EXP_BACKOFF(FUNC, ERET, MAX_DELAY) \<br>
> +do { int tst_delay = 1; \<br>
> + for (;;) { \<br>
> + typeof(FUNC) ret = FUNC; \<br>
> + if (ret == ERET) \<br>
> + break; \<br>
<br>
</span>Maybe it should return ret somehow?<br></blockquote><div><br></div><div><div style="font-family:arial,helvetica,sans-serif" class="gmail_default">Maybe yes!<br></div><div style="font-family:arial,helvetica,sans-serif" class="gmail_default"><br></div><div style="font-family:arial,helvetica,sans-serif" class="gmail_default">And, if we do that, the macro should probably be rewritten as:<br></div><br></div><div><div style="font-family:arial,helvetica,sans-serif" class="gmail_default">#define TST_RETRY_FN_EXP_BACKOFF(FUNC, ERET, MAX_DELAY) \<br>({ int tst_delay = 1; \<br> for (;;) { \<br> typeof(FUNC) ret = FUNC; \<br> if (ret == ERET) \<br> break; \<br> if (tst_delay < MAX_DELAY * 1000000) { \<br> tst_res(TINFO, \<br> #FUNC" returned %i, retrying" \<br> " in %ius", ret, tst_delay); \<br> usleep(tst_delay); \<br> tst_delay *= 2; \<br> } else { \<br> tst_brk(TBROK, #FUNC" failed"); \<br> } \<br> } \<br> ERET; \<br>})<br></div><br></div></div><br clear="all"><br>-- <br><div class="gmail_signature">Li Wang<br><a href="mailto:liwang@redhat.com" target="_blank">liwang@redhat.com</a></div>
</div></div>