1 /* libsockevent - sockevent_proc.c - process suspension state management */
2 
3 #include <minix/drivers.h>
4 #include <minix/sockdriver.h>
5 
6 #include "sockevent_proc.h"
7 
8 static struct sockevent_proc sockevent_procs[NR_PROCS];
9 static struct sockevent_proc *sockevent_freeprocs;
10 
11 /*
12  * Initialize the process suspension table.
13  */
14 void
15 sockevent_proc_init(void)
16 {
17 	unsigned int slot;
18 
19 	for (slot = 0; slot < __arraycount(sockevent_procs); slot++) {
20 		sockevent_procs[slot].spr_next = sockevent_freeprocs;
21 		sockevent_freeprocs = &sockevent_procs[slot];
22 	}
23 }
24 
25 /*
26  * Allocate and return a new socket process suspension entry.  Return NULL if
27  * no entries are available.
28  */
29 struct sockevent_proc *
30 sockevent_proc_alloc(void)
31 {
32 	struct sockevent_proc *spr;
33 
34 	if ((spr = sockevent_freeprocs) == NULL)
35 		return NULL;
36 
37 	sockevent_freeprocs = spr->spr_next;
38 	spr->spr_next = NULL;
39 
40 	return spr;
41 }
42 
43 /*
44  * Free up a previously allocated socket process suspension entry for reuse.
45  */
46 void
47 sockevent_proc_free(struct sockevent_proc * spr)
48 {
49 
50 	spr->spr_next = sockevent_freeprocs;
51 	sockevent_freeprocs = spr;
52 }
53