revert between 56095 -> 55830 in arch
[AROS.git] / rom / exec / allocpooled.c
blobbadde62ab5329d2fedd09b0831342beb61a22cb6
1 /*
2 Copyright � 1995-2013, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Allocate memory in a pool.
6 Lang: english
7 */
9 #include <aros/libcall.h>
11 #include "exec_intern.h"
12 #include "exec_util.h"
13 #include "memory.h"
15 #include "exec_debug.h"
16 #ifndef DEBUG_AllocPooled
17 # define DEBUG_AllocPooled 0
18 #endif
19 #undef DEBUG
20 #if DEBUG_AllocPooled
21 # define DEBUG 1
22 #endif
23 #include <aros/debug.h>
24 #undef kprintf
28 /*****************************************************************************
30 NAME */
31 #include <exec/memory.h>
32 #include <exec/memheaderext.h>
33 #include <proto/exec.h>
35 AROS_LH2(APTR, AllocPooled,
37 /* SYNOPSIS */
38 AROS_LHA(APTR, poolHeader, A0),
39 AROS_LHA(IPTR, memSize, D0),
41 /* LOCATION */
42 struct ExecBase *, SysBase, 118, Exec)
44 /* FUNCTION
45 Allocate memory out of a private memory pool. The memory must be
46 freed with FreePooled(), or by deallocating the entire pool with
47 DeletePool().
49 INPUTS
50 poolHeader - Handle of the memory pool
51 memSize - Number of bytes you want to get
53 RESULT
54 A pointer to the number of bytes you wanted or NULL if the memory
55 couldn't be allocated
57 NOTES
59 EXAMPLE
61 BUGS
63 SEE ALSO
64 CreatePool(), DeletePool(), FreePooled()
66 INTERNALS
68 ******************************************************************************/
70 AROS_LIBFUNC_INIT
72 struct MemHeaderExt *mhe = (struct MemHeaderExt *)poolHeader;
74 /* 0-sized allocation results in returning NULL (API guarantee) */
75 if(!memSize)
76 return NULL;
78 if (IsManagedMem(mhe))
80 ULONG poolrequirements = (ULONG)(IPTR)mhe->mhe_MemHeader.mh_First;
82 if (mhe->mhe_Alloc)
83 return mhe->mhe_Alloc(mhe, memSize, &poolrequirements);
84 else
85 return NULL;
87 else
89 struct TraceLocation tp = CURRENT_LOCATION("AllocPooled");
90 struct Pool *pool = poolHeader + MEMHEADER_TOTAL;
92 D(bug("AllocPooled 0x%p memsize %u by \"%s\"\n", poolHeader, memSize, GET_THIS_TASK->tc_Node.ln_Name);)
94 /* Allocate from the specified pool with flags stored in pool header */
95 return InternalAllocPooled(poolHeader, memSize, pool->Requirements, &tp, SysBase);
98 AROS_LIBFUNC_EXIT
100 } /* AllocPooled */