Skip to content

Commit 9c1a363

Browse files
stoeckmannlucasdemarchi
authored andcommitted
util: Use local variable in get_backoff_delta_msec
This might make the code easier to read. Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org> Link: #377 Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
1 parent 2537c17 commit 9c1a363

1 file changed

Lines changed: 13 additions & 11 deletions

File tree

shared/util.c

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -536,32 +536,34 @@ int sleep_until_msec(unsigned long long msec)
536536
unsigned long long get_backoff_delta_msec(unsigned long long tend,
537537
unsigned long long *delta)
538538
{
539-
unsigned long long t;
539+
unsigned long long d, t;
540540

541+
d = *delta;
541542
t = now_msec();
542543

543544
if (tend <= t) {
544545
/* Timeout already reached */
545-
*delta = 0;
546+
d = 0;
546547
} else {
547548
const unsigned long long limit = tend - t;
548549

549550
/* Double the amount of requested delta, if possible */
550-
if (!*delta)
551-
*delta = 1;
552-
else if (umulll_overflow(*delta, 2, delta))
553-
*delta = ULLONG_MAX;
551+
if (!d)
552+
d = 1;
553+
else if (umulll_overflow(d, 2, &d))
554+
d = ULLONG_MAX;
554555

555556
/* Search for a fitting backoff delta */
556-
while (*delta > limit)
557-
*delta >>= 1;
557+
while (d > limit)
558+
d >>= 1;
558559

559560
/* If none found, use maximum wait time */
560-
if (!*delta)
561-
*delta = limit;
561+
if (!d)
562+
d = limit;
562563
}
563564

564-
return t + *delta;
565+
*delta = d;
566+
return t + d;
565567
}
566568

567569
unsigned long long now_usec(void)

0 commit comments

Comments
 (0)