XINU
system
getbuf.c
Go to the documentation of this file.
1
5
#include <
xinu.h
>
6
19
char
*
getbuf
(
bpid32
poolid)
20
{
21
intmask
mask;
/* Saved interrupt mask */
22
struct
bpentry
*bpptr;
/* Pointer to entry in buftab */
23
struct
bpentry
*bufptr;
/* Pointer to a buffer */
24
25
mask =
disable
();
26
27
/* Check arguments */
28
29
if
((poolid < 0 || poolid >=
nbpools
))
30
{
31
restore
(mask);
32
return
(
char
*)
SYSERR
;
33
}
34
bpptr = &
buftab
[poolid];
35
36
/* Wait for pool to have > 0 buffers and allocate a buffer */
37
38
wait
(bpptr->
bpsem
);
39
bufptr = bpptr->
bpnext
;
40
41
/* Unlink buffer from pool */
42
43
bpptr->
bpnext
= bufptr->
bpnext
;
44
45
/* Record pool ID in first four bytes of buffer and skip */
46
47
*(
bpid32
*)bufptr = poolid;
48
bufptr = (
struct
bpentry
*)(
sizeof
(
bpid32
) + (
char
*)bufptr);
49
restore
(mask);
50
return
(
char
*)bufptr;
51
}
buftab
struct bpentry buftab[]
バッファプールテーブルのextern宣言
Definition:
bufinit.c:8
restore
void restore(intmask)
xinu.h
全てのシステムヘッダファイルをインクルードする。
SYSERR
#define SYSERR
処理が失敗した場合
Definition:
kernel.h:79
bpid32
int32 bpid32
バッファプールID
Definition:
kernel.h:34
nbpools
bpid32 nbpools
割り当てられたバッファプールの現在の数
Definition:
bufinit.c:10
bpentry::bpsem
sid32 bpsem
バッファプールで現在使用可能なバッファをカウントするセマフォ
Definition:
bufpool.h:32
bpentry::bpnext
struct bpentry * bpnext
次のフリーバッファへのポインタ
Definition:
bufpool.h:30
bpentry
バッファプールテーブルエントリ
Definition:
bufpool.h:27
intmask
uint32 intmask
保存された割り込みマスク
Definition:
kernel.h:38
getbuf
char * getbuf(bpid32 poolid)
事前に確保されたバッファプールからバッファを取得する。
Definition:
getbuf.c:19
wait
syscall wait(sid32)
Definition:
wait.c:9
disable
intmask disable(void)
割り込み禁止(intr.Sに定義がある)
Generated by
1.8.13