Merge pull request #10304 from kjbracey-arm/equeue_align

equeue: align passed-in buffer
pull/10320/head
Martin Kojtal 2019-04-04 12:42:03 +02:00 committed by GitHub
commit 0b6983730f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 3 deletions

View File

@ -18,9 +18,9 @@
#include "equeue/equeue.h" #include "equeue/equeue.h"
#include <stdlib.h> #include <stdlib.h>
#include <stdint.h>
#include <string.h> #include <string.h>
// calculate the relative-difference between absolute times while // calculate the relative-difference between absolute times while
// correctly handling overflow conditions // correctly handling overflow conditions
static inline int equeue_tickdiff(unsigned a, unsigned b) static inline int equeue_tickdiff(unsigned a, unsigned b)
@ -63,7 +63,11 @@ int equeue_create(equeue_t *q, size_t size)
int equeue_create_inplace(equeue_t *q, size_t size, void *buffer) int equeue_create_inplace(equeue_t *q, size_t size, void *buffer)
{ {
// setup queue around provided buffer // setup queue around provided buffer
q->buffer = buffer; // ensure buffer and size are aligned
q->buffer = (void *)(((uintptr_t) buffer + sizeof(void *) -1) & ~(sizeof(void *) -1));
size -= (char *) q->buffer - (char *) buffer;
size &= ~(sizeof(void *) -1);
q->allocated = 0; q->allocated = 0;
q->npw2 = 0; q->npw2 = 0;
@ -73,7 +77,7 @@ int equeue_create_inplace(equeue_t *q, size_t size, void *buffer)
q->chunks = 0; q->chunks = 0;
q->slab.size = size; q->slab.size = size;
q->slab.data = buffer; q->slab.data = q->buffer;
q->queue = 0; q->queue = 0;
q->tick = equeue_tick(); q->tick = equeue_tick();