[llvm-commits] CVS: poolalloc/runtime/FreeListAllocator/PoolAllocator.cpp PoolAllocator.h
Chris Lattner
lattner at cs.uiuc.edu
Fri Nov 14 16:06:03 PST 2003
Changes in directory poolalloc/runtime/FreeListAllocator:
PoolAllocator.cpp updated: 1.27 -> 1.28
PoolAllocator.h updated: 1.9 -> 1.10
---
Log message:
Do not export poolallocarray, make it static and move it before poolalloc
instead
---
Diffs of the changes: (+97 -97)
Index: poolalloc/runtime/FreeListAllocator/PoolAllocator.cpp
diff -u poolalloc/runtime/FreeListAllocator/PoolAllocator.cpp:1.27 poolalloc/runtime/FreeListAllocator/PoolAllocator.cpp:1.28
--- poolalloc/runtime/FreeListAllocator/PoolAllocator.cpp:1.27 Fri Nov 14 15:52:22 2003
+++ poolalloc/runtime/FreeListAllocator/PoolAllocator.cpp Fri Nov 14 16:05:39 2003
@@ -212,101 +212,6 @@
}
//
-// Function: poolalloc ()
-//
-// Description:
-// Allocates memory from the pool. Typically, we will allocate memory
-// in the same size chunks as we usually do, but sometimes, we will have to
-// allocate more.
-//
-void *
-poolalloc(PoolTy *Pool, unsigned BytesWanted)
-{
- // Pointer to the data block to return
- void * Data;
-
- // Slab Pointer
- struct SlabHeader * Slabp;
-
- assert(Pool && "Null pool pointer passed in to poolalloc!\n");
-
- // Make sure we allocate something
- BytesWanted = (BytesWanted ? BytesWanted : 1);
-
- //
- // Determine if we can satisfy this request normally. If not, then
- // we need to use the array allocation instead.
- //
- if (Pool->NodeSize < BytesWanted)
- {
- return (poolallocarray (Pool, (BytesWanted+Pool->NodeSize-1)/Pool->NodeSize));
- }
-
- //
- // If we don't have a slab, this is our first initialization. Do some
- // quick stuff.
- //
- Slabp = Pool->Slabs;
- if (Slabp == NULL)
- {
- Pool->Slabs = Slabp = createSlab (Pool);
- (Slabp->NextFreeData)++;
- return (Slabp->Data);
- }
-
- //
- // Determine whether we can allocate from the current slab.
- //
- if (Slabp->NextFreeData < Slabp->NodesPerSlab)
- {
- //
- // Return the block and increment the index of the next free data block.
- //
- Data = (Slabp->Data + (Pool->NodeSize * Slabp->NextFreeData));
- (Slabp->NextFreeData)++;
- return (Data);
- }
-
- //
- // We have a slab, but it doesn't have any new blocks.
- // Check the free list to see if we can use any recycled blocks.
- //
- if (Pool->FreeList.Next == NULL)
- {
- //
- // Create a new slab and add it to the list.
- //
- Slabp = createSlab (Pool);
- Slabp->Next = Pool->Slabs;
- Pool->Slabs = Slabp;
-
- (Slabp->NextFreeData)++;
-
- //
- // Return the block and increment the index of the next free data block.
- //
- return (Slabp->Data);
- }
-
- //
- // Determine which slab owns this block.
- //
- Slabp = BlockOwner (PageSize, Pool->FreeList);
-
- //
- // Find the data block that corresponds with this pointer.
- //
- Data = (Slabp->Data + (Pool->NodeSize * (Pool->FreeList.Next - &(Slabp->BlockList[0]))));
-
- //
- // Unlink the first block.
- //
- Pool->FreeList.Next = Pool->FreeList.Next->Next;
-
- return Data;
-}
-
-//
// Function: poolallocarray ()
//
// Description:
@@ -316,7 +221,7 @@
// Pool - The pool from which to allocate memory.
// ArraySize - The size of the array in number of elements (not bytes).
//
-void *
+static void *
poolallocarray(PoolTy* Pool, unsigned ArraySize)
{
assert(Pool && "Null pool pointer passed into poolallocarray!\n");
@@ -413,6 +318,102 @@
// Return the list of blocks to the caller.
//
return (Slabp->Data);
+}
+
+
+//
+// Function: poolalloc ()
+//
+// Description:
+// Allocates memory from the pool. Typically, we will allocate memory
+// in the same size chunks as we usually do, but sometimes, we will have to
+// allocate more.
+//
+void *
+poolalloc(PoolTy *Pool, unsigned BytesWanted)
+{
+ // Pointer to the data block to return
+ void * Data;
+
+ // Slab Pointer
+ struct SlabHeader * Slabp;
+
+ assert(Pool && "Null pool pointer passed in to poolalloc!\n");
+
+ // Make sure we allocate something
+ BytesWanted = (BytesWanted ? BytesWanted : 1);
+
+ //
+ // Determine if we can satisfy this request normally. If not, then
+ // we need to use the array allocation instead.
+ //
+ if (Pool->NodeSize < BytesWanted)
+ {
+ return (poolallocarray (Pool, (BytesWanted+Pool->NodeSize-1)/Pool->NodeSize));
+ }
+
+ //
+ // If we don't have a slab, this is our first initialization. Do some
+ // quick stuff.
+ //
+ Slabp = Pool->Slabs;
+ if (Slabp == NULL)
+ {
+ Pool->Slabs = Slabp = createSlab (Pool);
+ (Slabp->NextFreeData)++;
+ return (Slabp->Data);
+ }
+
+ //
+ // Determine whether we can allocate from the current slab.
+ //
+ if (Slabp->NextFreeData < Slabp->NodesPerSlab)
+ {
+ //
+ // Return the block and increment the index of the next free data block.
+ //
+ Data = (Slabp->Data + (Pool->NodeSize * Slabp->NextFreeData));
+ (Slabp->NextFreeData)++;
+ return (Data);
+ }
+
+ //
+ // We have a slab, but it doesn't have any new blocks.
+ // Check the free list to see if we can use any recycled blocks.
+ //
+ if (Pool->FreeList.Next == NULL)
+ {
+ //
+ // Create a new slab and add it to the list.
+ //
+ Slabp = createSlab (Pool);
+ Slabp->Next = Pool->Slabs;
+ Pool->Slabs = Slabp;
+
+ (Slabp->NextFreeData)++;
+
+ //
+ // Return the block and increment the index of the next free data block.
+ //
+ return (Slabp->Data);
+ }
+
+ //
+ // Determine which slab owns this block.
+ //
+ Slabp = BlockOwner (PageSize, Pool->FreeList);
+
+ //
+ // Find the data block that corresponds with this pointer.
+ //
+ Data = (Slabp->Data + (Pool->NodeSize * (Pool->FreeList.Next - &(Slabp->BlockList[0]))));
+
+ //
+ // Unlink the first block.
+ //
+ Pool->FreeList.Next = Pool->FreeList.Next->Next;
+
+ return Data;
}
void
Index: poolalloc/runtime/FreeListAllocator/PoolAllocator.h
diff -u poolalloc/runtime/FreeListAllocator/PoolAllocator.h:1.9 poolalloc/runtime/FreeListAllocator/PoolAllocator.h:1.10
--- poolalloc/runtime/FreeListAllocator/PoolAllocator.h:1.9 Fri Nov 14 15:52:22 2003
+++ poolalloc/runtime/FreeListAllocator/PoolAllocator.h Fri Nov 14 16:05:39 2003
@@ -55,7 +55,6 @@
void pooldestroy(PoolTy *Pool);
void *poolalloc(PoolTy *Pool, unsigned NodeSize);
void poolfree(PoolTy *Pool, void *Node);
- void* poolallocarray(PoolTy* Pool, unsigned Size);
}
#endif
More information about the llvm-commits
mailing list