Annotation of xinu/sys/screate.c, revision 1.1.1.1

1.1       root        1: /* screate.c - screate, newsem */
                      2: 
                      3: #include <conf.h>
                      4: #include <kernel.h>
                      5: #include <proc.h>
                      6: #include <q.h>
                      7: #include <sem.h>
                      8: 
                      9: /*------------------------------------------------------------------------
                     10:  * screate  --  create and initialize a semaphore, returning its id
                     11:  *------------------------------------------------------------------------
                     12:  */
                     13: SYSCALL screate(count)
                     14:        int     count;                  /* initial count (>=0)          */
                     15: {
                     16:        PStype  ps;
                     17:        int     sem;
                     18: 
                     19:        disable(ps);
                     20:        if ( count<0 || (sem=newsem())==SYSERR ) {
                     21:                restore(ps);
                     22:                return(SYSERR);
                     23:        }
                     24:        semaph[sem].semcnt = count;
                     25:        /* sqhead and sqtail were initialized at system startup */
                     26:        restore(ps);
                     27:        return(sem);
                     28: }
                     29: 
                     30: /*------------------------------------------------------------------------
                     31:  * newsem  --  allocate an unused semaphore and return its index
                     32:  *------------------------------------------------------------------------
                     33:  */
                     34: LOCAL  newsem()
                     35: {
                     36:        int     sem;
                     37:        int     i;
                     38: 
                     39:        for (i=0 ; i<NSEM ; i++) {
                     40:                sem=nextsem--;
                     41:                if (nextsem < 0)
                     42:                        nextsem = NSEM-1;
                     43:                if (semaph[sem].sstate==SFREE) {
                     44:                        semaph[sem].sstate = SUSED;
                     45:                        return(sem);
                     46:                }
                     47:        }
                     48:        return(SYSERR);
                     49: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.