blob: 8d750b72a40256c4975d2a4c48410fa1b8eab50c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
/* ISC license. */
#include <errno.h>
#include <skalibs/genset.h>
void genset_init (genset_ref x, void *storage, unsigned int *freelist, unsigned int esize, unsigned int max)
{
register unsigned int i = 0 ;
x->storage = (char *)storage ;
x->freelist = freelist ;
x->esize = esize ;
x->max = max ;
x->sp = max ;
for (; i < max ; i++) freelist[i] = max - 1 - i ;
}
unsigned int genset_new (genset_ref x)
{
return x->sp ? x->freelist[--x->sp] : (errno = ENOSPC, x->max) ;
}
int genset_delete (genset_ref x, unsigned int i)
{
if ((i >= x->max) || (x->sp >= x->max)) return (errno = EINVAL, 0) ;
x->freelist[x->sp++] = i ;
return 1 ;
}
|