Doc fix.
/*
- * 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
#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
#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
/*
- * 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
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");
HEAP_DEBUG (heap, "after __heap_alloc");
- mutex_unlock (heap->lock);
+ __heap_unlock (heap);
return mem;
}
/*
- * 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
size = HEAP_ADJUST_SIZE (size);
- mutex_lock (heap->lock);
+ __heap_lock (heap);
HEAP_DEBUG (heap, "before __heap_alloc_at");
HEAP_DEBUG (heap, "after __heap_alloc_at");
- mutex_unlock (heap->lock);
+ __heap_unlock (heap);
return alloced;
}
/*
- * 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
int success = 0;
struct heap_free_area *fa;
- mutex_lock (heap->lock);
+ __heap_lock (heap);
HEAP_DEBUG (heap, "before __heap_append_free");
HEAP_DEBUG (heap, "after __heap_append_free");
- mutex_unlock (heap->lock);
+ __heap_unlock (heap);
return success;
}
/*
- * 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
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");
done:
HEAP_DEBUG (heap, "after __heap_free");
- mutex_unlock (heap->lock);
+ __heap_unlock (heap);
}