sos-os / kernel

The Stupid Operating System
Apache License 2.0
264 stars 16 forks source link

Allocators can deallocate a block without mutable references #64

Closed hawkw closed 7 years ago

hawkw commented 7 years ago

Needed for allocation handle implementation for the heap allocator.

See TODO here:

        // TODO: need a way to mutably access the parent allocator...
        // unsafe { self.allocator.deallocate(*self.ptr, self.order, self.size)
hawkw commented 7 years ago

I think that, since we're using the RFC 1396 allocator API (see #72), which requires allocation & deallocation to take an &mut self, the right way to go about this is to make a newtype for Mutex<Allocator>/Mutex<Option<Allocator>> for our global allocators. The borrowed handles can take a reference to that, rather than to the Allocator instance itself.

Although I suspect @cjm00 will hate me for this, he global allocator newtype can also implement Deref and DerefMut by waiting to lock the allocator.