mirror of
https://git.rwth-aachen.de/acs/public/villas/node/
synced 2025-03-09 00:00:00 +01:00
Ceil queue size to power of 2
This commit is contained in:
parent
8e4eeef3f1
commit
66d184589b
2 changed files with 5 additions and 8 deletions
|
@ -62,12 +62,6 @@
|
|||
/** Check if the number is a power of 2 */
|
||||
#define IS_POW2(x) (((x) != 0) && !((x) & ((x) - 1)))
|
||||
|
||||
/** Get nearest up-rounded power of 2 */
|
||||
#define LOG2_CEIL(x) (1 << (log2i((x) - 1) + 1))
|
||||
|
||||
/** Check if the number is a power of 2 */
|
||||
#define IS_POW2(x) (((x) != 0) && !((x) & ((x) - 1)))
|
||||
|
||||
/** Calculate the number of elements in an array. */
|
||||
#define ARRAY_LEN(a) ( sizeof (a) / sizeof (a)[0] )
|
||||
|
||||
|
|
|
@ -39,8 +39,11 @@ int queue_init(struct queue *q, size_t size, const struct memtype *mem)
|
|||
{
|
||||
|
||||
/* Queue size must be 2 exponent */
|
||||
if (!IS_POW2(size))
|
||||
return -1;
|
||||
if (!IS_POW2(size)) {
|
||||
size_t old_size = size;
|
||||
size = LOG2_CEIL(size);
|
||||
warn("A queue size was changed from %lu to %lu", old_size, size);
|
||||
}
|
||||
|
||||
q->mem = mem;
|
||||
q->buffer_mask = size - 1;
|
||||
|
|
Loading…
Add table
Reference in a new issue