some fixes to accented characters
[tangerine.git] / rom / exec / createpool.c
blob372a38934f75ce71224b9b56e0d113c9ed591ca8
1 /*
2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Create a memory pool.
6 Lang: english
7 */
8 #include "exec_intern.h"
9 #include <aros/libcall.h>
10 #include <clib/alib_protos.h>
11 #include "memory.h"
13 /*****************************************************************************
15 NAME */
16 #include <exec/memory.h>
17 #include <proto/exec.h>
19 AROS_LH3(APTR, CreatePool,
21 /* SYNOPSIS */
22 AROS_LHA(ULONG, requirements, D0),
23 AROS_LHA(ULONG, puddleSize, D1),
24 AROS_LHA(ULONG, threshSize, D2),
26 /* LOCATION */
27 struct ExecBase *, SysBase, 116, Exec)
29 /* FUNCTION
30 Create a private pool for memory allocations.
32 INPUTS
33 requirements - The type of the memory
34 puddleSize - The number of bytes that the pool expands
35 if it is too small.
36 threshSize - Allocations beyond the threshSize are given
37 directly to the system. threshSize must be
38 smaller or equal than the puddleSize.
40 RESULT
41 A handle for the memory pool or NULL if the pool couldn't
42 be created
44 NOTES
46 EXAMPLE
47 \* Get the handle to a private memory pool *\
48 po=CreatePool(MEMF_ANY,16384,8192);
49 if(po!=NULL)
51 \* Use the pool *\
52 UBYTE *mem1,*mem2;
53 mem1=AllocPooled(po,1000);
54 mem2=AllocPooled(po,2000);
55 \* Do something with the memory... *\
57 \* Free everything at once *\
58 DeletePool(po);
61 BUGS
63 SEE ALSO
64 DeletePool(), AllocPooled(), FreePooled()
66 INTERNALS
68 ******************************************************************************/
70 AROS_LIBFUNC_INIT
72 struct ProtectedPool *pool = NULL;
74 /* puddleSize must not be smaller than threshSize */
75 if(puddleSize >= threshSize)
77 LONG poolstruct_size;
79 /* Round puddleSize up to be a multiple of MEMCHUNK_TOTAL. */
80 puddleSize = (puddleSize + MEMCHUNK_TOTAL - 1) & ~(MEMCHUNK_TOTAL - 1);
83 Allocate memory for the Pool structure using the same requirements
84 as for the whole pool (to make it shareable, residentable or
85 whatever is needed).
88 poolstruct_size = (requirements & MEMF_SEM_PROTECTED) ? sizeof(struct ProtectedPool) :
89 sizeof(struct Pool);
91 pool=(struct ProtectedPool *)AllocMem(poolstruct_size, requirements & ~MEMF_SEM_PROTECTED);
92 if(pool != NULL)
94 /* Clear the lists */
95 NEWLIST((struct List *)&pool->pool.PuddleList);
96 NEWLIST((struct List *)&pool->pool.BlockList );
98 /* Set the rest */
99 pool->pool.Requirements = requirements;
100 pool->pool.PuddleSize = puddleSize;
101 pool->pool.ThreshSize = threshSize;
103 if (requirements & MEMF_SEM_PROTECTED)
105 InitSemaphore(&pool->sem);
109 } /* if(puddleSize >= threshSize) */
111 return pool;
113 AROS_LIBFUNC_EXIT
115 } /* CreatePool */