raspberrypi / pico-sdk

BSD 3-Clause "New" or "Revised" License
3.25k stars 838 forks source link

#1670 adding static queue methods #1673

Open daveythacher opened 3 months ago

daveythacher commented 3 months ago

Adding static_queue_init and static_queue_init_spinlock. These accept a pointer to a static storage array. This allows using the queue API without calloc. Added null checks to queue logic also.

No testing performed.

peterharperuk commented 3 months ago

Looks ok. We might want to protect queue_free so it does nothing if it memory was not allocated on the heap? And maybe add an example, although you can leave that to us.

daveythacher commented 3 months ago

Queue free is a good point. Part of me wants to create a new type which forces a duplication of the API. Part of me says we could add a field to the queue structure. Overall I think we could point out in the documentation or example that queue free is not required for static queues. This is ambiguous, which can be problematic.

peterharperuk commented 3 months ago

It might be possible to assert the memory is in the heap? But you can leave queue_free as it is for now.

daveythacher commented 3 months ago

Any objections to removing the heap completely? (Probably more of a question for version 2.0 of the SDK.)

peterharperuk commented 3 months ago

I think as much as we'd like to remove stuff we don't like, we're stuck with it for the time being.