XINU
mark.c
Go to the documentation of this file.
1 /* mark.c - markinit, mark */
2 
3 #include <xinu.h>
4 
5 int32 *marks[MAXMARK]; /* Pointers to marked locations */
6 int32 nmarks; /* Number of marked locations */
7 sid32 mkmutex; /* Mutual exclusion semaphore */
8 
9 /*------------------------------------------------------------------------
10  * markinit - Called once at system startup
11  *------------------------------------------------------------------------
12  */
13 void markinit(void)
14 {
15  nmarks = 0;
16  mkmutex = semcreate(1);
17 }
18 
19 
20 /*------------------------------------------------------------------------
21  * mark - Mark a specified memory location
22  *------------------------------------------------------------------------
23  */
25  int32 *loc /* Location to mark */
26  )
27 {
28 
29  /* If location is already marked, do nothing */
30 
31  if ( (*loc>=0) && (*loc<nmarks) && (marks[*loc]==loc) ) {
32  return OK;
33  }
34 
35  /* If no more memory marks are available, indicate an error */
36 
37  if (nmarks >= MAXMARK) {
38  return SYSERR;
39  }
40 
41  /* Obtain exclusive access and mark the specified location */
42 
43  wait(mkmutex);
44  marks[ (*loc) = nmarks++ ] = loc;
45  signal(mkmutex);
46  return OK;
47 }
void markinit(void)
Definition: mark.c:13
int32 * marks[MAXMARK]
Definition: mark.c:5
sid32 semcreate(int32)
未使用セマフォを割り当て、そのセマフォへのインデックス(セマフォID)を返す。
Definition: semcreate.c:22
全てのシステムヘッダファイルをインクルードする。
#define SYSERR
処理が失敗した場合
Definition: kernel.h:79
#define OK
処理が成功した場合
Definition: kernel.h:77
int32 status
ステータスを意味する返り値の型(OK/SYSERR)
Definition: kernel.h:57
int32 nmarks
Definition: mark.c:6
sid32 mkmutex
Definition: mark.c:7
status mark(int32 *loc)
Definition: mark.c:24
int int32
符号あり32ビット整数(int)
Definition: kernel.h:11
syscall wait(sid32)
Definition: wait.c:9
syscall signal(sid32)
セマフォにシグナルを送り、待機プロセスがある場合は解除する。
Definition: signal.c:18
#define MAXMARK
Definition: mark.h:3
int32 sid32
セマフォID
Definition: kernel.h:22