XINU
ptclear.c
Go to the documentation of this file.
1 
5 #include <xinu.h>
6 
24 void _ptclear(struct ptentry *ptptr, uint16 newstate, int32 (*dispose)(int32))
25 {
26  struct ptnode *walk; /* Pointer to walk message list */
27 
28  /* Place port in limbo state while waiting processes are freed */
29 
30  ptptr->ptstate = PT_LIMBO;
31 
32  ptptr->ptseq++; /* Reset accession number */
33  walk = ptptr->pthead; /* First item on msg list */
34 
35  if (walk != NULL)
36  { /* If message list nonempty */
37 
38  /* Walk message list and dispose of each message */
39 
40  for (; walk != NULL; walk = walk->ptnext)
41  {
42  (*dispose)(walk->ptmsg);
43  }
44 
45  /* Link entire message list into the free list */
46 
47  (ptptr->pttail)->ptnext = ptfree;
48  ptfree = ptptr->pthead;
49  }
50 
51  if (newstate == PT_ALLOC)
52  {
53  ptptr->pttail = ptptr->pthead = NULL;
54  semreset(ptptr->ptssem, ptptr->ptmaxcnt);
55  semreset(ptptr->ptrsem, 0);
56  }
57  else
58  {
59  semdelete(ptptr->ptssem);
60  semdelete(ptptr->ptrsem);
61  }
62  ptptr->ptstate = newstate;
63  return;
64 }
#define NULL
連結リスト用のNULLポインタ
Definition: kernel.h:68
ポートテーブルエントリ
Definition: ports.h:33
全てのシステムヘッダファイルをインクルードする。
#define PT_ALLOC
ポートが割り当てられた
Definition: ports.h:15
void _ptclear(struct ptentry *ptptr, uint16 newstate, int32(*dispose)(int32))
ポートを用いたメッセージと待機中プロセスを解放する。
Definition: ptclear.c:24
sid32 ptrsem
受信側セマフォ
Definition: ports.h:38
uint16 ptmaxcnt
ポートに挿入できる最大メッセージ数
Definition: ports.h:42
syscall semdelete(sid32)
セマフォテーブルエントリを解放し、セマフォを削除する。
Definition: semdelete.c:22
メッセージリストのノード
Definition: ports.h:21
#define PT_LIMBO
ポートが削除された、もしくはリセットされる
Definition: ports.h:13
struct ptnode * ptnext
メッセージリストの次のノードへのポインタ
Definition: ports.h:26
sid32 ptssem
送信側セマフォ
Definition: ports.h:36
uint16 ptstate
ポート状態(FREE/LIMBO/ALLOC)
Definition: ports.h:40
int int32
符号あり32ビット整数(int)
Definition: kernel.h:11
unsigned short uint16
符号なし16ビット整数(unsigned short)
Definition: kernel.h:17
syscall semreset(sid32, int32)
セマフォカウントをリセットし、待機中のプロセスを全て解放する。
Definition: semreset.c:25
struct ptnode * pttail
メッセージリストの末尾ポインタ
Definition: ports.h:48
uint32 ptmsg
ワンワードのメッセージ
Definition: ports.h:24
struct ptnode * pthead
メッセージリストの先頭ポインタ
Definition: ports.h:46
int32 ptseq
生成時に変更されたシーケンス
Definition: ports.h:44
struct ptnode * ptfree
フリーノードリストのextern宣言
Definition: ptinit.c:8