XINU
Functions | Variables
ptinit.c File Reference

ポートを用いたメッセージ送受信機能を初期化する。 More...

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

Go to the source code of this file.

Functions

syscall ptinit (int32 maxmsgs)
 全てのポートを初期化する。 More...
 

Variables

struct ptentry porttab [NPORTS]
 ポートテーブルエントリ More...
 
struct ptnodeptfree
 フリーメッセージノードのリスト More...
 
int32 ptnextid
 次に試みるテーブルエントリ More...
 

Detailed Description

ポートを用いたメッセージ送受信機能を初期化する。

Definition in file ptinit.c.

Function Documentation

◆ ptinit()

syscall ptinit ( int32  maxmsgs)

全てのポートを初期化する。

Step1. 全てのポート中の最大メッセージ数分だけメモリを確保する。
メモリが確保できなかった場合はpanic状態となり、再起動が必要となる。
Step2. 全てのポートテーブルエントリをFREE状態として初期化する。
Step3. フリーメッセージリストをリンクさせる。

Parameters
[in]maxmsgs全てのポート中の最大メッセージ数
Returns
初期化成功時はOK、メモリ確保失敗時はpanic状態となって再起動が必須となる。

Definition at line 24 of file ptinit.c.

References getmem(), NPORTS, NULL, OK, panic(), porttab, PT_FREE, ptnode::ptnext, ptnextid, ptentry::ptseq, ptentry::ptstate, and SYSERR.

25 {
26  int32 i; /* Runs through the port table */
27  struct ptnode *next, *curr; /* Used to build a free list */
28 
29  /* Allocate memory for all messages on all ports */
30 
31  ptfree = (struct ptnode *)getmem(maxmsgs * sizeof(struct ptnode));
32  if (ptfree == (struct ptnode *)SYSERR)
33  {
34  panic("ptinit - insufficient memory");
35  }
36 
37  /* Initialize all port table entries to free */
38 
39  for (i = 0; i < NPORTS; i++)
40  {
41  porttab[i].ptstate = PT_FREE;
42  porttab[i].ptseq = 0;
43  }
44  ptnextid = 0;
45 
46  /* Create a free list of message nodes linked together */
47 
48  for (curr = next = ptfree; --maxmsgs > 0; curr = next)
49  {
50  curr->ptnext = ++next;
51  }
52 
53  /* Set the pointer in the final node to NULL */
54 
55  curr->ptnext = NULL;
56  return OK;
57 }
#define NULL
連結リスト用のNULLポインタ
Definition: kernel.h:68
struct ptentry porttab[NPORTS]
ポートテーブルエントリ
Definition: ptinit.c:10
#define SYSERR
処理が失敗した場合
Definition: kernel.h:79
#define OK
処理が成功した場合
Definition: kernel.h:77
メッセージリストのノード
Definition: ports.h:21
#define NPORTS
ポートの最大数
Definition: ports.h:7
struct ptnode * ptfree
フリーメッセージノードのリスト
Definition: ptinit.c:8
struct ptnode * ptnext
メッセージリストの次のノードへのポインタ
Definition: ports.h:26
uint16 ptstate
ポート状態(FREE/LIMBO/ALLOC)
Definition: ports.h:40
int int32
符号あり32ビット整数(int)
Definition: kernel.h:11
void panic(char *)
Panic状態に陥った旨のメッセージを表示し、全てのプロセスを停止させる。
Definition: panic.c:12
#define PT_FREE
ポートがFREE状態
Definition: ports.h:11
int32 ptnextid
次に試みるテーブルエントリ
Definition: ptinit.c:12
int32 ptseq
生成時に変更されたシーケンス
Definition: ports.h:44
char * getmem(uint32)
ヒープ領域を割り当て、最下位のワードアドレスを返す。
Definition: getmem.c:25
Here is the call graph for this function:

Variable Documentation

◆ porttab

struct ptentry porttab[NPORTS]

ポートテーブルエントリ

ポートテーブルエントリのextern宣言

Definition at line 10 of file ptinit.c.

Referenced by ptcount(), ptcreate(), ptdelete(), ptinit(), ptrecv(), ptreset(), and ptsend().

◆ ptfree

struct ptnode* ptfree

フリーメッセージノードのリスト

フリーノードリストのextern宣言

Definition at line 8 of file ptinit.c.

Referenced by _ptclear(), ptrecv(), and ptsend().

◆ ptnextid

int32 ptnextid

次に試みるテーブルエントリ

空きスロットを探す際に試みる次のポートID

Definition at line 12 of file ptinit.c.

Referenced by ptcreate(), ptdelete(), and ptinit().