embeddedartistry / libmemory

Embedded systems memory management library. Implementations for malloc(), free(), and other useful memory management functions
https://embeddedartistry.com
MIT License
216 stars 44 forks source link

need to add a locking variant #41

Closed phillipjohnston closed 4 years ago

phillipjohnston commented 5 years ago

malloc/free: need to add a locking variant. Or CAS version. I don't believe the freelist is threadsafe.

phillipjohnston commented 4 years ago

Atomic CAS would be a nice implementation to have, although you'd need some way to say "thread sleep" as a primitive that can be overridden. Another approach would be to follow the newlib/picolibc approach and define __malloc_lock() and __malloc_unlock() stubs that can be weakly defined and overridden for a specific RTOS. We can provide example implementations in this repo for common RTOSes.

phillipjohnston commented 4 years ago

Thinking on this more, I like weakly defined __malloc_lock() and __malloc_unlock() stubs that default to no-ops.