Port the SB128 code to AROS.
[AROS.git] / rom / exec / signal.c
blob2a5094960ae3daba4b8454da6477919e94f08e74
1 /*
2 Copyright © 1995-2001, 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? Raise the exception or defer it for later. */
69 if(task->tc_State==TS_RUN)
71 /* Are taskswitches allowed? (Don't count own Disable() here) */
72 if(SysBase->TDNestCnt>=0||SysBase->IDNestCnt>0)
73 /* No. Store it for later. */
74 SysBase->AttnResched|=0x80;
75 else
77 /* Switches are allowed. Move the current task away. */
78 // SysBase->ThisTask->tc_State=TS_READY;
79 // Enqueue(&SysBase->TaskReady,&SysBase->ThisTask->tc_Node);
81 /* And force a rescedule. */
82 Reschedule(task);
85 /* All done. */
86 Enable();
87 return;
92 Is the task receiving the signals waiting on them
93 (or on a exception) ?
95 if((task->tc_State==TS_WAIT)&&
96 (task->tc_SigRecvd&(task->tc_SigWait|task->tc_SigExcept)))
98 /* Yes. Move him to the ready list. */
99 task->tc_State=TS_READY;
100 Remove(&task->tc_Node);
101 Enqueue(&SysBase->TaskReady,&task->tc_Node);
103 /* Has it a higher priority as the current one? */
104 if(task->tc_Node.ln_Pri>SysBase->ThisTask->tc_Node.ln_Pri)
107 Yes. A taskswitch is necessary. Prepare one if possible.
108 (If the current task is not running it is already moved)
110 if(SysBase->ThisTask->tc_State==TS_RUN)
112 /* Are taskswitches allowed? */
113 if(SysBase->TDNestCnt>=0||SysBase->IDNestCnt>0)
114 /* No. Store it for later. */
115 SysBase->AttnResched|=0x80;
116 else
117 /* Switches are allowed. Move the current task away.
118 And force a rescedule. */
119 Reschedule(task);
124 Enable();
125 AROS_LIBFUNC_EXIT