Skip to content

Commit 0b69837

Browse files
authored
Merge pull request #10304 from kjbracey-arm/equeue_align
equeue: align passed-in buffer
2 parents 6081727 + db18c22 commit 0b69837

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

events/equeue/equeue.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818
#include "equeue/equeue.h"
1919

2020
#include <stdlib.h>
21+
#include <stdint.h>
2122
#include <string.h>
2223

23-
2424
// calculate the relative-difference between absolute times while
2525
// correctly handling overflow conditions
2626
static inline int equeue_tickdiff(unsigned a, unsigned b)
@@ -63,7 +63,11 @@ int equeue_create(equeue_t *q, size_t size)
6363
int equeue_create_inplace(equeue_t *q, size_t size, void *buffer)
6464
{
6565
// setup queue around provided buffer
66-
q->buffer = buffer;
66+
// ensure buffer and size are aligned
67+
q->buffer = (void *)(((uintptr_t) buffer + sizeof(void *) -1) & ~(sizeof(void *) -1));
68+
size -= (char *) q->buffer - (char *) buffer;
69+
size &= ~(sizeof(void *) -1);
70+
6771
q->allocated = 0;
6872

6973
q->npw2 = 0;
@@ -73,7 +77,7 @@ int equeue_create_inplace(equeue_t *q, size_t size, void *buffer)
7377

7478
q->chunks = 0;
7579
q->slab.size = size;
76-
q->slab.data = buffer;
80+
q->slab.data = q->buffer;
7781

7882
q->queue = 0;
7983
q->tick = equeue_tick();

0 commit comments

Comments
 (0)