Browse Source

Rename mutex stuff to use heap-specific names.
Doc fix.

Miles Bader 23 years ago
parent
commit
246192008b

+ 14 - 12
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  NEC Corporation
  *  Copyright (C) 2002  Miles Bader <miles@gnu.org>
  *  Copyright (C) 2002  Miles Bader <miles@gnu.org>
@@ -16,16 +16,16 @@
 
 
 #ifdef __UCLIBC_HAS_THREADS__
 #ifdef __UCLIBC_HAS_THREADS__
 #include <pthread.h>
 #include <pthread.h>
-typedef pthread_mutex_t mutex_t;
+typedef pthread_mutex_t heap_mutex_t;
-# define MUTEX_INITIALIZER  PTHREAD_MUTEX_INITIALIZER
+# define HEAP_MUTEX_INIT	PTHREAD_MUTEX_INITIALIZER
-# define mutex_lock(x)	    pthread_mutex_lock(&(x))
+# define __heap_lock(heap)	pthread_mutex_lock (&(heap)->lock)
-# define mutex_unlock(x)    pthread_mutex_unlock(&(x));
+# define __heap_unlock(heap)	pthread_mutex_unlock (&(heap)->lock);
 #else
 #else
-/* Mutex operations are currently a nop.  */
+/* Without threads, Mutex operations are a nop.  */
-typedef int mutex_t;
+typedef int heap_mutex_t;
-# define MUTEX_INITIALIZER 0
+# define HEAP_MUTEX_INIT	0
-# define mutex_lock(x)
+# define __heap_lock(heap)
-# define mutex_unlock(x)
+# define __heap_unlock(heap)
 #endif
 #endif
 
 
 
 
@@ -36,13 +36,15 @@ typedef int mutex_t;
 #define HEAP_GRANULARITY	(sizeof (double))
 #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
 {
 {
   struct heap_free_area *free_areas;
   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
 /* A free-list area `header'.  These are actually stored at the _ends_ of

+ 3 - 3
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  NEC Corporation
  *  Copyright (C) 2002  Miles Bader <miles@gnu.org>
  *  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.  */
        we must make sure that every allocated block can hold one.  */
     _size = HEAP_ADJUST_SIZE (sizeof (struct heap_free_area));
     _size = HEAP_ADJUST_SIZE (sizeof (struct heap_free_area));
 
 
-  mutex_lock (heap->lock);
+  __heap_lock (heap);
 
 
   HEAP_DEBUG (heap, "before __heap_alloc");
   HEAP_DEBUG (heap, "before __heap_alloc");
 
 
@@ -49,7 +49,7 @@ __heap_alloc (struct heap *heap, size_t *size)
 
 
   HEAP_DEBUG (heap, "after __heap_alloc");
   HEAP_DEBUG (heap, "after __heap_alloc");
 
 
-  mutex_unlock (heap->lock);
+  __heap_unlock (heap);
 
 
   return mem;
   return mem;
 }
 }

+ 3 - 3
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  NEC Corporation
  *  Copyright (C) 2002  Miles Bader <miles@gnu.org>
  *  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);
   size = HEAP_ADJUST_SIZE (size);
 
 
-  mutex_lock (heap->lock);
+  __heap_lock (heap);
 
 
   HEAP_DEBUG (heap, "before __heap_alloc_at");
   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");
   HEAP_DEBUG (heap, "after __heap_alloc_at");
 
 
-  mutex_unlock (heap->lock);
+  __heap_unlock (heap);
 
 
   return alloced;
   return alloced;
 }
 }

+ 3 - 3
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  NEC Corporation
  *  Copyright (C) 2002  Miles Bader <miles@gnu.org>
  *  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;
   int success = 0;
   struct heap_free_area *fa;
   struct heap_free_area *fa;
 
 
-  mutex_lock (heap->lock);
+  __heap_lock (heap);
 
 
   HEAP_DEBUG (heap, "before __heap_append_free");
   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");
   HEAP_DEBUG (heap, "after __heap_append_free");
 
 
-  mutex_unlock (heap->lock);
+  __heap_unlock (heap);
 
 
   return success;
   return success;
 }
 }

+ 3 - 3
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  NEC Corporation
  *  Copyright (C) 2002  Miles Bader <miles@gnu.org>
  *  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;
   struct heap_free_area *prev_fa, *fa, *new_fa;
   void *end = (char *)mem + size;
   void *end = (char *)mem + size;
 
 
-  mutex_lock (heap->lock);
+  __heap_lock (heap);
 
 
   HEAP_DEBUG (heap, "before __heap_free");
   HEAP_DEBUG (heap, "before __heap_free");
 
 
@@ -123,5 +123,5 @@ __heap_free (struct heap *heap, void *mem, size_t size)
  done:
  done:
   HEAP_DEBUG (heap, "after __heap_free");
   HEAP_DEBUG (heap, "after __heap_free");
 
 
-  mutex_unlock (heap->lock);
+  __heap_unlock (heap);
 }
 }