summaryrefslogtreecommitdiffstats
path: root/libc/stdlib/malloc-simple/alloc.c
diff options
context:
space:
mode:
authorCarmelo Amoroso <carmelo.amoroso@st.com>2008-07-09 16:47:01 +0000
committerCarmelo Amoroso <carmelo.amoroso@st.com>2008-07-09 16:47:01 +0000
commit62a21af8006ab04282fdc354c5b4dc765f56d058 (patch)
tree568761d58289238aa14cced3f0010809d4d28c00 /libc/stdlib/malloc-simple/alloc.c
parentef250238dc1572caf859c2b64652f9cdfb0d9e42 (diff)
downloaduClibc-alpine-62a21af8006ab04282fdc354c5b4dc765f56d058.tar.bz2
uClibc-alpine-62a21af8006ab04282fdc354c5b4dc765f56d058.tar.xz
BIG BIG commit: all left files merged from trunk [rev 22714]. Currenntly NPTL sh4 port build and work fine. All committed to allow Khem Ray working on a working branch to integrate the ARM nptl port. MIPS nptl port not tested but should still building and working fine. There are some other part non yet merged with trunk (misc/internals and some headers file that need some more work). Signed-off-by: Carmelo Amoroso <carmelo.amoroso@st.com>
Diffstat (limited to 'libc/stdlib/malloc-simple/alloc.c')
-rw-r--r--libc/stdlib/malloc-simple/alloc.c30
1 files changed, 14 insertions, 16 deletions
diff --git a/libc/stdlib/malloc-simple/alloc.c b/libc/stdlib/malloc-simple/alloc.c
index a1c7b93c9..13d4166a7 100644
--- a/libc/stdlib/malloc-simple/alloc.c
+++ b/libc/stdlib/malloc-simple/alloc.c
@@ -13,11 +13,10 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <unistd.h>
#include <errno.h>
#include <sys/mman.h>
-libc_hidden_proto(memcpy)
+/* Experimentally off - libc_hidden_proto(memcpy) */
/*libc_hidden_proto(memset)*/
libc_hidden_proto(mmap)
libc_hidden_proto(munmap)
@@ -115,12 +114,11 @@ void free(void *ptr)
#endif
#ifdef L_memalign
-#ifdef __UCLIBC_HAS_THREADS__
-# include <pthread.h>
-pthread_mutex_t __malloc_lock = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;
-#endif
-#define LOCK __pthread_mutex_lock(&__malloc_lock)
-#define UNLOCK __pthread_mutex_unlock(&__malloc_lock)
+
+#include <bits/uClibc_mutex.h>
+__UCLIBC_MUTEX_STATIC(__malloc_lock, PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP);
+#define __MALLOC_LOCK __UCLIBC_MUTEX_LOCK(__malloc_lock)
+#define __MALLOC_UNLOCK __UCLIBC_MUTEX_UNLOCK(__malloc_lock)
/* List of blocks allocated with memalign or valloc */
struct alignlist
@@ -139,7 +137,7 @@ int __libc_free_aligned(void *ptr)
if (ptr == NULL)
return 0;
- LOCK;
+ __MALLOC_LOCK;
for (l = _aligned_blocks; l != NULL; l = l->next) {
if (l->aligned == ptr) {
/* Mark the block as free */
@@ -150,7 +148,7 @@ int __libc_free_aligned(void *ptr)
return 1;
}
}
- UNLOCK;
+ __MALLOC_UNLOCK;
return 0;
}
void * memalign (size_t alignment, size_t size)
@@ -162,11 +160,10 @@ void * memalign (size_t alignment, size_t size)
if (result == NULL)
return NULL;
- adj = (unsigned long int) ((unsigned long int) ((char *) result -
- (char *) NULL)) % alignment;
+ adj = (unsigned long int) ((unsigned long int) ((char *) result - (char *) NULL)) % alignment;
if (adj != 0) {
struct alignlist *l;
- LOCK;
+ __MALLOC_LOCK;
for (l = _aligned_blocks; l != NULL; l = l->next)
if (l->aligned == NULL)
/* This slot is free. Use it. */
@@ -175,15 +172,16 @@ void * memalign (size_t alignment, size_t size)
l = (struct alignlist *) malloc (sizeof (struct alignlist));
if (l == NULL) {
free(result);
- UNLOCK;
- return NULL;
+ result = NULL;
+ goto DONE;
}
l->next = _aligned_blocks;
_aligned_blocks = l;
}
l->exact = result;
result = l->aligned = (char *) result + alignment - adj;
- UNLOCK;
+DONE:
+ __MALLOC_UNLOCK;
}
return result;