summaryrefslogtreecommitdiff
path: root/libc
diff options
context:
space:
mode:
authorMiles Bader <miles@lsi.nec.co.jp>2002-07-19 04:26:41 +0000
committerMiles Bader <miles@lsi.nec.co.jp>2002-07-19 04:26:41 +0000
commit246192008bf450a7098af436a02dcfdfd88b7ea9 (patch)
tree7c54d2926a118cbfac9aa9d09830733f0eb69e8f /libc
parent35d29fcb08fadaf006561a058746b0fce76a6a74 (diff)
Rename mutex stuff to use heap-specific names.
Doc fix.
Diffstat (limited to 'libc')
-rw-r--r--libc/stdlib/malloc/heap.h26
-rw-r--r--libc/stdlib/malloc/heap_alloc.c6
-rw-r--r--libc/stdlib/malloc/heap_alloc_at.c6
-rw-r--r--libc/stdlib/malloc/heap_append_free.c6
-rw-r--r--libc/stdlib/malloc/heap_free.c6
5 files changed, 26 insertions, 24 deletions
diff --git a/libc/stdlib/malloc/heap.h b/libc/stdlib/malloc/heap.h
index 74b56603b..0d6465050 100644
--- a/libc/stdlib/malloc/heap.h
+++ b/libc/stdlib/malloc/heap.h
@@ -1,5 +1,5 @@
/*
- * libc/stdlib/malloc-zarg/heap.h -- heap allocator used for malloc
+ * libc/stdlib/malloc/heap.h -- heap allocator used for malloc
*
* Copyright (C) 2002 NEC Corporation
* Copyright (C) 2002 Miles Bader <miles@gnu.org>
@@ -16,16 +16,16 @@
#ifdef __UCLIBC_HAS_THREADS__
#include <pthread.h>
-typedef pthread_mutex_t mutex_t;
-# define MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER
-# define mutex_lock(x) pthread_mutex_lock(&(x))
-# define mutex_unlock(x) pthread_mutex_unlock(&(x));
+typedef pthread_mutex_t heap_mutex_t;
+# define HEAP_MUTEX_INIT PTHREAD_MUTEX_INITIALIZER
+# define __heap_lock(heap) pthread_mutex_lock (&(heap)->lock)
+# define __heap_unlock(heap) pthread_mutex_unlock (&(heap)->lock);
#else
-/* Mutex operations are currently a nop. */
-typedef int mutex_t;
-# define MUTEX_INITIALIZER 0
-# define mutex_lock(x)
-# define mutex_unlock(x)
+/* Without threads, Mutex operations are a nop. */
+typedef int heap_mutex_t;
+# define HEAP_MUTEX_INIT 0
+# define __heap_lock(heap)
+# define __heap_unlock(heap)
#endif
@@ -36,13 +36,15 @@ typedef int mutex_t;
#define HEAP_GRANULARITY (sizeof (double))
+/* A heap is a collection of memory blocks, from which smaller blocks
+ of memory can be allocated. */
struct heap
{
struct heap_free_area *free_areas;
- mutex_t lock;
+ heap_mutex_t lock;
};
-#define HEAP_INIT { 0, MUTEX_INITIALIZER }
+#define HEAP_INIT { 0, HEAP_MUTEX_INIT }
/* A free-list area `header'. These are actually stored at the _ends_ of
diff --git a/libc/stdlib/malloc/heap_alloc.c b/libc/stdlib/malloc/heap_alloc.c
index 22591d613..d0e1d752a 100644
--- a/libc/stdlib/malloc/heap_alloc.c
+++ b/libc/stdlib/malloc/heap_alloc.c
@@ -1,5 +1,5 @@
/*
- * libc/stdlib/malloc-zarg/heap_alloc.c -- allocate from a heap
+ * libc/stdlib/malloc/heap_alloc.c -- allocate memory from a heap
*
* Copyright (C) 2002 NEC Corporation
* Copyright (C) 2002 Miles Bader <miles@gnu.org>
@@ -33,7 +33,7 @@ __heap_alloc (struct heap *heap, size_t *size)
we must make sure that every allocated block can hold one. */
_size = HEAP_ADJUST_SIZE (sizeof (struct heap_free_area));
- mutex_lock (heap->lock);
+ __heap_lock (heap);
HEAP_DEBUG (heap, "before __heap_alloc");
@@ -49,7 +49,7 @@ __heap_alloc (struct heap *heap, size_t *size)
HEAP_DEBUG (heap, "after __heap_alloc");
- mutex_unlock (heap->lock);
+ __heap_unlock (heap);
return mem;
}
diff --git a/libc/stdlib/malloc/heap_alloc_at.c b/libc/stdlib/malloc/heap_alloc_at.c
index 8ee925488..4047697c5 100644
--- a/libc/stdlib/malloc/heap_alloc_at.c
+++ b/libc/stdlib/malloc/heap_alloc_at.c
@@ -1,5 +1,5 @@
/*
- * libc/stdlib/malloc-zarg/heap_alloc_at.c -- allocate at a specific address
+ * libc/stdlib/malloc/heap_alloc_at.c -- allocate at a specific address
*
* Copyright (C) 2002 NEC Corporation
* Copyright (C) 2002 Miles Bader <miles@gnu.org>
@@ -26,7 +26,7 @@ __heap_alloc_at (struct heap *heap, void *mem, size_t size)
size = HEAP_ADJUST_SIZE (size);
- mutex_lock (heap->lock);
+ __heap_lock (heap);
HEAP_DEBUG (heap, "before __heap_alloc_at");
@@ -45,7 +45,7 @@ __heap_alloc_at (struct heap *heap, void *mem, size_t size)
HEAP_DEBUG (heap, "after __heap_alloc_at");
- mutex_unlock (heap->lock);
+ __heap_unlock (heap);
return alloced;
}
diff --git a/libc/stdlib/malloc/heap_append_free.c b/libc/stdlib/malloc/heap_append_free.c
index 42f0cf5bb..d67f46495 100644
--- a/libc/stdlib/malloc/heap_append_free.c
+++ b/libc/stdlib/malloc/heap_append_free.c
@@ -1,5 +1,5 @@
/*
- * libc/stdlib/malloc-zarg/heap_append_free.c -- append to heap free area
+ * libc/stdlib/malloc/heap_append_free.c -- append memory to a heap free area
*
* Copyright (C) 2002 NEC Corporation
* Copyright (C) 2002 Miles Bader <miles@gnu.org>
@@ -25,7 +25,7 @@ __heap_append_free (struct heap *heap, void *mem, size_t size)
int success = 0;
struct heap_free_area *fa;
- mutex_lock (heap->lock);
+ __heap_lock (heap);
HEAP_DEBUG (heap, "before __heap_append_free");
@@ -65,7 +65,7 @@ __heap_append_free (struct heap *heap, void *mem, size_t size)
HEAP_DEBUG (heap, "after __heap_append_free");
- mutex_unlock (heap->lock);
+ __heap_unlock (heap);
return success;
}
diff --git a/libc/stdlib/malloc/heap_free.c b/libc/stdlib/malloc/heap_free.c
index 20ef65572..d8eaf7e66 100644
--- a/libc/stdlib/malloc/heap_free.c
+++ b/libc/stdlib/malloc/heap_free.c
@@ -1,5 +1,5 @@
/*
- * libc/stdlib/malloc-zarg/heap_free.c -- return memory to a heap
+ * libc/stdlib/malloc/heap_free.c -- return memory to a heap
*
* Copyright (C) 2002 NEC Corporation
* Copyright (C) 2002 Miles Bader <miles@gnu.org>
@@ -23,7 +23,7 @@ __heap_free (struct heap *heap, void *mem, size_t size)
struct heap_free_area *prev_fa, *fa, *new_fa;
void *end = (char *)mem + size;
- mutex_lock (heap->lock);
+ __heap_lock (heap);
HEAP_DEBUG (heap, "before __heap_free");
@@ -123,5 +123,5 @@ __heap_free (struct heap *heap, void *mem, size_t size)
done:
HEAP_DEBUG (heap, "after __heap_free");
- mutex_unlock (heap->lock);
+ __heap_unlock (heap);
}