Cancel redefinition of DOSBase for the 'cdrom' test utility. Now the
[AROS.git] / rom / exec / deletepool.c
blobcf4ffef8ea979f914073794031e320e0a4ed97e3
1 /*
2 Copyright � 1995-2013, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Delete a memory pool including all its memory.
6 Lang: english
7 */
9 #include <aros/libcall.h>
10 #include <exec/memory.h>
11 #include <exec/memheaderext.h>
12 #include <proto/exec.h>
14 #include "exec_intern.h"
15 #include "exec_util.h"
16 #include "memory.h"
17 #include "mungwall.h"
19 /*****************************************************************************
21 NAME */
23 AROS_LH1(void, DeletePool,
25 /* SYNOPSIS */
26 AROS_LHA(APTR, poolHeader, A0),
28 /* LOCATION */
29 struct ExecBase *, SysBase, 117, Exec)
31 /* FUNCTION
32 Delete a pool including all its memory.
34 INPUTS
35 poolHeader - The pool allocated with CreatePool() or NULL.
37 RESULT
39 NOTES
41 EXAMPLE
43 BUGS
45 SEE ALSO
46 CreatePool(), AllocPooled(), FreePooled(), AllocVecPooled(),
47 FreeVecPooled()
49 INTERNALS
51 ******************************************************************************/
53 AROS_LIBFUNC_INIT
55 ASSERT_VALID_PTR_OR_NULL(poolHeader);
57 D(bug("[exec] DeletePool(0x%p)\n", poolHeader));
59 /* It is legal to DeletePool(NULL) */
60 if (poolHeader != NULL)
62 struct TraceLocation tp = CURRENT_LOCATION("DeletePool");
63 struct Pool *pool = poolHeader + MEMHEADER_TOTAL;
64 struct Node *p, *p2; /* Avoid casts */
65 struct MemHeaderExt *mhe = (struct MemHeaderExt *)poolHeader;
67 if (pool->PoolMagic != POOL_MAGIC)
69 PoolManagerAlert(PME_DEL_POOL_INV_POOL, 0, 0, NULL, NULL, poolHeader);
71 else
73 D(bug("[DeletePool] Pool header 0x%p\n", pool));
74 pool->PoolMagic = 0x0;
77 * The poolHeader is in fact a MemHeader structure. Check, if it was
78 * MEMF_MANAGED memory...
80 if (!(mhe->mhe_MemHeader.mh_Attributes & MEMF_MANAGED))
83 * We are going to deallocate the whole pool.
84 * Scan mungwall's allocations list and remove all chunks belonging to the pool.
86 MungWall_Scan(pool, &tp, SysBase);
89 * Free the list of puddles.
90 * Remember that initial puddle containing the pool structure is also in this list.
91 * We do not need to free it until everything else is freed.
93 for (p = (struct Node *)pool->PuddleList.mlh_Head; p->ln_Succ; p = p2)
95 p2 = p->ln_Succ;
97 D(bug("[DeletePool] Puddle 0x%p...", p));
99 if (p != poolHeader)
101 D(bug(" freeing"));
102 FreeMemHeader(p, &tp, SysBase);
104 D(bug("\n"));
110 /* Free the last puddle, containing the pool header */
111 D(bug("[DeletePool] Freeing initial puddle 0x%p\n", poolHeader));
112 FreeMemHeader(poolHeader, &tp, SysBase);
116 AROS_LIBFUNC_EXIT
117 } /* DeletePool */