X-Git-Url: http://git.pond.sub.org/?p=empserver;a=blobdiff_plain;f=src%2Flib%2Flwp%2Fsem.c;h=58867cf26fb89d873b725de243c14eba78481f4c;hp=ee8199acf882f67f15da82bdea1e70086534479d;hb=9b7adfbe;hpb=5f263a7753dc728809ff85c993af975f6c76e61e diff --git a/src/lib/lwp/sem.c b/src/lib/lwp/sem.c index ee8199acf..58867cf26 100644 --- a/src/lib/lwp/sem.c +++ b/src/lib/lwp/sem.c @@ -37,54 +37,57 @@ extern char *strdup(); /* * create a lwpSemaphore. */ -struct lwpSem *lwpCreateSem(name, count) - char *name; - int count; +struct lwpSem * +lwpCreateSem(name, count) +char *name; +int count; { - struct lwpSem *new; + struct lwpSem *new; - if (!(new = (struct lwpSem *)malloc(sizeof(struct lwpSem)))) - return (0); - new->name = strdup(name); - new->count = count; - new->q.head = new->q.tail = 0; - return (new); + if (!(new = (struct lwpSem *)malloc(sizeof(struct lwpSem)))) + return (0); + new->name = strdup(name); + new->count = count; + new->q.head = new->q.tail = 0; + return (new); } /* * signal a lwpSemaphore. We only yield here if * the blocked process has a higher priority than ours'. */ -void lwpSignal(s) - struct lwpSem *s; +void +lwpSignal(s) +struct lwpSem *s; { - extern struct lwpProc *LwpCurrent; + extern struct lwpProc *LwpCurrent; - lwpStatus(LwpCurrent, "done with semaphore %s", s->name); - if (s->count++ < 0) { - struct lwpProc *p = lwpGetFirst(&s->q); - lwpStatus(LwpCurrent, "activating first waiter"); - lwpReady(p); - if (LwpCurrent->pri < p->pri) { - lwpStatus(p, "priority is higher"); - lwpYield(); - } + lwpStatus(LwpCurrent, "done with semaphore %s", s->name); + if (s->count++ < 0) { + struct lwpProc *p = lwpGetFirst(&s->q); + lwpStatus(LwpCurrent, "activating first waiter"); + lwpReady(p); + if (LwpCurrent->pri < p->pri) { + lwpStatus(p, "priority is higher"); + lwpYield(); } + } } /* * wait on a lwpSemaphore */ -void lwpWait(s) - struct lwpSem *s; +void +lwpWait(s) +struct lwpSem *s; { - extern struct lwpProc *LwpCurrent; + extern struct lwpProc *LwpCurrent; - lwpStatus(LwpCurrent, "checking semaphore %s", s->name); - if (--s->count < 0) { - lwpStatus(LwpCurrent, "blocking"); - lwpAddTail(&s->q, LwpCurrent); - lwpReschedule(); - } + lwpStatus(LwpCurrent, "checking semaphore %s", s->name); + if (--s->count < 0) { + lwpStatus(LwpCurrent, "blocking"); + lwpAddTail(&s->q, LwpCurrent); + lwpReschedule(); + } } #endif