[libc-commits] [libc] [libc] make integration test malloc work properly when threaded (PR #151622)
Joseph Huber via libc-commits
libc-commits at lists.llvm.org
Fri Aug 1 08:15:38 PDT 2025
================
@@ -65,14 +65,18 @@ int atexit(void (*func)(void)) { return LIBC_NAMESPACE::atexit(func); }
static constexpr uint64_t MEMORY_SIZE = 16384;
static uint8_t memory[MEMORY_SIZE];
-static uint8_t *ptr = memory;
+static LIBC_NAMESPACE::cpp::Atomic<size_t> used = 0;
extern "C" {
+// For simple test purposes.
void *malloc(size_t s) {
- void *mem = ptr;
- ptr += s;
- return static_cast<uint64_t>(ptr - memory) >= MEMORY_SIZE ? nullptr : mem;
+ constexpr size_t MAX_ALIGNMENT = alignof(long double);
+ s += (-s) & (MAX_ALIGNMENT - 1); // Align to max alignment.
+ auto res = used.fetch_add(s);
----------------
jhuber6 wrote:
Specify relaxed ordering, this is completely wait-free and has no ordering constraints.
https://github.com/llvm/llvm-project/pull/151622
More information about the libc-commits
mailing list