add necessary tasklist spinlocks
[AROS.git] / rom / exec / signal.c
blob10d8f242864490fd36751e157dcbb9e3128f0582
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 #include "exec_intern.h"
16 /*****************************************************************************
18 NAME */
20 AROS_LH2(void, Signal,
22 /* SYNOPSIS */
23 AROS_LHA(struct Task *, task, A1),
24 AROS_LHA(ULONG, signalSet, D0),
26 /* LOCATION */
27 struct ExecBase *, SysBase, 54, Exec)
29 /* FUNCTION
30 Send some signals to a given task. If the task is currently waiting
31 on these signals, has a higher priority as the current one and if
32 taskswitches are allowed the new task begins to run immediately.
34 INPUTS
35 task - Pointer to task structure.
36 signalSet - The set of signals to send to the task.
38 RESULT
40 NOTES
41 This function may be used from interrupts.
43 EXAMPLE
45 BUGS
47 SEE ALSO
48 AllocSignal(), FreeSignal(), Wait(), SetSignal(), SetExcept()
50 INTERNALS
52 HISTORY
54 ******************************************************************************/
56 AROS_LIBFUNC_INIT
58 /* Protect the task lists against other tasks that may use Signal(). */
59 Disable();
61 /* Set the signals in the task structure. */
62 task->tc_SigRecvd|=signalSet;
64 /* Do those bits raise exceptions? */
65 if(task->tc_SigExcept&task->tc_SigRecvd)
67 /* Yes. Set the exception flag. */
68 task->tc_Flags|=TF_EXCEPT;
70 /* task is running (Signal() called from within interrupt)? Raise the exception or defer it for later. */
71 if (task->tc_State==TS_RUN)
73 /* Order a reschedule */
74 Reschedule();
76 /* All done. */
77 Enable();
78 return;
83 Is the task receiving the signals waiting on them
84 (or on a exception) ?
86 if((task->tc_State==TS_WAIT)&&
87 (task->tc_SigRecvd&(task->tc_SigWait|task->tc_SigExcept)))
89 /* Yes. Move him to the ready list. */
90 task->tc_State=TS_READY;
91 Remove(&task->tc_Node);
92 Enqueue(&SysBase->TaskReady,&task->tc_Node);
94 /* Has it a higher priority as the current one? */
95 if (task->tc_Node.ln_Pri > GET_THIS_TASK->tc_Node.ln_Pri)
98 Yes. A taskswitch is necessary. Prepare one if possible.
99 (If the current task is not running it is already moved)
101 if (GET_THIS_TASK->tc_State == TS_RUN)
102 Reschedule();
106 Enable();
108 AROS_LIBFUNC_EXIT