simplerexx updated:
[AROS.git] / rom / exec / signal.c
blob9beeddd10e7bdbac5782070ccd10937d6080de88
1 /*
2 Copyright © 1995-2011, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Send some signal to a given task
6 Lang: english
7 */
9 #include <exec/execbase.h>
10 #include <aros/libcall.h>
11 #include <proto/exec.h>
12 #include <aros/debug.h>
14 /*****************************************************************************
16 NAME */
18 AROS_LH2(void, Signal,
20 /* SYNOPSIS */
21 AROS_LHA(struct Task *, task, A1),
22 AROS_LHA(ULONG, signalSet, D0),
24 /* LOCATION */
25 struct ExecBase *, SysBase, 54, Exec)
27 /* FUNCTION
28 Send some signals to a given task. If the task is currently waiting
29 on these signals, has a higher priority as the current one and if
30 taskswitches are allowed the new task begins to run immediately.
32 INPUTS
33 task - Pointer to task structure.
34 signalSet - The set of signals to send to the task.
36 RESULT
38 NOTES
39 This function may be used from interrupts.
41 EXAMPLE
43 BUGS
45 SEE ALSO
46 AllocSignal(), FreeSignal(), Wait(), SetSignal(), SetExcept()
48 INTERNALS
50 HISTORY
52 ******************************************************************************/
54 AROS_LIBFUNC_INIT
56 /* Protect the task lists against other tasks that may use Signal(). */
57 Disable();
59 /* Set the signals in the task structure. */
60 task->tc_SigRecvd|=signalSet;
62 /* Do those bits raise exceptions? */
63 if(task->tc_SigExcept&task->tc_SigRecvd)
65 /* Yes. Set the exception flag. */
66 task->tc_Flags|=TF_EXCEPT;
68 /* task is running (Signal() called from within interrupt)? Raise the exception or defer it for later. */
69 if (task->tc_State==TS_RUN)
71 /* Order a reschedule */
72 Reschedule();
74 /* All done. */
75 Enable();
76 return;
81 Is the task receiving the signals waiting on them
82 (or on a exception) ?
84 if((task->tc_State==TS_WAIT)&&
85 (task->tc_SigRecvd&(task->tc_SigWait|task->tc_SigExcept)))
87 /* Yes. Move him to the ready list. */
88 task->tc_State=TS_READY;
89 Remove(&task->tc_Node);
90 Enqueue(&SysBase->TaskReady,&task->tc_Node);
92 /* Has it a higher priority as the current one? */
93 if (task->tc_Node.ln_Pri > SysBase->ThisTask->tc_Node.ln_Pri)
96 Yes. A taskswitch is necessary. Prepare one if possible.
97 (If the current task is not running it is already moved)
99 if (SysBase->ThisTask->tc_State == TS_RUN)
100 Reschedule();
104 Enable();
106 AROS_LIBFUNC_EXIT