forwarding a patch that uses the fetch macros to pull in acpica and build it (NicJA).
[AROS.git] / compiler / alib / liballocpooled.c
blob34142871e73b0239ab607af818a1257f4fc6e287
1 /*
2 Copyright © 1995-2007, The AROS Development Team. All rights reserved.
3 Original version from libnix
4 $Id$
5 */
7 #define AROS_LIBREQ(base,ver) /* We test for versions manually */
9 #include "pool.h"
10 #include <proto/exec.h>
12 /*****************************************************************************
14 NAME */
15 #include <proto/alib.h>
17 APTR LibAllocPooled (
19 /* SYNOPSIS */
20 APTR pool,
21 ULONG memSize)
23 /* FUNCTION
25 INPUTS
27 RESULT
29 NOTES
31 EXAMPLE
33 BUGS
35 SEE ALSO
37 INTERNALS
39 HISTORY
40 06.12.96 digulla Created after original from libnix
42 ******************************************************************************/
44 # define poolHeader ((POOL *)pool)
45 ULONG *puddle = NULL;
47 if (SysBase->LibNode.lib_Version >= 39)
48 return (AllocPooled (pool, memSize));
50 if (poolHeader != NULL && memSize != 0)
52 ULONG size;
54 if (poolHeader->ThreshSize > memSize)
56 struct MemHeader * a = (struct MemHeader *)poolHeader->PuddleList.mlh_Head;
58 for(;;)
60 if (a->mh_Node.ln_Succ!=NULL)
62 if (a->mh_Node.ln_Type
63 && (puddle = (ULONG *)Allocate (a, memSize)) != NULL
65 break;
67 a = (struct MemHeader *)a->mh_Node.ln_Succ;
69 else
71 size = poolHeader->PuddleSize
72 + sizeof (struct MemHeader)
73 + 2 * sizeof (ULONG);
75 if (!(puddle = (ULONG *)AllocMem (size, poolHeader->MemoryFlags)) )
76 return NULL;
78 *puddle ++ = size;
80 a = (struct MemHeader *)puddle;
82 a->mh_Node.ln_Type = NT_MEMORY;
83 a->mh_Lower =
84 a->mh_First = (struct MemChunk *)(
85 (UBYTE *)a
86 + sizeof (struct MemHeader)
87 + sizeof (UBYTE *)
89 a->mh_First->mc_Next = NULL;
90 a->mh_Free =
91 a->mh_First->mc_Bytes = poolHeader->PuddleSize;
92 a->mh_Upper = (char *)a->mh_First + a->mh_Free;
94 AddHead ((struct List *)&poolHeader->PuddleList, &a->mh_Node);
96 puddle = (ULONG *)Allocate (a, memSize);
98 break;
103 We do have to clear memory here. It may have been dirtied
104 by somebody using it beforehand.
106 if (poolHeader->MemoryFlags & MEMF_CLEAR)
108 ULONG *p = puddle;
110 memSize += 7;
111 memSize >>= 3;
115 *p++=0;
116 *p++=0;
117 } while (--memSize);
120 else
122 size = memSize + sizeof (struct MinNode) + 2 * sizeof (ULONG);
124 if ((puddle = (ULONG *)AllocMem (size, poolHeader->MemoryFlags)))
126 *puddle ++ = size;
128 AddTail ((struct List *)&poolHeader->PuddleList
129 , (struct Node *)puddle
132 puddle = (ULONG *)((struct MinNode *)puddle + 1);
134 *puddle ++ = 0;
139 return puddle;
140 } /* LibAllocPooled */