~kris/9p

9hist

ref: 995bfb15bd0a26b95cb56dc4dc60a8bf33c60141 9hist/pc/bbmalloc.c -rw-r--r-- 1.2 KiB
995bfb15 — David du Colombier Plan 9 from Bell Labs 1993-08-08 33 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#include	"u.h"
#include	"../port/lib.h"
#include	"mem.h"
#include	"dat.h"
#include	"fns.h"
#include	"io.h"

/*
 * Allocate memory for use in kernel bitblts.
 *
 * This code will have to be interlocked if we ever get
 * a multiprocessor with a bitmapped display.
 */

/* a 0->3 bitblt can take 800 longs */
enum {
	narena=2,	/* put interrupt time stuff in separate arena */
	nbbarena=4096	/* number of words in an arena */
};

static ulong	*bbarena[narena];
static ulong	*bbcur[narena];
static ulong	*bblast[narena];

#define INTENABLED(v)	((v)&(1<<9))
void *
bbmalloc(int nbytes)
{
	int nw, a;
	int s;
	ulong *ans;

	nw = nbytes/sizeof(long);
	s = splhi();
	a = INTENABLED(s) ? 0 : 1;
	if(bbcur[a] + nw > bbarena[a] + nbbarena)
		ans = bbarena[a];
	else
		ans = bbcur[a];
	bbcur[a] = ans + nw;
	bblast[a] = ans;
	splx(s);
	return ans;
}

void
bbinit(void)
{
	int i;

	if(bbarena[0])
		return;
	for(i = 0; i < narena; i++){
		bbarena[i] = xalloc(nbbarena * sizeof(long));
		bbcur[i] = bbarena[i];
		bblast[i] = 0;
	}
}


void
bbfree(void *p, int n)
{
	int a, s;

	s = splhi();
	a = INTENABLED(s) ? 0 : 1;
	if(p == bblast[a])
		bbcur[a] = (ulong *)(((char *)bblast[a]) + n);
	splx(s);
}

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

int
bbonstack(void)
{
	return 0;
}