grub2: bring back build of aros-side grub2 tools
[AROS.git] / workbench / libs / icon / addfreelist.c
blobd767e3370308288671be5fd1dfab8b6992e2238d
1 /*
2 Copyright © 1995-2013, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc:
6 Lang: english
7 */
8 #include "icon_intern.h"
10 /*****************************************************************************
12 NAME */
13 #include <proto/icon.h>
15 AROS_LH3(BOOL, AddFreeList,
17 /* SYNOPSIS */
18 AROS_LHA(struct FreeList *, freelist, A0),
19 AROS_LHA(APTR , mem, A1),
20 AROS_LHA(unsigned long , size, A2),
22 /* LOCATION */
23 struct IconBase *, IconBase, 12, Icon)
25 /* FUNCTION
26 Adds supplied memory chunk to the supplied freelist. The memory chunk
27 must have been allocated by AllocMem(). All memory added into the
28 freelist can later be deallocated through a single FreeFreeList() call.
30 INPUTS
31 freelist - pointer to freelist struct previously allocated by
32 the programmer.
33 mem - memory to add to the freelist.
34 size - size of memory chunk to add to the freelist.
36 RESULT
37 FALSE on failure, else TRUE.
39 NOTES
41 EXAMPLE
43 BUGS
45 SEE ALSO
46 FreeFreeList()
48 INTERNALS
50 HISTORY
52 *****************************************************************************/
54 AROS_LIBFUNC_INIT
56 struct MemList *memlist;
57 struct MemEntry *mementry;
58 /* We get hold of the last memlist node inside the list */
59 memlist = (struct MemList*)freelist->fl_MemList.lh_TailPred;
61 /* Is this memlist full? */
62 if (freelist->fl_NumFree == 0)
64 /* No more room, we must allocate a new entry */
65 if (!(memlist = AllocMem (sizeof(struct IconInternalMemList),
66 MEMF_CLEAR)
67 ) )
68 return FALSE;
70 freelist->fl_NumFree = FREELIST_MEMLISTENTRIES;
71 memlist->ml_NumEntries = FREELIST_MEMLISTENTRIES;
73 AddTail ((struct List*)&freelist->fl_MemList, (struct Node*)memlist);
76 /* Insert the supplied parameters */
77 mementry = &memlist->ml_ME[freelist->fl_NumFree - 1];
79 mementry->me_Un.meu_Addr = mem;
80 mementry->me_Length = size;
82 freelist->fl_NumFree--;
84 return TRUE;
85 AROS_LIBFUNC_EXIT
86 } /* AddFreeList */