XINU
suspend.c
Go to the documentation of this file.
1 
5 #include <xinu.h>
6 
24 {
25  intmask mask; /* Saved interrupt mask */
26  struct procent *prptr; /* Ptr to process's table entry */
27  pri16 prio; /* Priority to return */
28 
29  mask = disable();
30  if (isbadpid(pid) || (pid == NULLPROC))
31  {
32  restore(mask);
33  return SYSERR;
34  }
35 
36  /* Only suspend a process that is current or ready */
37 
38  prptr = &proctab[pid];
39  if ((prptr->prstate != PR_CURR) && (prptr->prstate != PR_READY))
40  {
41  restore(mask);
42  return SYSERR;
43  }
44  if (prptr->prstate == PR_READY)
45  {
46  getitem(pid); /* Remove a ready process */
47  /* from the ready list */
48  prptr->prstate = PR_SUSP;
49  }
50  else
51  {
52  prptr->prstate = PR_SUSP; /* Mark the current process */
53  resched(); /* suspended and resched. */
54  }
55  prio = prptr->prprio;
56  restore(mask);
57  return prio;
58 }
void restore(intmask)
#define PR_READY
プロセスが準備完了(READY)状態。
Definition: process.h:39
#define PR_SUSP
プロセスがサスペンド(休止)させられた状態。
Definition: process.h:45
全てのシステムヘッダファイルをインクルードする。
#define isbadpid(x)
プロセスIDを検証する。割り込みが無効になっている事を想定している。
Definition: process.h:71
#define SYSERR
処理が失敗した場合
Definition: kernel.h:79
int16 pri16
プロセス優先度
Definition: kernel.h:30
#define NULLPROC
NULLプロセスのID。NULLプロセスは、他に動かすプロセスがない時に動く空プロセス
Definition: process.h:54
pri16 prprio
プロセスのスケジューリング優先度。
Definition: process.h:90
#define PR_CURR
プロセスが現在動作中。
Definition: process.h:37
uint32 intmask
保存された割り込みマスク
Definition: kernel.h:38
uint16 prstate
プロセス状態(PR_CURR, ..., etc)。
Definition: process.h:88
void resched(void)
最優先の適切なプロセスにCPU実行権を渡す。
Definition: resched.c:22
pid32 getitem(pid32)
キューの任意の位置からプロセスを取り出す。
Definition: getitem.c:51
struct procent proctab[]
プロセステーブル。
Definition: initialize.c:23
int32 syscall
システムコール関数 返り値の型
Definition: kernel.h:47
int32 pid32
プロセスID
Definition: kernel.h:26
プロセステーブル(32bitsの倍数)。
Definition: process.h:85
syscall suspend(pid32 pid)
プロセスを一時停止し、休止状態(サスペンド)に遷移させる。
Definition: suspend.c:23
intmask disable(void)
割り込み禁止(intr.Sに定義がある)