XINU
Functions
semcount.c File Reference

セマフォのカウント値を返す。 More...

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

Go to the source code of this file.

Functions

syscall semcount (sid32 semid)
 セマフォのカウント値を返す。 More...
 

Detailed Description

セマフォのカウント値を返す。

Definition in file semcount.c.

Function Documentation

◆ semcount()

syscall semcount ( sid32  semid)

セマフォのカウント値を返す。

Step1. 割り込みを禁止する。
Step2. 「セマフォIDが不正値」か「セマフォがFREE状態」の場合、割り込み許可状態に復元して、処理を終了する。
Step3. 引数で渡されたセマフォIDを基に、セマフォテーブルからセマフォのカウント値を取得する。
Step4. 割り込み許可状態に復元する。

Parameters
[in]semidセマフォカウンタを確認したいセマフォのID
Returns
成功時はセマフォのカウント値、「不正なセマフォID」や「セマフォがFREE状態の場合はSYSERR」を返す。
Note
セマフォカウンタ値が整数値(正負問わず)のため、SYSERR(-1)と同じ値になる可能性がある。

Definition at line 18 of file semcount.c.

References disable(), isbadsem, restore(), S_FREE, sentry::scount, semtab, and SYSERR.

Referenced by ethhandler(), ip_enqueue(), ptcount(), rdswrite(), ttycontrol(), ttyhandle_in(), ttyhandle_out(), and ttyread().

19 {
20  intmask mask; /* Saved interrupt mask */
21  int32 count; /* Current sempahore count */
22 
23  mask = disable();
24 
25  if (isbadsem(semid) || semtab[semid].sstate == S_FREE)
26  {
27  restore(mask);
28  return SYSERR;
29  }
30  count = semtab[semid].scount;
31  restore(mask);
32  return count;
33 }
void restore(intmask)
#define SYSERR
処理が失敗した場合
Definition: kernel.h:79
#define isbadsem(s)
セマフォIDが不適切かどうかを確認する。
Definition: semaphore.h:40
uint32 intmask
保存された割り込みマスク
Definition: kernel.h:38
int int32
符号あり32ビット整数(int)
Definition: kernel.h:11
int32 scount
セマフォカウント(負の値(-N)の場合は、キューにN個の待機プロセスがある。それ以外はキューが空である) ...
Definition: semaphore.h:24
#define S_FREE
セマフォテーブルエントリが利用可能
Definition: semaphore.h:11
struct sentry semtab[]
セマフォテーブルエントリのextern宣言
Definition: initialize.c:25
intmask disable(void)
割り込み禁止(intr.Sに定義がある)
Here is the call graph for this function:
Here is the caller graph for this function: