Updated PCI IDs to latest snapshot.
[tangerine.git] / rom / exec / freepooled.c
blob079b0e3020ecc18aeb266af9ae86252106e7a148
1 /*
2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Free memory allocated by AllocPooled().
6 Lang: english
7 */
8 #include "exec_intern.h"
9 #include <aros/libcall.h>
10 #include "memory.h"
11 #include <exec/memory.h>
12 #include <proto/exec.h>
15 /*****************************************************************************
17 NAME */
19 AROS_LH3(void,FreePooled,
21 /* SYNOPSIS */
22 AROS_LHA(APTR, poolHeader,A0),
23 AROS_LHA(APTR, memory, A1),
24 AROS_LHA(ULONG,memSize, D0),
26 /* LOCATION */
27 struct ExecBase *, SysBase, 119, Exec)
29 /* FUNCTION
30 Free memory allocated out of a private memory pool.
32 INPUTS
33 poolHeader - Handle of the memory pool
34 memory - Pointer to the memory
35 memSize - Size of the memory chunk
37 RESULT
39 NOTES
41 EXAMPLE
43 BUGS
45 SEE ALSO
46 CreatePool(), DeletePool(), AllocPooled()
48 INTERNALS
50 ******************************************************************************/
52 AROS_LIBFUNC_INIT
54 struct ProtectedPool *pool = (struct ProtectedPool *)poolHeader;
56 if (!memory || !memSize) return;
58 if (pool->pool.Requirements & MEMF_SEM_PROTECTED)
60 ObtainSemaphore(&pool->sem);
63 /* If memSize is bigger than the ThreshSize it's allocated seperately. */
64 if(memSize > pool->pool.ThreshSize)
66 struct Block *bl;
68 /* Get pointer to header */
69 bl = (struct Block *)((UBYTE *)memory - BLOCK_TOTAL);
71 /* Remove it from the list */
72 Remove((struct Node *)&bl->Node);
74 if (bl->Size != memSize + BLOCK_TOTAL)
76 kprintf("\nFreePooled: free size does not match alloc size: allocsize = %d freesize = %d!!!\n\n",
77 bl->Size - BLOCK_TOTAL,
78 memSize);
81 /* And Free the memory */
82 FreeMem(bl, bl->Size);
85 else
87 /* Look for the right MemHeader */
88 struct MemHeader *mh = (struct MemHeader *)pool->pool.PuddleList.mlh_Head;
90 for(;;)
92 #if !defined(NO_CONSISTENCY_CHECKS)
93 if (!mh)
95 /* memory block is not in pool. */
96 Alert(AT_Recovery | AN_MemCorrupt);
97 break;
99 #endif
101 /* The memory must be between the two borders */
102 if(memory >= mh->mh_Lower && memory < mh->mh_Upper)
104 /* Found the MemHeader. Free the memory. */
105 Deallocate(mh, memory, memSize);
107 /* Is this MemHeader completely free now? */
108 if(mh->mh_Free == pool->pool.PuddleSize)
110 /* Yes. Remove it from the list. */
111 Remove(&mh->mh_Node);
113 /* And free it. */
114 FreeMem(mh, pool->pool.PuddleSize + MEMHEADER_TOTAL);
116 /* All done. */
117 break;
119 /* Try next MemHeader */
120 mh = (struct MemHeader *)mh->mh_Node.ln_Succ;
124 if (pool->pool.Requirements & MEMF_SEM_PROTECTED)
126 ReleaseSemaphore(&pool->sem);
129 AROS_LIBFUNC_EXIT
131 } /* FreePooled */