~kris/9p

9hist

ref: 79da173a13d9b0451908d337f5c516c9e5f8372f 9hist/pc/bbmalloc.c -rw-r--r-- 700 bytes
79da173a — David du Colombier Plan 9 from Bell Labs 1991-11-02 34 years ago
                                                                                
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
53
#include	"u.h"
#include	"lib.h"
#include	"mem.h"
#include	"dat.h"
#include	"fns.h"

static	char	bbarena[10000];
static	char	bbused[10];

void*
bbmalloc(int n)
{
	char *a;
	int s, i;

	s = splhi();
	a = memchr(bbused, 0, sizeof(bbused));
	if(a) {
		i = a - bbused;
		a = bbarena + i*n;
		if(a+n <= bbarena+sizeof(bbarena)) {
			bbused[i] = 1;
			splx(s);
			return a;
		}
	}
	splx(s);
	print("too many bbmallocs\n");
	return bbarena;
}

void
bbfree(void *va, int n)
{
	int s, i;

	s = splhi();
	i = ((char*)va - bbarena) /n;
	if(i >= 0 && i < sizeof(bbused) && bbused[i]){
		bbused[i] = 0;
		splx(s);
		return;
	}
	splx(s);
	print("sanity bbfree\n");
}

void*
bbdflush(void *p, int n)
{
	return p;
}