XINU
Functions
getbuf.c File Reference

事前に確保されたバッファプールからバッファを取得する。 More...

#include <xinu.h>
Include dependency graph for getbuf.c:

Go to the source code of this file.

Functions

char * getbuf (bpid32 poolid)
 事前に確保されたバッファプールからバッファを取得する。 More...
 

Detailed Description

事前に確保されたバッファプールからバッファを取得する。

Definition in file getbuf.c.

Function Documentation

◆ getbuf()

char* getbuf ( bpid32  poolid)

事前に確保されたバッファプールからバッファを取得する。

Step1. 割り込みを禁止する。
Step2. バッファプールIDが不正値の場合は、割り込み状態を復元し、処理を終了する。
Step3. バッファプールに使用できるバッファが用意されるまで、待機する。
Step4. 提供するバッファをプール(リスト)から切り離す。
Step5. 提供するバッファの先頭4byteにバッファプールIDを記録し、4Byte分だけバッファのポインタを進める。
Step6. 割り込み状態を復元する。

Parameters
[in]poolidバッファテーブル中のバッファプールID
Returns
成功時はバッファへのポインタ、バッファプールIDが不正の場合はSYSERRを返す。

Definition at line 19 of file getbuf.c.

References bpentry::bpnext, bpentry::bpsem, buftab, disable(), nbpools, restore(), SYSERR, and wait().

Referenced by icmp_mkpkt(), netin(), udp_send(), and udp_sendto().

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 }
struct bpentry buftab[]
バッファプールテーブルのextern宣言
Definition: bufinit.c:8
void restore(intmask)
#define SYSERR
処理が失敗した場合
Definition: kernel.h:79
int32 bpid32
バッファプールID
Definition: kernel.h:34
bpid32 nbpools
割り当てられたバッファプールの現在の数
Definition: bufinit.c:10
sid32 bpsem
バッファプールで現在使用可能なバッファをカウントするセマフォ
Definition: bufpool.h:32
struct bpentry * bpnext
次のフリーバッファへのポインタ
Definition: bufpool.h:30
バッファプールテーブルエントリ
Definition: bufpool.h:27
uint32 intmask
保存された割り込みマスク
Definition: kernel.h:38
syscall wait(sid32)
Definition: wait.c:9
intmask disable(void)
割り込み禁止(intr.Sに定義がある)
Here is the call graph for this function:
Here is the caller graph for this function: