mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-05 02:38:31 +00:00
Introduce ctl::set and ctl::map
We now have a C++ red-black tree implementation that implements standard template library compatible APIs while compiling 10x faster than libcxx. It's not as beautiful as the red-black tree implementation in Plinko but this will get the job done and the test proves it upholds all invariants This change also restores CheckForMemoryLeaks() support and fixes a real actual bug I discovered with Doug Lea's dlmalloc_inspect_all() function.
This commit is contained in:
parent
388e236360
commit
c4c812c154
45 changed files with 2358 additions and 135 deletions
1
third_party/dlmalloc/README.cosmo
vendored
1
third_party/dlmalloc/README.cosmo
vendored
|
@ -9,6 +9,7 @@ LICENSE
|
|||
|
||||
LOCAL CHANGES
|
||||
|
||||
- Fix bug in dlmalloc_inspect_all()
|
||||
- Define dlmalloc_requires_more_vespene_gas()
|
||||
- Make dlmalloc scalable using sched_getcpu()
|
||||
- Use faster two power roundup for memalign()
|
||||
|
|
4
third_party/dlmalloc/dlmalloc.c
vendored
4
third_party/dlmalloc/dlmalloc.c
vendored
|
@ -25,6 +25,7 @@
|
|||
#include "third_party/dlmalloc/vespene.internal.h"
|
||||
#include "libc/thread/tls.h"
|
||||
#include "libc/intrin/kprintf.h"
|
||||
#include "libc/intrin/kprintf.h"
|
||||
#include "third_party/nsync/mu.h"
|
||||
|
||||
#if !IsTiny()
|
||||
|
@ -1221,7 +1222,8 @@ static void internal_inspect_all(mstate m,
|
|||
}
|
||||
}
|
||||
if (start < (void*)next) /* skip if all space is bookkeeping */
|
||||
handler(start, next, used, arg);
|
||||
if (start != s) /* [jart] fix phantom alloc bug w/ mspace+mmap */
|
||||
handler(start, next, used, arg);
|
||||
if (q == top)
|
||||
break;
|
||||
q = next;
|
||||
|
|
25
third_party/dlmalloc/threaded.inc
vendored
25
third_party/dlmalloc/threaded.inc
vendored
|
@ -25,6 +25,8 @@
|
|||
#include "libc/nexgen32e/x86feature.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/thread/thread.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/intrin/weaken.h"
|
||||
#include "third_party/dlmalloc/dlmalloc.h"
|
||||
|
||||
#if !FOOTERS || !MSPACES
|
||||
|
@ -64,11 +66,28 @@ size_t dlbulk_free(void *array[], size_t nelem) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
struct ThreadedMallocVisitor {
|
||||
mstate heap;
|
||||
void (*handler)(void *start, void *end,
|
||||
size_t used_bytes, void *arg);
|
||||
void *arg;
|
||||
};
|
||||
|
||||
static void threaded_malloc_visitor(void *start, void *end,
|
||||
size_t used_bytes, void *arg) {
|
||||
struct ThreadedMallocVisitor *tmv = arg;
|
||||
if (start == tmv->heap)
|
||||
return;
|
||||
tmv->handler(start, end, used_bytes, tmv->arg);
|
||||
}
|
||||
|
||||
void dlmalloc_inspect_all(void handler(void *start, void *end,
|
||||
size_t used_bytes, void *callback_arg),
|
||||
size_t used_bytes, void *arg),
|
||||
void *arg) {
|
||||
for (unsigned i = 0; i < g_heapslen; ++i)
|
||||
mspace_inspect_all(g_heaps[i], handler, arg);
|
||||
for (unsigned i = 0; i < g_heapslen; ++i) {
|
||||
struct ThreadedMallocVisitor tmv = {g_heaps[i], handler, arg};
|
||||
mspace_inspect_all(g_heaps[i], threaded_malloc_visitor, &tmv);
|
||||
}
|
||||
}
|
||||
|
||||
forceinline mstate get_arena(void) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue