00001 00007 /* Embedded XINU, Copyright (C) 2007. All rights reserved. */ 00008 00009 #include <kernel.h> 00010 #include <semaphore.h> 00011 #include <queue.h> 00012 00021 syscall freesem(semaphore sem) 00022 { 00023 irqmask ps; 00024 struct sentry *sptr; 00025 int pid; 00026 00027 ps = disable(); /* disable interrupts */ 00028 if ( isbadsem(sem) ) /* check sem validity */ 00029 { 00030 restore(ps); 00031 return SYSERR; 00032 } 00033 sptr = &semtab[sem]; 00034 while ( nonempty(sptr->queue) ) /* release processes in wait queue */ 00035 { 00036 pid = dequeue(sptr->queue); 00037 ready(pid, RESCHED_NO); 00038 } 00039 sptr->count = 0; /* reset the semaphore count */ 00040 sptr->state = SFREE; /* deallocate in semaphore table */ 00041 restore(ps); /* restore interrupts */ 00042 return OK; 00043 }