Expand PMF_FN_* macros.
[netbsd-mini2440.git] / sys / dev / raidframe / rf_alloclist.c
blob8c1a686e04a9b9d68b633fc9eb81202b0129810a
1 /* $NetBSD: rf_alloclist.c,v 1.25 2006/11/16 01:33:23 christos Exp $ */
2 /*
3 * Copyright (c) 1995 Carnegie-Mellon University.
4 * All rights reserved.
6 * Author: Mark Holland
8 * Permission to use, copy, modify and distribute this software and
9 * its documentation is hereby granted, provided that both the copyright
10 * notice and this permission notice appear in all copies of the
11 * software, derivative works or modified versions, and any portions
12 * thereof, and that both notices appear in supporting documentation.
14 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
15 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
16 * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
18 * Carnegie Mellon requests users of this software to return to
20 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
21 * School of Computer Science
22 * Carnegie Mellon University
23 * Pittsburgh PA 15213-3890
25 * any improvements or extensions that they make and grant Carnegie the
26 * rights to redistribute these changes.
29 /****************************************************************************
31 * Alloclist.c -- code to manipulate allocation lists
33 * an allocation list is just a list of AllocListElem structures. Each
34 * such structure contains a fixed-size array of pointers. Calling
35 * FreeAList() causes each pointer to be freed.
37 ***************************************************************************/
39 #include <sys/cdefs.h>
40 __KERNEL_RCSID(0, "$NetBSD: rf_alloclist.c,v 1.25 2006/11/16 01:33:23 christos Exp $");
42 #include <dev/raidframe/raidframevar.h>
44 #include "rf_options.h"
45 #include "rf_threadstuff.h"
46 #include "rf_alloclist.h"
47 #include "rf_debugMem.h"
48 #include "rf_etimer.h"
49 #include "rf_general.h"
50 #include "rf_shutdown.h"
51 #include "rf_netbsd.h"
53 #include <sys/pool.h>
55 #define RF_AL_FREELIST_MAX 256
56 #define RF_AL_FREELIST_MIN 64
58 static void rf_ShutdownAllocList(void *);
60 static void rf_ShutdownAllocList(void *ignored)
62 pool_destroy(&rf_pools.alloclist);
65 int
66 rf_ConfigureAllocList(RF_ShutdownList_t **listp)
69 rf_pool_init(&rf_pools.alloclist, sizeof(RF_AllocListElem_t),
70 "rf_alloclist_pl", RF_AL_FREELIST_MIN, RF_AL_FREELIST_MAX);
71 rf_ShutdownCreate(listp, rf_ShutdownAllocList, NULL);
73 return (0);
77 /* we expect the lists to have at most one or two elements, so we're willing
78 * to search for the end. If you ever observe the lists growing longer,
79 * increase POINTERS_PER_ALLOC_LIST_ELEMENT.
81 void
82 rf_real_AddToAllocList(RF_AllocListElem_t *l, void *p, int size)
84 RF_AllocListElem_t *newelem;
86 for (; l->next; l = l->next)
87 RF_ASSERT(l->numPointers == RF_POINTERS_PER_ALLOC_LIST_ELEMENT); /* find end of list */
89 RF_ASSERT(l->numPointers >= 0 && l->numPointers <= RF_POINTERS_PER_ALLOC_LIST_ELEMENT);
90 if (l->numPointers == RF_POINTERS_PER_ALLOC_LIST_ELEMENT) {
91 newelem = rf_real_MakeAllocList();
92 l->next = newelem;
93 l = newelem;
95 l->pointers[l->numPointers] = p;
96 l->sizes[l->numPointers] = size;
97 l->numPointers++;
101 void
102 rf_FreeAllocList(RF_AllocListElem_t *l)
104 int i;
105 RF_AllocListElem_t *temp, *p;
107 for (p = l; p; p = p->next) {
108 RF_ASSERT(p->numPointers >= 0 &&
109 p->numPointers <= RF_POINTERS_PER_ALLOC_LIST_ELEMENT);
110 for (i = 0; i < p->numPointers; i++) {
111 RF_ASSERT(p->pointers[i]);
112 RF_Free(p->pointers[i], p->sizes[i]);
115 while (l) {
116 temp = l;
117 l = l->next;
118 pool_put(&rf_pools.alloclist, temp);
122 RF_AllocListElem_t *
123 rf_real_MakeAllocList(void)
125 RF_AllocListElem_t *p;
127 p = pool_get(&rf_pools.alloclist, PR_WAITOK);
128 memset((char *) p, 0, sizeof(RF_AllocListElem_t));
129 return (p);