summaryrefslogtreecommitdiff
path: root/libc/stdlib/malloc-930716/memalign.c
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>2003-12-30 10:40:49 +0000
committerEric Andersen <andersen@codepoet.org>2003-12-30 10:40:49 +0000
commit8d532c51318bad2436880ecac972c9dfa3996c9b (patch)
tree821863358734242feb99643e9d66ee9b175ad464 /libc/stdlib/malloc-930716/memalign.c
parent4c9086ee4afde4257a4b4a8f55e05932d1b6acfd (diff)
Rework malloc. The new default implementation is based on dlmalloc from Doug
Lea. It is about 2x faster than the old malloc-930716, and behave itself much better -- it will properly release memory back to the system, and it uses a combination of brk() for small allocations and mmap() for larger allocations. -Erik
Diffstat (limited to 'libc/stdlib/malloc-930716/memalign.c')
-rw-r--r--libc/stdlib/malloc-930716/memalign.c67
1 files changed, 0 insertions, 67 deletions
diff --git a/libc/stdlib/malloc-930716/memalign.c b/libc/stdlib/malloc-930716/memalign.c
deleted file mode 100644
index b89165452..000000000
--- a/libc/stdlib/malloc-930716/memalign.c
+++ /dev/null
@@ -1,67 +0,0 @@
-/* malloc.c - C standard library routine.
- Copyright (c) 1989, 1993 Michael J. Haertel
- You may redistribute this library under the terms of the
- GNU Library General Public License (version 2 or any later
- version) as published by the Free Software Foundation.
- THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT ANY EXPRESS OR IMPLIED
- WARRANTY. IN PARTICULAR, THE AUTHOR MAKES NO REPRESENTATION OR
- WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY OF THIS
- SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. */
-
-#define _GNU_SOURCE
-#include <features.h>
-#include <limits.h>
-#include <stddef.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include "malloc.h"
-
-#ifdef __UCLIBC_HAS_THREADS__
-#include <pthread.h>
-extern pthread_mutex_t __malloclock;
-# define LOCK __pthread_mutex_lock(&__malloclock)
-# define UNLOCK __pthread_mutex_unlock(&__malloclock);
-#else
-# define LOCK
-# define UNLOCK
-#endif
-
-
-__ptr_t memalign (size_t alignment, size_t size)
-{
- __ptr_t result;
- unsigned long int adj;
-
- result = malloc (size + alignment - 1);
- if (result == NULL)
- return NULL;
- adj = (unsigned long int) ((unsigned long int) ((char *) result -
- (char *) NULL)) % alignment;
- if (adj != 0)
- {
- struct alignlist *l;
- LOCK;
- for (l = _aligned_blocks; l != NULL; l = l->next)
- if (l->aligned == NULL)
- /* This slot is free. Use it. */
- break;
- if (l == NULL)
- {
- l = (struct alignlist *) malloc (sizeof (struct alignlist));
- if (l == NULL) {
- __free_unlocked (result);
- UNLOCK;
- return NULL;
- }
- l->next = _aligned_blocks;
- _aligned_blocks = l;
- }
- l->exact = result;
- result = l->aligned = (char *) result + alignment - adj;
- UNLOCK;
- }
-
- return result;
-}
-