XINU
system
ptrecv.c
Go to the documentation of this file.
1
5
#include <
xinu.h
>
6
29
uint32
ptrecv
(
int32
portid)
30
{
31
intmask
mask;
/* Saved interrupt mask */
32
struct
ptentry
*ptptr;
/* Pointer to table entry */
33
int32
seq;
/* Local copy of sequence num. */
34
umsg32
msg;
/* Message to return */
35
struct
ptnode
*msgnode;
/* First node on message list */
36
37
mask =
disable
();
38
if
(
isbadport
(portid) ||
39
(ptptr = &
porttab
[portid])->ptstate !=
PT_ALLOC
)
40
{
41
restore
(mask);
42
return
(
uint32
)
SYSERR
;
43
}
44
45
/* Wait for message and verify that the port is still allocated */
46
47
seq = ptptr->
ptseq
;
/* Record orignal sequence */
48
if
(
wait
(ptptr->
ptrsem
) ==
SYSERR
|| ptptr->
ptstate
!=
PT_ALLOC
|| ptptr->
ptseq
!= seq)
49
{
50
restore
(mask);
51
return
(
uint32
)
SYSERR
;
52
}
53
54
/* Dequeue first message that is waiting in the port */
55
56
msgnode = ptptr->
pthead
;
57
msg = msgnode->
ptmsg
;
58
if
(ptptr->
pthead
== ptptr->
pttail
)
/* Delete last item */
59
ptptr->
pthead
= ptptr->
pttail
=
NULL
;
60
else
61
ptptr->
pthead
= msgnode->
ptnext
;
62
msgnode->
ptnext
=
ptfree
;
/* Return to free list */
63
ptfree
= msgnode;
64
signal
(ptptr->
ptssem
);
65
restore
(mask);
66
return
msg;
67
}
NULL
#define NULL
連結リスト用のNULLポインタ
Definition:
kernel.h:68
restore
void restore(intmask)
ptentry
ポートテーブルエントリ
Definition:
ports.h:33
isbadport
#define isbadport(portid)
ポートIDが不正値かどうかを確認する。
Definition:
ports.h:64
xinu.h
全てのシステムヘッダファイルをインクルードする。
SYSERR
#define SYSERR
処理が失敗した場合
Definition:
kernel.h:79
PT_ALLOC
#define PT_ALLOC
ポートが割り当てられた
Definition:
ports.h:15
ptentry::ptrsem
sid32 ptrsem
受信側セマフォ
Definition:
ports.h:38
ptnode
メッセージリストのノード
Definition:
ports.h:21
umsg32
uint32 umsg32
プロセス間で渡されるメッセージ
Definition:
kernel.h:32
porttab
struct ptentry porttab[]
ポートテーブルエントリのextern宣言
Definition:
ptinit.c:10
ptnode::ptnext
struct ptnode * ptnext
メッセージリストの次のノードへのポインタ
Definition:
ports.h:26
ptentry::ptssem
sid32 ptssem
送信側セマフォ
Definition:
ports.h:36
ptentry::ptstate
uint16 ptstate
ポート状態(FREE/LIMBO/ALLOC)
Definition:
ports.h:40
intmask
uint32 intmask
保存された割り込みマスク
Definition:
kernel.h:38
int32
int int32
符号あり32ビット整数(int)
Definition:
kernel.h:11
ptentry::pttail
struct ptnode * pttail
メッセージリストの末尾ポインタ
Definition:
ports.h:48
ptnode::ptmsg
uint32 ptmsg
ワンワードのメッセージ
Definition:
ports.h:24
wait
syscall wait(sid32)
Definition:
wait.c:9
signal
syscall signal(sid32)
セマフォにシグナルを送り、待機プロセスがある場合は解除する。
Definition:
signal.c:18
ptrecv
uint32 ptrecv(int32 portid)
ポートからメッセージを受信する。受信前にメッセージが空の場合はブロッキングする。
Definition:
ptrecv.c:29
uint32
unsigned int uint32
符号なし32ビット整数(unsigned int)
Definition:
kernel.h:15
ptentry::pthead
struct ptnode * pthead
メッセージリストの先頭ポインタ
Definition:
ports.h:46
ptentry::ptseq
int32 ptseq
生成時に変更されたシーケンス
Definition:
ports.h:44
disable
intmask disable(void)
割り込み禁止(intr.Sに定義がある)
ptfree
struct ptnode * ptfree
フリーノードリストのextern宣言
Definition:
ptinit.c:8
Generated by
1.8.13