forked from ApolloTeam-dev/ApolloOS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathallocpooled.c
More file actions
103 lines (74 loc) · 2.31 KB
/
Copy pathallocpooled.c
File metadata and controls
103 lines (74 loc) · 2.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/*
Copyright � 1995-2013, The AROS Development Team. All rights reserved.
$Id$
Desc: Allocate memory in a pool.
Lang: english
*/
#include <aros/libcall.h>
#include "exec_intern.h"
#include "exec_util.h"
#include "memory.h"
#include "exec_debug.h"
#ifndef DEBUG_AllocPooled
# define DEBUG_AllocPooled 0
#endif
#undef DEBUG
#if DEBUG_AllocPooled
# define DEBUG 1
#endif
#include <aros/debug.h>
#undef kprintf
/*****************************************************************************
NAME */
#include <exec/memory.h>
#include <exec/memheaderext.h>
#include <proto/exec.h>
AROS_LH2(APTR, AllocPooled,
/* SYNOPSIS */
AROS_LHA(APTR, poolHeader, A0),
AROS_LHA(IPTR, memSize, D0),
/* LOCATION */
struct ExecBase *, SysBase, 118, Exec)
/* FUNCTION
Allocate memory out of a private memory pool. The memory must be
freed with FreePooled(), or by deallocating the entire pool with
DeletePool().
INPUTS
poolHeader - Handle of the memory pool
memSize - Number of bytes you want to get
RESULT
A pointer to the number of bytes you wanted or NULL if the memory
couldn't be allocated
NOTES
EXAMPLE
BUGS
SEE ALSO
CreatePool(), DeletePool(), FreePooled()
INTERNALS
******************************************************************************/
{
AROS_LIBFUNC_INIT
struct MemHeaderExt *mhe = (struct MemHeaderExt *)poolHeader;
/* 0-sized allocation results in returning NULL (API guarantee) */
if(!memSize)
return NULL;
#if HANDLE_MANAGED_MEM
if (IsManagedMem(mhe))
{
ULONG poolrequirements = (ULONG)(IPTR)mhe->mhe_MemHeader.mh_First;
if (mhe->mhe_Alloc)
return mhe->mhe_Alloc(mhe, memSize, &poolrequirements);
else
return NULL;
}
else
#endif
{
struct TraceLocation tp = CURRENT_LOCATION("AllocPooled");
struct Pool *pool = poolHeader + MEMHEADER_TOTAL;
D(bug("AllocPooled 0x%p memsize %u by \"%s\"\n", poolHeader, memSize, GET_THIS_TASK->tc_Node.ln_Name);)
/* Allocate from the specified pool with flags stored in pool header */
return InternalAllocPooled(poolHeader, memSize, pool->Requirements, &tp, SysBase);
}
AROS_LIBFUNC_EXIT
} /* AllocPooled */