summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRich Felker <dalias@aerifal.cx>2018-04-19 18:43:05 -0400
committerRich Felker <dalias@aerifal.cx>2018-04-19 18:44:17 -0400
commit23389b1988b061e8487c316893a8a8eb77770a2f (patch)
tree842b50b821132dff65530972c2a44bfc60a8fe7a
parent618b18c78e33acfe54a4434e91aa57b8e171df89 (diff)
downloadmusl-23389b1988b061e8487c316893a8a8eb77770a2f.tar.gz
move malloc implementation types and macros to an internal header
-rw-r--r--src/internal/malloc_impl.h39
-rw-r--r--src/malloc/malloc.c38
2 files changed, 40 insertions, 37 deletions
diff --git a/src/internal/malloc_impl.h b/src/internal/malloc_impl.h
new file mode 100644
index 00000000..1ea0407c
--- /dev/null
+++ b/src/internal/malloc_impl.h
@@ -0,0 +1,39 @@
+#ifndef MALLOC_IMPL_H
+#define MALLOC_IMPL_H
+
+void *__mmap(void *, size_t, int, int, int, off_t);
+int __munmap(void *, size_t);
+void *__mremap(void *, size_t, size_t, int, ...);
+int __madvise(void *, size_t, int);
+
+struct chunk {
+ size_t psize, csize;
+ struct chunk *next, *prev;
+};
+
+struct bin {
+ volatile int lock[2];
+ struct chunk *head;
+ struct chunk *tail;
+};
+
+#define SIZE_ALIGN (4*sizeof(size_t))
+#define SIZE_MASK (-SIZE_ALIGN)
+#define OVERHEAD (2*sizeof(size_t))
+#define MMAP_THRESHOLD (0x1c00*SIZE_ALIGN)
+#define DONTCARE 16
+#define RECLAIM 163840
+
+#define CHUNK_SIZE(c) ((c)->csize & -2)
+#define CHUNK_PSIZE(c) ((c)->psize & -2)
+#define PREV_CHUNK(c) ((struct chunk *)((char *)(c) - CHUNK_PSIZE(c)))
+#define NEXT_CHUNK(c) ((struct chunk *)((char *)(c) + CHUNK_SIZE(c)))
+#define MEM_TO_CHUNK(p) (struct chunk *)((char *)(p) - OVERHEAD)
+#define CHUNK_TO_MEM(c) (void *)((char *)(c) + OVERHEAD)
+#define BIN_TO_CHUNK(i) (MEM_TO_CHUNK(&mal.bins[i].head))
+
+#define C_INUSE ((size_t)1)
+
+#define IS_MMAPPED(c) !((c)->csize & (C_INUSE))
+
+#endif
diff --git a/src/malloc/malloc.c b/src/malloc/malloc.c
index da775921..c8bc9227 100644
--- a/src/malloc/malloc.c
+++ b/src/malloc/malloc.c
@@ -8,54 +8,18 @@
#include "libc.h"
#include "atomic.h"
#include "pthread_impl.h"
+#include "malloc_impl.h"
#if defined(__GNUC__) && defined(__PIC__)
#define inline inline __attribute__((always_inline))
#endif
-void *__mmap(void *, size_t, int, int, int, off_t);
-int __munmap(void *, size_t);
-void *__mremap(void *, size_t, size_t, int, ...);
-int __madvise(void *, size_t, int);
-
-struct chunk {
- size_t psize, csize;
- struct chunk *next, *prev;
-};
-
-struct bin {
- volatile int lock[2];
- struct chunk *head;
- struct chunk *tail;
-};
-
static struct {
volatile uint64_t binmap;
struct bin bins[64];
volatile int free_lock[2];
} mal;
-
-#define SIZE_ALIGN (4*sizeof(size_t))
-#define SIZE_MASK (-SIZE_ALIGN)
-#define OVERHEAD (2*sizeof(size_t))
-#define MMAP_THRESHOLD (0x1c00*SIZE_ALIGN)
-#define DONTCARE 16
-#define RECLAIM 163840
-
-#define CHUNK_SIZE(c) ((c)->csize & -2)
-#define CHUNK_PSIZE(c) ((c)->psize & -2)
-#define PREV_CHUNK(c) ((struct chunk *)((char *)(c) - CHUNK_PSIZE(c)))
-#define NEXT_CHUNK(c) ((struct chunk *)((char *)(c) + CHUNK_SIZE(c)))
-#define MEM_TO_CHUNK(p) (struct chunk *)((char *)(p) - OVERHEAD)
-#define CHUNK_TO_MEM(c) (void *)((char *)(c) + OVERHEAD)
-#define BIN_TO_CHUNK(i) (MEM_TO_CHUNK(&mal.bins[i].head))
-
-#define C_INUSE ((size_t)1)
-
-#define IS_MMAPPED(c) !((c)->csize & (C_INUSE))
-
-
/* Synchronization tools */
static inline void lock(volatile int *lk)