XINU
Functions
ptcreate.c File Reference

未処理のメッセージを「カウント」できるポートを作成する。 More...

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

Go to the source code of this file.

Functions

syscall ptcreate (int32 count)
 未処理のメッセージを「カウント」できるポートを作成する。 More...
 

Detailed Description

未処理のメッセージを「カウント」できるポートを作成する。

Definition in file ptcreate.c.

Function Documentation

◆ ptcreate()

syscall ptcreate ( int32  count)

未処理のメッセージを「カウント」できるポートを作成する。

Step1. 割り込みを禁止する。
Step2. ポートサイズが0より小さい場合は割り込み状態を復元し、処理を終了する。
Step3. 0〜NPORTS(30)の中で、空きポートIDを探す。
Step4. 空きポートに以下の対応を行う。
 ・状態をALLOCに変更
 ・送受信セマフォを作成
 ・メッセージリストを初期化(先頭と末尾をNULLとする)
 ・シーケンス番号を1増加
 ・最大待機メッセージ数を設定
Step5. 割り込み状態を復元する。

Parameters
[in]countポートサイズ(未処理メッセージの最大数)
Returns
成功時は割り当てたポートID、ポートサイズが不正な場合はSYSERRを返す。

Definition at line 23 of file ptcreate.c.

References disable(), NPORTS, NULL, porttab, PT_ALLOC, PT_FREE, ptentry::pthead, ptentry::ptmaxcnt, ptnextid, ptentry::ptrsem, ptentry::ptseq, ptentry::ptssem, ptentry::ptstate, ptentry::pttail, restore(), semcreate(), and SYSERR.

24 {
25  intmask mask; /* Saved interrupt mask */
26  int32 i; /* Counts all possible ports */
27  int32 ptnum; /* Candidate port number to try */
28  struct ptentry *ptptr; /* Pointer to port table entry */
29 
30  mask = disable();
31  if (count < 0)
32  {
33  restore(mask);
34  return SYSERR;
35  }
36 
37  for (i = 0; i < NPORTS; i++)
38  { /* Count all table entries */
39  ptnum = ptnextid; /* Get an entry to check */
40  if (++ptnextid >= NPORTS)
41  {
42  ptnextid = 0; /* Reset for next iteration */
43  }
44 
45  /* Check table entry that corresponds to ID ptnum */
46 
47  ptptr = &porttab[ptnum];
48  if (ptptr->ptstate == PT_FREE)
49  {
50  ptptr->ptstate = PT_ALLOC;
51  ptptr->ptssem = semcreate(count);
52  ptptr->ptrsem = semcreate(0);
53  ptptr->pthead = ptptr->pttail = NULL;
54  ptptr->ptseq++;
55  ptptr->ptmaxcnt = count;
56  restore(mask);
57  return ptnum;
58  }
59  }
60  restore(mask);
61  return SYSERR;
62 }
#define NULL
連結リスト用のNULLポインタ
Definition: kernel.h:68
sid32 semcreate(int32)
未使用セマフォを割り当て、そのセマフォへのインデックス(セマフォID)を返す。
Definition: semcreate.c:22
void restore(intmask)
ポートテーブルエントリ
Definition: ports.h:33
#define SYSERR
処理が失敗した場合
Definition: kernel.h:79
#define PT_ALLOC
ポートが割り当てられた
Definition: ports.h:15
sid32 ptrsem
受信側セマフォ
Definition: ports.h:38
uint16 ptmaxcnt
ポートに挿入できる最大メッセージ数
Definition: ports.h:42
#define NPORTS
ポートの最大数
Definition: ports.h:7
struct ptentry porttab[]
ポートテーブルエントリのextern宣言
Definition: ptinit.c:10
sid32 ptssem
送信側セマフォ
Definition: ports.h:36
uint16 ptstate
ポート状態(FREE/LIMBO/ALLOC)
Definition: ports.h:40
uint32 intmask
保存された割り込みマスク
Definition: kernel.h:38
int int32
符号あり32ビット整数(int)
Definition: kernel.h:11
int32 ptnextid
空きスロットを探す際に試みる次のポートID
Definition: ptinit.c:12
struct ptnode * pttail
メッセージリストの末尾ポインタ
Definition: ports.h:48
#define PT_FREE
ポートがFREE状態
Definition: ports.h:11
struct ptnode * pthead
メッセージリストの先頭ポインタ
Definition: ports.h:46
int32 ptseq
生成時に変更されたシーケンス
Definition: ports.h:44
intmask disable(void)
割り込み禁止(intr.Sに定義がある)
Here is the call graph for this function: