mirror of https://github.com/ARMmbed/mbed-os.git
equeue: align passed-in buffer
Make equeue_create_inplace align the passed-in buffer and size to sizeof(void *). Really we should be aiming to align more for ARM, as blocks should be 8-byte aligned, but the internal heap mechanisms only work to 4-byte alignment at the moment. More work would be needed to ensure 8-byte alignment of allocated blocks.pull/10304/head
parent
040388370f
commit
db18c2252e
|
@ -18,9 +18,9 @@
|
|||
#include "equeue/equeue.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
|
||||
// calculate the relative-difference between absolute times while
|
||||
// correctly handling overflow conditions
|
||||
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)
|
||||
{
|
||||
// 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->npw2 = 0;
|
||||
|
@ -73,7 +77,7 @@ int equeue_create_inplace(equeue_t *q, size_t size, void *buffer)
|
|||
|
||||
q->chunks = 0;
|
||||
q->slab.size = size;
|
||||
q->slab.data = buffer;
|
||||
q->slab.data = q->buffer;
|
||||
|
||||
q->queue = 0;
|
||||
q->tick = equeue_tick();
|
||||
|
|
Loading…
Reference in New Issue