#include <assert.h>
#include <stdlib.h>
-static inline int divide_rounding_upwards(int dividend, int divisor)
+static inline int divide_rounding_upwards_or_inf(int dividend, int divisor)
{
- return (dividend + (divisor - 1)) / (divisor ?: 1);
+ if (divisor == 0)
+ return -1; // QoS interprets -1 as infinite
+
+ return (dividend + (divisor - 1)) / divisor;
}
static inline int sort_by_count(const void *vlhs, const void *vrhs)
{
/* round upwards so that it's never 0, to give all clients a chance
* to log at least something (so a developer can tell it's alive) */
- const int equal_limit_for_everybody = divide_rounding_upwards(qos->max_throughput, count);
+ const int equal_limit_for_everybody = divide_rounding_upwards_or_inf(qos->max_throughput, count);
for (int i = 0; i < count; ++i)
infos[i].count = equal_limit_for_everybody;
-- count_above_threshold;
}
- const int higher_threshold = divide_rounding_upwards(remaining_throughput, count_above_threshold);
+ const int higher_threshold = divide_rounding_upwards_or_inf(remaining_throughput, count_above_threshold);
for (int i = 0; i < count; ++i)
if (infos[i].count >= equal_threshold)
infos[i].count = higher_threshold;
++ below_current_threshold;
}
prev_threshold = threshold;
- threshold = divide_rounding_upwards(remaining_throughput, count_above_threshold);
+ threshold = divide_rounding_upwards_or_inf(remaining_throughput, count_above_threshold);
} while (below_current_threshold > 0);
for (int i = 0; i < count; ++i)