Skip to content

Add static version of queue #1670

Open
Open
@daveythacher

Description

@daveythacher

I was looking into the queue API and I noticed that it works off the heap. It should be possible to implement this as static?

void queue_init_with_spinlock(queue_t *q, uint element_size, uint element_count, uint spinlock_num) {
lock_init(&q->core, spinlock_num);
q->data = (uint8_t *)calloc(element_count + 1, element_size);
q->element_count = (uint16_t)element_count;
q->element_size = (uint16_t)element_size;
q->wptr = 0;
q->rptr = 0;
}

It is a little more risky, but for people that do not want to use heap they are probably stuck with that.

void static_queue_init_with_spinlock(queue_t *q, uint element_size, uint element_count, uint spinlock_num, uint8_t *storage) {
    lock_init(&q->core, spinlock_num);
    q->data = storage;
    q->element_count = (uint16_t)element_count;
    q->element_size = (uint16_t)element_size;
    q->wptr = 0;
    q->rptr = 0;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions