#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: rf_alloclist.c,v 1.29 2021/07/23 00:54:45 oster Exp $");
#include <dev/raidframe/raidframevar.h>
#include "rf_options.h"
#include "rf_threadstuff.h"
#include "rf_alloclist.h"
#include "rf_debugMem.h"
#include "rf_etimer.h"
#include "rf_general.h"
#include "rf_shutdown.h"
#include "rf_netbsd.h"
#include <sys/pool.h>
#define RF_AL_FREELIST_MAX 256
#define RF_AL_FREELIST_MIN 64
static void rf_ShutdownAllocList(void *);
static void rf_ShutdownAllocList(void *ignored)
{
pool_destroy(&rf_alloclist_pool);
}
int
rf_ConfigureAllocList(RF_ShutdownList_t **listp)
{
pool_init(&rf_alloclist_pool, sizeof(RF_AllocListElem_t), 0, 0, 0, "rf_alloclist_pl", NULL, IPL_BIO);
pool_sethiwat(&rf_alloclist_pool, RF_AL_FREELIST_MAX);
pool_prime(&rf_alloclist_pool, RF_AL_FREELIST_MIN);
rf_ShutdownCreate(listp, rf_ShutdownAllocList, NULL);
return (0);
}
void
rf_real_AddToAllocList(RF_AllocListElem_t *l, void *p, int size)
{
RF_AllocListElem_t *newelem;
for (; l->next; l = l->next)
RF_ASSERT(l->numPointers == RF_POINTERS_PER_ALLOC_LIST_ELEMENT);
RF_ASSERT(l->numPointers >= 0 && l->numPointers <= RF_POINTERS_PER_ALLOC_LIST_ELEMENT);
if (l->numPointers == RF_POINTERS_PER_ALLOC_LIST_ELEMENT) {
newelem = rf_real_MakeAllocList();
l->next = newelem;
l = newelem;
}
l->pointers[l->numPointers] = p;
l->sizes[l->numPointers] = size;
l->numPointers++;
}
void
rf_FreeAllocList(RF_AllocListElem_t *l)
{
int i;
RF_AllocListElem_t *temp, *p;
for (p = l; p; p = p->next) {
RF_ASSERT(p->numPointers >= 0 &&
p->numPointers <= RF_POINTERS_PER_ALLOC_LIST_ELEMENT);
for (i = 0; i < p->numPointers; i++) {
RF_ASSERT(p->pointers[i]);
RF_Free(p->pointers[i], p->sizes[i]);
}
}
while (l) {
temp = l;
l = l->next;
pool_put(&rf_alloclist_pool, temp);
}
}
RF_AllocListElem_t *
rf_real_MakeAllocList(void)
{
return pool_get(&rf_alloclist_pool, PR_WAITOK | PR_ZERO);
}