Rev 2 | Rev 14 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
2 | pj | 1 | /* |
2 | * Project: S.Ha.R.K. |
||
3 | * |
||
4 | * Coordinators: |
||
5 | * Giorgio Buttazzo <giorgio@sssup.it> |
||
6 | * Paolo Gai <pj@gandalf.sssup.it> |
||
7 | * |
||
8 | * Authors : |
||
9 | * Paolo Gai <pj@gandalf.sssup.it> |
||
10 | * (see the web pages for full authors list) |
||
11 | * |
||
12 | * ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy) |
||
13 | * |
||
14 | * http://www.sssup.it |
||
15 | * http://retis.sssup.it |
||
16 | * http://shark.sssup.it |
||
17 | */ |
||
18 | |||
19 | /** |
||
20 | ------------ |
||
21 | CVS : $Id: activate.c,v 1.1.1.1 2002-03-29 14:12:51 pj Exp $ |
||
22 | |||
23 | File: $File$ |
||
24 | Revision: $Revision: 1.1.1.1 $ |
||
25 | Last update: $Date: 2002-03-29 14:12:51 $ |
||
26 | ------------ |
||
27 | |||
28 | task_activate & group_activate |
||
29 | |||
30 | **/ |
||
31 | |||
32 | /* |
||
33 | * Copyright (C) 2000 Paolo Gai |
||
34 | * |
||
35 | * This program is free software; you can redistribute it and/or modify |
||
36 | * it under the terms of the GNU General Public License as published by |
||
37 | * the Free Software Foundation; either version 2 of the License, or |
||
38 | * (at your option) any later version. |
||
39 | * |
||
40 | * This program is distributed in the hope that it will be useful, |
||
41 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
42 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
43 | * GNU General Public License for more details. |
||
44 | * |
||
45 | * You should have received a copy of the GNU General Public License |
||
46 | * along with this program; if not, write to the Free Software |
||
47 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
||
48 | * |
||
49 | */ |
||
50 | |||
51 | #include <stdarg.h> |
||
52 | #include <ll/ll.h> |
||
53 | #include <ll/stdlib.h> |
||
54 | #include <ll/stdio.h> |
||
55 | #include <ll/string.h> |
||
56 | #include <kernel/config.h> |
||
57 | #include <kernel/model.h> |
||
58 | #include <kernel/const.h> |
||
59 | #include <sys/types.h> |
||
60 | #include <kernel/types.h> |
||
61 | #include <kernel/descr.h> |
||
62 | #include <errno.h> |
||
63 | #include <kernel/var.h> |
||
64 | #include <kernel/func.h> |
||
65 | #include <kernel/trace.h> |
||
66 | |||
67 | /*+ |
||
68 | Activates a single task |
||
69 | +*/ |
||
70 | int task_activate(PID p) |
||
71 | { |
||
72 | LEVEL l; /* the level of the task p */ |
||
73 | |||
74 | /* some controls on the task p */ |
||
75 | if (p<0 || p>=MAX_PROC) { |
||
76 | errno = EUNVALID_TASK_ID; |
||
77 | return -1; |
||
78 | } |
||
79 | if (proc_table[p].status == FREE) { |
||
80 | errno = EUNVALID_TASK_ID; |
||
81 | return -1; |
||
82 | } |
||
83 | |||
84 | /*+ if we are calling the runlevel functions the system is |
||
85 | into the global_context... we only have to call |
||
86 | the task_activate of the level +*/ |
||
87 | if (calling_runlevel_func) { |
||
88 | SYS_FLAGS f; |
||
89 | f=kern_fsave(); |
||
90 | if (proc_table[p].control & FREEZE_ACTIVATION) |
||
91 | proc_table[p].frozen_activations++; |
||
92 | else { |
||
93 | l = proc_table[p].task_level; |
||
94 | level_table[l]->task_activate(l,p); |
||
95 | } |
||
96 | kern_frestore(f); |
||
97 | return 0; |
||
98 | } |
||
99 | |||
100 | |||
101 | /* Begin activate */ |
||
102 | if (ll_ActiveInt()) { |
||
103 | SYS_FLAGS f; |
||
104 | f = kern_fsave(); |
||
105 | if (proc_table[p].control & FREEZE_ACTIVATION) |
||
106 | proc_table[p].frozen_activations++; |
||
107 | else { |
||
108 | l = proc_table[p].task_level; |
||
109 | level_table[l]->task_activate(l,p); |
||
110 | event_need_reschedule(); |
||
111 | } |
||
112 | kern_frestore(f); |
||
113 | } |
||
114 | else { |
||
115 | proc_table[exec_shadow].context = kern_context_save(); |
||
116 | |||
117 | if (proc_table[p].control & FREEZE_ACTIVATION) |
||
118 | proc_table[p].frozen_activations++; |
||
119 | else { |
||
120 | /* tracer stuff */ |
||
121 | trc_logevent(TRC_ACTIVATE,&p); |
||
122 | l = proc_table[p].task_level; |
||
123 | level_table[l]->task_activate(l,p); |
||
124 | |||
125 | /* Preempt if necessary */ |
||
126 | scheduler(); |
||
127 | } |
||
128 | kern_context_load(proc_table[exec_shadow].context); |
||
129 | } |
||
130 | |||
131 | return 0; |
||
132 | } |
||
133 | |||
134 | |||
135 | /*+ |
||
136 | Activate a group of tasks, identified by the group g |
||
137 | It returns -1 if the group is not valid |
||
138 | +*/ |
||
139 | int group_activate(WORD g) |
||
140 | { |
||
141 | PID i; /* a counter */ |
||
142 | register LEVEL l; /* a level value */ |
||
143 | |||
144 | if (g == 0) { |
||
145 | errno = EUNVALID_GROUP; |
||
146 | return -1; |
||
147 | } |
||
148 | |||
149 | /*+ if we are calling the runlevel functions the system is |
||
150 | into the global_context... we only have to call |
||
151 | the task_activate of the level +*/ |
||
152 | if (calling_runlevel_func) { |
||
153 | SYS_FLAGS f; |
||
154 | f=kern_fsave(); |
||
155 | |||
156 | for (i=0 ; i<MAX_PROC; i++) |
||
157 | if (proc_table[i].group == g) { |
||
158 | if (proc_table[i].control & FREEZE_ACTIVATION) { |
||
159 | proc_table[i].frozen_activations++; |
||
160 | continue; |
||
161 | } |
||
162 | /* tracer stuff */ |
||
163 | trc_logevent(TRC_ACTIVATE,&i); |
||
164 | l = proc_table[i].task_level; |
||
165 | level_table[l]->task_activate(l,i); |
||
166 | } |
||
167 | |||
168 | kern_frestore(f); |
||
169 | return 0; |
||
170 | } |
||
171 | |||
172 | if (ll_ActiveInt()) { |
||
173 | SYS_FLAGS f; |
||
174 | f=kern_fsave(); |
||
175 | for (i=0 ; i<MAX_PROC; i++) |
||
176 | if (proc_table[i].group == g) { |
||
177 | if (proc_table[i].control & FREEZE_ACTIVATION) { |
||
178 | proc_table[i].frozen_activations++; |
||
179 | continue; |
||
180 | } |
||
181 | /* tracer stuff */ |
||
182 | trc_logevent(TRC_ACTIVATE,&i); |
||
183 | l = proc_table[i].task_level; |
||
184 | level_table[l]->task_activate(l,i); |
||
185 | } |
||
186 | event_need_reschedule(); |
||
187 | kern_frestore(f); |
||
188 | } |
||
189 | else { |
||
190 | proc_table[exec_shadow].context = kern_context_save(); |
||
191 | |||
192 | for (i=0 ; i<MAX_PROC; i++) |
||
193 | if (proc_table[i].group == g) { |
||
194 | if (proc_table[i].control & FREEZE_ACTIVATION) { |
||
195 | proc_table[i].frozen_activations++; |
||
196 | continue; |
||
197 | } |
||
198 | l = proc_table[i].task_level; |
||
199 | level_table[l]->task_activate(l,i); |
||
200 | /* tracer stuff */ |
||
201 | trc_logevent(TRC_ACTIVATE,&i); |
||
202 | } |
||
203 | |||
204 | scheduler(); |
||
205 | kern_context_load(proc_table[exec_shadow].context); |
||
206 | } |
||
207 | return 0; |
||
208 | } |