summaryrefslogtreecommitdiff
path: root/minix/lib/libsockevent/sockevent_proc.c
blob: df5e3a91f2ef4ab992cae5cc4b44b7dc7e2b6438 (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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/* libsockevent - sockevent_proc.c - process suspension state management */

#include <minix/drivers.h>
#include <minix/sockdriver.h>

#include "sockevent_proc.h"

static struct sockevent_proc sockevent_procs[NR_PROCS];
static struct sockevent_proc *sockevent_freeprocs;

/*
 * Initialize the process suspension table.
 */
void
sockevent_proc_init(void)
{
	unsigned int slot;

	for (slot = 0; slot < __arraycount(sockevent_procs); slot++) {
		sockevent_procs[slot].spr_next = sockevent_freeprocs;
		sockevent_freeprocs = &sockevent_procs[slot];
	}
}

/*
 * Allocate and return a new socket process suspension entry.  Return NULL if
 * no entries are available.
 */
struct sockevent_proc *
sockevent_proc_alloc(void)
{
	struct sockevent_proc *spr;

	if ((spr = sockevent_freeprocs) == NULL)
		return NULL;

	sockevent_freeprocs = spr->spr_next;
	spr->spr_next = NULL;

	return spr;
}

/*
 * Free up a previously allocated socket process suspension entry for reuse.
 */
void
sockevent_proc_free(struct sockevent_proc * spr)
{

	spr->spr_next = sockevent_freeprocs;
	sockevent_freeprocs = spr;
}