diff --git a/options/internal/include/mlibc/allocator.hpp b/options/internal/include/mlibc/allocator.hpp index 378e6078..2d26160f 100644 --- a/options/internal/include/mlibc/allocator.hpp +++ b/options/internal/include/mlibc/allocator.hpp @@ -2,10 +2,29 @@ #ifndef MLIBC_FRIGG_ALLOC #define MLIBC_FRIGG_ALLOC -#include -#include #include +struct AllocatorLock { + AllocatorLock() + : _futex{0} { } + + AllocatorLock(const AllocatorLock &) = delete; + + AllocatorLock &operator= (const AllocatorLock &) = delete; + + void lock() { + if(__atomic_exchange_n(&_futex, 1, __ATOMIC_ACQUIRE)) + __ensure(!"Implement AllocatorLock slow path"); + } + + void unlock() { + __atomic_store_n(&_futex, 0, __ATOMIC_RELEASE); + } + +private: + int _futex; +}; + struct VirtualAllocator { public: uintptr_t map(size_t length); @@ -13,7 +32,7 @@ public: void unmap(uintptr_t address, size_t length); }; -typedef frg::slab_allocator MemoryAllocator; +typedef frg::slab_allocator MemoryAllocator; MemoryAllocator &getAllocator(); diff --git a/options/posix/generic/environment.cpp b/options/posix/generic/environment.cpp index cee4c645..faa6ae0d 100644 --- a/options/posix/generic/environment.cpp +++ b/options/posix/generic/environment.cpp @@ -100,7 +100,7 @@ int unsetenv(const char *name) { update_env_copy(); auto k = find_env_index(name); - assert(k != size_t(-1)); + FRG_ASSERT(k != size_t(-1)); // Last pointer is always null. __ensure(global_env_vector.size() >= 2 && !global_env_vector.back());