forked from xinu-os/xinu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
signal.c
43 lines (40 loc) · 967 Bytes
/
signal.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/**
* @file signal.c
*
*/
/* Embedded Xinu, Copyright (C) 2009. All rights reserved. */
#include <thread.h>
/**
* @ingroup semaphores
*
* Signal a semaphore, releasing up to one waiting thread.
*
* signal() may reschedule the currently running thread. As a result, signal()
* should not be called from non-reentrant interrupt handlers unless ::resdefer
* is set to a positive value at the start of the interrupt handler.
*
* @param sem
* Semaphore to signal.
*
* @return
* ::OK on success, ::SYSERR on failure. This function can only fail if @p
* sem did not specify a valid semaphore.
*/
syscall signal(semaphore sem)
{
register struct sement *semptr;
irqmask im;
im = disable();
if (isbadsem(sem))
{
restore(im);
return SYSERR;
}
semptr = &semtab[sem];
if ((semptr->count++) < 0)
{
ready(dequeue(semptr->queue), RESCHED_YES);
}
restore(im);
return OK;
}