screate.c,v
来自「TCP-IP红宝书源代码」· C,V 代码 · 共 74 行
C,V
74 行
head 1.1;
access;
symbols;
locks
dls:1.1; strict;
comment @ * @;
1.1
date 97.09.21.19.29.30; author dls; state Dist;
branches;
next ;
desc
@@
1.1
log
@pre-3e code
@
text
@/* screate.c - screate, newsem */
#include <conf.h>
#include <kernel.h>
#include <proc.h>
#include <q.h>
#include <sem.h>
/*------------------------------------------------------------------------
* screate -- create and initialize a semaphore, returning its id
*------------------------------------------------------------------------
*/
SYSCALL screate(count)
int count; /* initial count (>=0) */
{
STATWORD ps;
int sem;
disable(ps);
if ( count<0 || (sem=newsem())==SYSERR ) {
restore(ps);
return(SYSERR);
}
semaph[sem].semcnt = count;
/* sqhead and sqtail were initialized at system startup */
restore(ps);
return(sem);
}
/*------------------------------------------------------------------------
* newsem -- allocate an unused semaphore and return its index
*------------------------------------------------------------------------
*/
LOCAL newsem()
{
int sem;
int i;
for (i=0 ; i<NSEM ; i++) {
sem=nextsem--;
if (nextsem < 0)
nextsem = NSEM-1;
if (semaph[sem].sstate==SFREE) {
semaph[sem].sstate = SUSED;
return(sem);
}
}
return(SYSERR);
}
@
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?