XINU
system
insertd.c
Go to the documentation of this file.
1
/* insertd.c - insertd */
2
3
#include <
xinu.h
>
4
5
/*------------------------------------------------------------------------
6
* insertd - Insert a process in delta list using delay as the key
7
*------------------------------------------------------------------------
8
*/
9
status
insertd
(
/* Assumes interrupts disabled */
10
pid32
pid,
/* ID of process to insert */
11
qid16
q,
/* ID of queue to use */
12
int32
key
/* Delay from "now" (in ms.) */
13
)
14
{
15
int32
next;
/* Runs through the delta list */
16
int32
prev;
/* Follows next through the list*/
17
18
if
(
isbadqid
(q) ||
isbadpid
(pid)) {
19
return
SYSERR
;
20
}
21
22
prev =
queuehead
(q);
23
next =
queuetab
[
queuehead
(q)].
qnext
;
24
while
((next !=
queuetail
(q)) && (
queuetab
[next].qkey <= key)) {
25
key -=
queuetab
[next].
qkey
;
26
prev = next;
27
next =
queuetab
[next].
qnext
;
28
}
29
30
/* Insert new node between prev and next nodes */
31
32
queuetab
[pid].
qnext
= next;
33
queuetab
[pid].
qprev
= prev;
34
queuetab
[pid].
qkey
= key;
35
queuetab
[prev].
qnext
= pid;
36
queuetab
[next].
qprev
= pid;
37
if
(next !=
queuetail
(q)) {
38
queuetab
[next].
qkey
-= key;
39
}
40
41
return
OK
;
42
}
queuetab
struct qentry queuetab[]
Definition:
queue.c:45
xinu.h
全てのシステムヘッダファイルをインクルードする。
isbadpid
#define isbadpid(x)
プロセスIDを検証する。割り込みが無効になっている事を想定している。
Definition:
process.h:71
SYSERR
#define SYSERR
処理が失敗した場合
Definition:
kernel.h:79
insertd
status insertd(pid32 pid, qid16 q, int32 key)
Definition:
insertd.c:9
queuehead
#define queuehead(q)
キューの先頭を返す。
Definition:
queue.h:53
OK
#define OK
処理が成功した場合
Definition:
kernel.h:77
isbadqid
#define isbadqid(x)
キューIDが不正値かどうかをチェックする。
Definition:
queue.h:132
status
int32 status
ステータスを意味する返り値の型(OK/SYSERR)
Definition:
kernel.h:57
qentry::qnext
qid16 qnext
次のプロセスか末尾のプロセスのインデックス。
Definition:
queue.h:39
qentry::qkey
int32 qkey
キュー順序を決定するキー(優先度)。
Definition:
queue.h:37
qentry::qprev
qid16 qprev
前のプロセスか先頭のプロセスのインデックス。
Definition:
queue.h:41
int32
int int32
符号あり32ビット整数(int)
Definition:
kernel.h:11
qid16
int16 qid16
キューID
Definition:
kernel.h:24
pid32
int32 pid32
プロセスID
Definition:
kernel.h:26
queuetail
#define queuetail(q)
キューの末尾を返す。
Definition:
queue.h:61
Generated by
1.8.13