author | Claus Gittinger <cg@exept.de> |
Sun, 07 Jun 1998 02:08:56 +0200 | |
changeset 3522 | 291ec553ac33 |
parent 3312 | 3c04e7517f17 |
child 3525 | 26fe903e0250 |
permissions | -rw-r--r-- |
1 | 1 |
" |
2 |
COPYRIGHT (c) 1993 by Claus Gittinger |
|
159 | 3 |
All Rights Reserved |
1 | 4 |
|
5 |
This software is furnished under a license and may be used |
|
6 |
only in accordance with the terms of that license and with the |
|
7 |
inclusion of the above copyright notice. This software may not |
|
8 |
be provided or otherwise made available to, or used by, any |
|
9 |
other person. No title to or ownership of the software is |
|
10 |
hereby transferred. |
|
11 |
" |
|
12 |
||
13 |
Object subclass:#ProcessorScheduler |
|
2280 | 14 |
instanceVariableNames:'quiescentProcessLists scheduler zombie activeProcess |
15 |
activeProcessId currentPriority readFdArray readSemaphoreArray |
|
16 |
readCheckArray writeFdArray writeSemaphoreArray timeoutArray |
|
17 |
timeoutActionArray timeoutProcessArray timeoutSemaphoreArray |
|
18 |
idleActions anyTimeouts dispatching interruptedProcess |
|
19 |
useIOInterrupts gotIOInterrupt osChildExitActions |
|
20 |
gotChildSignalInterrupt exitWhenNoMoreUserProcesses |
|
3522
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
21 |
suspendScheduler timeSliceProcess processesToRestart' |
768
20434b8239f3
stefans modalBox changes (no more polling)
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
22 |
classVariableNames:'KnownProcesses KnownProcessIds PureEventDriven |
752
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
750
diff
changeset
|
23 |
UserSchedulingPriority UserInterruptPriority TimingPriority |
1679
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
24 |
HighestPriority SchedulingPriority MaxNumberOfProcesses |
2626
4194d370d46f
made event polling interval a variable
Claus Gittinger <cg@exept.de>
parents:
2625
diff
changeset
|
25 |
InvalidProcessSignal TimeSlicingPriorityLimit TimeSliceInterval |
4194d370d46f
made event polling interval a variable
Claus Gittinger <cg@exept.de>
parents:
2625
diff
changeset
|
26 |
EventPollingInterval' |
768
20434b8239f3
stefans modalBox changes (no more polling)
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
27 |
poolDictionaries:'' |
20434b8239f3
stefans modalBox changes (no more polling)
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
28 |
category:'Kernel-Processes' |
1 | 29 |
! |
30 |
||
1783
be7402f74d94
hide timerInterrupt & ioInterrupt contexts when switching
Claus Gittinger <cg@exept.de>
parents:
1780
diff
changeset
|
31 |
!ProcessorScheduler class methodsFor:'documentation'! |
88 | 32 |
|
33 |
copyright |
|
34 |
" |
|
35 |
COPYRIGHT (c) 1993 by Claus Gittinger |
|
159 | 36 |
All Rights Reserved |
88 | 37 |
|
38 |
This software is furnished under a license and may be used |
|
39 |
only in accordance with the terms of that license and with the |
|
40 |
inclusion of the above copyright notice. This software may not |
|
41 |
be provided or otherwise made available to, or used by, any |
|
42 |
other person. No title to or ownership of the software is |
|
43 |
hereby transferred. |
|
44 |
" |
|
45 |
! |
|
46 |
||
47 |
documentation |
|
48 |
" |
|
49 |
This class has only one instance, which is bound to the global |
|
2193 | 50 |
'Processor' (well, on future multiprocessor systems, things may look |
51 |
different ... ;-). It is responsible for scheduling among the smalltalk |
|
88 | 52 |
processes (threads; not to confuse with heavy weight unix processes). |
93 | 53 |
|
54 |
Scheduling is fully done in smalltalk (the always runnable scheduler- |
|
55 |
process, running at highest priority does this). |
|
2193 | 56 |
See the 'scheduling' documentation. |
57 |
||
231 | 58 |
The main VM primitive to support this is found in threadSwitch, which passes |
93 | 59 |
control to another process (usually selected by the scheduler). |
159 | 60 |
Thus it is possible to modify the schedulers policy and implementation |
61 |
at the smalltalk level. |
|
93 | 62 |
|
63 |
Notice: Smalltalk/X can (still) be compiled & configured without |
|
64 |
process support. This non-process mode is called 'pureEventDriven' mode |
|
65 |
and is useful to quickly port ST/X to systems, where these facilities |
|
66 |
are either not needed (server applications), or are difficult to |
|
67 |
implement (threads require some assembler support functions). |
|
68 |
To allow pureEvent mode, kludges are built into some places in the |
|
69 |
system, where either a process is forked, or a timeout is used instead |
|
70 |
(for examples, see ProcessMonitor or MemoryMonitor). |
|
71 |
||
335 | 72 |
This pure-event mode may not be supported in the future |
2193 | 73 |
(actually, it is no longer maintained, so dont run the system without Processes). |
93 | 74 |
|
369 | 75 |
|
1273 | 76 |
[class variables:] |
93 | 77 |
|
1780
1b3a4ddc5b94
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1683
diff
changeset
|
78 |
KnownProcesses <WeakArray> all known processes |
1679
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
79 |
KnownProcessIds <Collection> and their IDs |
241 | 80 |
|
1679
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
81 |
PureEventDriven <Boolean> true, if no process support |
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
82 |
is available |
241 | 83 |
|
1679
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
84 |
UserSchedulingPriority <Integer> the priority at which normal |
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
85 |
user interfaces run |
241 | 86 |
|
1679
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
87 |
UserInterruptPriority the priority at which user- |
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
88 |
interrupts (Cntl-C) processing |
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
89 |
takes place. Processes with |
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
90 |
a greater or equal priority are |
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
91 |
not interruptable. |
241 | 92 |
|
1679
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
93 |
TimingPriority the priority used for timing. |
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
94 |
Processes with a greater or |
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
95 |
equal priority are not interrupted |
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
96 |
by timers. |
241 | 97 |
|
1679
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
98 |
HighestPriority The highest allowed prio for processes |
241 | 99 |
|
1679
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
100 |
SchedulingPriority The priority of the scheduler (must |
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
101 |
me higher than any other). |
93 | 102 |
|
1679
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
103 |
MaxNumberOfProcesses if non-nil, no more than this |
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
104 |
number of processes are allowed |
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
105 |
(for debugging) |
93 | 106 |
|
2534 | 107 |
TimeSliceInterval for preemptive priority scheduling only: |
2190 | 108 |
the time interval in millis, at which processes |
109 |
are timesliced |
|
2534 | 110 |
|
111 |
TimeSlicingPriorityLimit for preemptive priority scheduling only: |
|
2193 | 112 |
processes are only timesliced, if running |
113 |
at or below this priority. |
|
2190 | 114 |
|
2626
4194d370d46f
made event polling interval a variable
Claus Gittinger <cg@exept.de>
parents:
2625
diff
changeset
|
115 |
EventPollingInterval for systems which do not support select on |
4194d370d46f
made event polling interval a variable
Claus Gittinger <cg@exept.de>
parents:
2625
diff
changeset
|
116 |
a fileDescriptor: the polling interval in millis. |
4194d370d46f
made event polling interval a variable
Claus Gittinger <cg@exept.de>
parents:
2625
diff
changeset
|
117 |
|
759
908363ce8a32
interest is written with one 'r' (shame on me)
Claus Gittinger <cg@exept.de>
parents:
752
diff
changeset
|
118 |
most interesting methods: |
93 | 119 |
|
1679
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
120 |
Processor>>suspend: (see also Process>>suspend) |
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
121 |
Processor>>resume: (see also Process>>resume) |
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
122 |
Processor>>terminate: (see also Process>>terminate) |
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
123 |
Processor>>yield |
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
124 |
Processor>>changePriority:for: (see also Process>>priority: |
93 | 125 |
|
1679
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
126 |
Processor>>signal:afterSeconds: (see also Delay>>forSeconds:) |
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
127 |
Processor>>signal:afterMilliseconds: (see also Delay>>forMilliseconds:) |
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
128 |
Processor>>signal:onInput: (see also ExternalStream>>readWait) |
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
129 |
Processor>>signal:onOutput: (see also ExternalStream>>writeWait) |
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
130 |
Processor>>disableSemaphore: |
1273 | 131 |
|
132 |
||
133 |
[see also:] |
|
1679
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
134 |
Process |
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
135 |
Delay Semaphore SemaphoreSet SharedQueue |
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
136 |
WindowGroup |
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
137 |
(``Working with processes'': programming/processes.html) |
1294 | 138 |
|
139 |
[author:] |
|
1679
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
140 |
Claus Gittinger |
88 | 141 |
" |
2193 | 142 |
! |
143 |
||
144 |
scheduling |
|
145 |
" |
|
146 |
By default, the scheduler does 'non preemptive priority scheduling'; |
|
147 |
||
148 |
this means, that the highest priority runnable process |
|
149 |
is choosen and allowed to run, until it either gives back the CPU (via #yield), |
|
150 |
or suspends (i.e. waiting for I/O, the time or a semaphore), |
|
151 |
or a higher priority process becomes runnable.. |
|
152 |
||
153 |
If another process is runnable at the same priority, it will not |
|
154 |
be given CPU-time, unless one of the above happens. |
|
155 |
||
156 |
The consequence is, that a user process running at (say) priority 8, |
|
157 |
may block other user processes at the same priority, if it does heavy |
|
158 |
processing, or loops. |
|
159 |
(the event handling responsible to care for userInterrupts, is running at |
|
160 |
a much higher priority, so that interrupting the process should always be possible). |
|
161 |
||
162 |
||
163 |
The scheduler also supports 'timesliced priority scheduling', which is enabled |
|
164 |
via the #startTimeSlicing message (and disabled by #stopTimeSlicing). |
|
165 |
In this mode, the highest priority running process is suspended in regular intervals |
|
166 |
(the TimeSliceInterval) IFF there is another runnable process with the same priority. |
|
167 |
I.e. the top highest priority processes are timeshared. |
|
168 |
In this mode, the other processes will also get a chance to make some progress - however, |
|
169 |
lower priority process will only run, IFF all higher prio processes are waiting for an |
|
170 |
event. |
|
171 |
Timeslicing will not be done for processes running above TimeSlicingPriorityLimit, which |
|
172 |
allows for critical processes to run unaffected to completion. |
|
173 |
||
174 |
WARNING: |
|
175 |
timesliced priority scheduling is an experimental feature. There is no warranty, |
|
2534 | 176 |
(at the moment), that the system runs reliable in this mode. |
2193 | 177 |
The problem is, that shared collections may now be easily modified by other |
178 |
processes, running at the same time. |
|
179 |
The class library is currently being investigated for such possible trouble spots |
|
180 |
(we have already eliminated many weak spots, and added critical regions at many places, |
|
181 |
but cannot guarantee that all of them have been found so far ...) |
|
182 |
||
183 |
We think, that the timeSlicer is a useful add-on and that the system is fit enough |
|
184 |
for it to be evaluated, therefore, its included. |
|
185 |
However, use it at your own risk. |
|
186 |
" |
|
88 | 187 |
! ! |
188 |
||
1783
be7402f74d94
hide timerInterrupt & ioInterrupt contexts when switching
Claus Gittinger <cg@exept.de>
parents:
1780
diff
changeset
|
189 |
!ProcessorScheduler class methodsFor:'initialization'! |
1 | 190 |
|
191 |
initialize |
|
44 | 192 |
"class setup: create the one-and-only instance of myself and |
193 |
setup some priority values." |
|
194 |
||
2193 | 195 |
TimeSliceInterval := 50. |
2626
4194d370d46f
made event polling interval a variable
Claus Gittinger <cg@exept.de>
parents:
2625
diff
changeset
|
196 |
EventPollingInterval := 20. |
2193 | 197 |
|
93 | 198 |
UserSchedulingPriority := 8. |
199 |
UserInterruptPriority := 24. |
|
200 |
TimingPriority := 16. |
|
2190 | 201 |
TimeSlicingPriorityLimit := 26. |
202 |
HighestPriority := 30. |
|
93 | 203 |
SchedulingPriority := 31. |
204 |
||
1679
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
205 |
InvalidProcessSignal isNil ifTrue:[ |
2534 | 206 |
InvalidProcessSignal := ErrorSignal newSignalMayProceed:true. |
207 |
InvalidProcessSignal nameClass:self message:#invalidProcessSignal. |
|
208 |
InvalidProcessSignal notifierString:'invalid process'. |
|
1679
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
209 |
]. |
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
210 |
|
159 | 211 |
Processor isNil ifTrue:[ |
2534 | 212 |
"create the one and only processor" |
213 |
||
214 |
Processor := self basicNew initialize. |
|
10 | 215 |
]. |
77 | 216 |
|
217 |
" |
|
218 |
allow configurations without processes |
|
2129
e03cd7bc3475
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
2123
diff
changeset
|
219 |
(but such configurations are no longer distributed) |
77 | 220 |
" |
13 | 221 |
PureEventDriven := self threadsAvailable not. |
222 |
PureEventDriven ifTrue:[ |
|
2534 | 223 |
'Processor [error]: no process support - running event driven' errorPrintCR |
13 | 224 |
]. |
1086 | 225 |
|
1679
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
226 |
"Modified: 23.9.1996 / 14:24:50 / stefan" |
2129
e03cd7bc3475
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
2123
diff
changeset
|
227 |
"Modified: 10.1.1997 / 18:03:03 / cg" |
1 | 228 |
! ! |
229 |
||
1783
be7402f74d94
hide timerInterrupt & ioInterrupt contexts when switching
Claus Gittinger <cg@exept.de>
parents:
1780
diff
changeset
|
230 |
!ProcessorScheduler class methodsFor:'instance creation'! |
10 | 231 |
|
232 |
new |
|
233 |
"there is (currently) only one processor ..." |
|
234 |
||
159 | 235 |
self error:'only one processor is allowed in the system' |
10 | 236 |
! ! |
237 |
||
1783
be7402f74d94
hide timerInterrupt & ioInterrupt contexts when switching
Claus Gittinger <cg@exept.de>
parents:
1780
diff
changeset
|
238 |
!ProcessorScheduler class methodsFor:'Signal constants'! |
1679
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
239 |
|
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
240 |
invalidProcessSignal |
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
241 |
^ InvalidProcessSignal |
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
242 |
|
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
243 |
"Created: 23.9.1996 / 13:44:57 / stefan" |
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
244 |
! ! |
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
245 |
|
1783
be7402f74d94
hide timerInterrupt & ioInterrupt contexts when switching
Claus Gittinger <cg@exept.de>
parents:
1780
diff
changeset
|
246 |
!ProcessorScheduler class methodsFor:'instance release'! |
10 | 247 |
|
2091
c11bb3e29a1b
Use dependent mechamism of WeakArray instead of #watcher.
Stefan Vogel <sv@exept.de>
parents:
1981
diff
changeset
|
248 |
update:something with:aParameter from:changedObject |
159 | 249 |
"some Process has been garbage collected |
335 | 250 |
- terminate the underlying thread. |
251 |
Usually this does not happen; instead, the process terminates itself |
|
252 |
by sending #terminate." |
|
10 | 253 |
|
254 |
|id sz "{ Class: SmallInteger }"| |
|
1 | 255 |
|
2091
c11bb3e29a1b
Use dependent mechamism of WeakArray instead of #watcher.
Stefan Vogel <sv@exept.de>
parents:
1981
diff
changeset
|
256 |
something == #ElementExpired ifTrue:[ |
2534 | 257 |
sz := KnownProcessIds size. |
258 |
1 to:sz do:[:index | |
|
259 |
"/ (KnownProcesses at:index) isNil ifTrue:[ |
|
260 |
(KnownProcesses at:index) == 0 ifTrue:[ |
|
261 |
id := KnownProcessIds at:index. |
|
262 |
id notNil ifTrue:[ |
|
263 |
'Processor [warning]: terminating thread ' errorPrint. |
|
264 |
id errorPrint. |
|
265 |
' (no longer refd)' errorPrintCR. |
|
266 |
||
267 |
self threadDestroy:id. |
|
268 |
KnownProcessIds at:index put:nil. |
|
269 |
]. |
|
270 |
KnownProcesses at:index put:nil. |
|
271 |
] |
|
272 |
] |
|
10 | 273 |
] |
2091
c11bb3e29a1b
Use dependent mechamism of WeakArray instead of #watcher.
Stefan Vogel <sv@exept.de>
parents:
1981
diff
changeset
|
274 |
|
c11bb3e29a1b
Use dependent mechamism of WeakArray instead of #watcher.
Stefan Vogel <sv@exept.de>
parents:
1981
diff
changeset
|
275 |
"Created: 7.1.1997 / 16:45:42 / stefan" |
2137 | 276 |
"Modified: 10.1.1997 / 19:10:48 / cg" |
10 | 277 |
! ! |
278 |
||
1783
be7402f74d94
hide timerInterrupt & ioInterrupt contexts when switching
Claus Gittinger <cg@exept.de>
parents:
1780
diff
changeset
|
279 |
!ProcessorScheduler class methodsFor:'primitive process primitives'! |
10 | 280 |
|
339 | 281 |
threadCreate:aProcess withId:id |
159 | 282 |
"physical creation of a process. |
10 | 283 |
(warning: low level entry, no administration done). |
339 | 284 |
This may raise an exception, if a VM process could not be created." |
13 | 285 |
|
369 | 286 |
MaxNumberOfProcesses notNil ifTrue:[ |
287 |
KnownProcessIds size >= MaxNumberOfProcesses ifTrue:[ |
|
288 |
(KnownProcessIds count:[:el | el notNil]) >= MaxNumberOfProcesses ifTrue:[ |
|
289 |
" |
|
290 |
the number of processes has reached the (soft) limit. |
|
291 |
This limit prevents runaway programs from creating too many |
|
292 |
processes. If you continue in the debugger, the process will be |
|
293 |
created as usual. If you dont want this, abort or terminate. |
|
294 |
" |
|
295 |
self error:'too many processes'. |
|
296 |
] |
|
297 |
] |
|
298 |
]. |
|
299 |
||
300 |
%{ |
|
1 | 301 |
int tid; |
302 |
extern int __threadCreate(); |
|
303 |
||
339 | 304 |
tid = __threadCreate(aProcess, |
305 |
0 /* stackSize: no longer needed */, |
|
1133 | 306 |
__isSmallInteger(id) ? __intVal(id) /* assign id */ |
339 | 307 |
: -1 /* let VM assign one */ ); |
308 |
if (tid) { |
|
1133 | 309 |
RETURN ( __MKSMALLINT(tid)); |
1 | 310 |
} |
311 |
%} |
|
13 | 312 |
. |
69 | 313 |
" |
314 |
arrive here, if creation of process in VM failed. |
|
159 | 315 |
This may happen, if the VM does not support more processes, |
316 |
or if it ran out of memory, when allocating internal data |
|
317 |
structures. |
|
69 | 318 |
" |
115 | 319 |
^ ObjectMemory allocationFailureSignal raise. |
1 | 320 |
! |
321 |
||
322 |
threadDestroy:id |
|
323 |
"physical destroy other process ... |
|
324 |
(warning: low level entry, no administration done)" |
|
325 |
||
13 | 326 |
%{ /* NOCONTEXT */ |
327 |
||
253 | 328 |
if (__isSmallInteger(id)) { |
1133 | 329 |
__threadDestroy(__intVal(id)); |
1 | 330 |
} |
331 |
%} |
|
699 | 332 |
! |
333 |
||
334 |
threadInterrupt:id |
|
335 |
"make the process evaluate an interrupt. This sets a flag in the VMs |
|
336 |
threadSwitcher, to let the process perform a #interrupt when its set to |
|
337 |
run the next time. The process itself can decide how to react on this |
|
338 |
interrupt (currently, it looks for interruptBlocks to evaluate)." |
|
339 |
||
340 |
%{ /* NOCONTEXT */ |
|
341 |
||
342 |
if (__isSmallInteger(id)) { |
|
1133 | 343 |
__threadInterrupt(__intVal(id)); |
699 | 344 |
} |
345 |
%} |
|
346 |
! |
|
347 |
||
348 |
threadsAvailable |
|
349 |
"return true, if the runtime system supports threads (i.e. processes); |
|
350 |
false otherwise." |
|
351 |
||
352 |
%{ /* NOCONTEXT */ |
|
353 |
RETURN (__threadsAvailable()); |
|
354 |
%} |
|
1 | 355 |
! ! |
356 |
||
1783
be7402f74d94
hide timerInterrupt & ioInterrupt contexts when switching
Claus Gittinger <cg@exept.de>
parents:
1780
diff
changeset
|
357 |
!ProcessorScheduler class methodsFor:'queries'! |
699 | 358 |
|
359 |
isPureEventDriven |
|
360 |
"this is temporary - (maybe not :-). |
|
361 |
you can run ST/X either with or without processes. |
|
362 |
Without, there is conceptionally a single process handling all |
|
363 |
outside events and timeouts. This has some negative implications |
|
364 |
(Debugger is ugly), but allows a fully portable ST/X without any |
|
365 |
assembler support - i.e. quick portability. |
|
366 |
The PureEvent flag will automatically be set if the runtime system |
|
367 |
does not support threads - otherwise, it can be set manually |
|
368 |
(from rc-file). |
|
369 |
" |
|
370 |
||
371 |
^ PureEventDriven |
|
372 |
! |
|
373 |
||
374 |
knownProcesses |
|
375 |
"return a collection of all (living) processes in the system" |
|
376 |
||
1780
1b3a4ddc5b94
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1683
diff
changeset
|
377 |
^ KnownProcesses select:[:p | p notNil and:[p ~~ 0]] |
699 | 378 |
! |
379 |
||
380 |
maxNumberOfProcesses |
|
381 |
"return the limit on the number of processes; |
|
382 |
the default is nil (i.e. unlimited)." |
|
383 |
||
384 |
^ MaxNumberOfProcesses |
|
385 |
! |
|
10 | 386 |
|
699 | 387 |
maxNumberOfProcesses:aNumber |
388 |
"set the limit on the number of processes. |
|
389 |
This helps if you have a program which (by error) creates countless |
|
390 |
subprocesses. Without this limit, you may have a hard time to find |
|
391 |
this error (and repairing it). If nil (the default), the number of |
|
392 |
processes is unlimited." |
|
393 |
||
394 |
MaxNumberOfProcesses := aNumber |
|
395 |
! |
|
396 |
||
397 |
processDriven |
|
398 |
"turn on process driven mode" |
|
10 | 399 |
|
699 | 400 |
PureEventDriven := false |
401 |
! |
|
402 |
||
403 |
pureEventDriven |
|
404 |
"turn on pure-event driven mode - no processes, single dispatch loop" |
|
405 |
||
406 |
PureEventDriven := true |
|
407 |
! ! |
|
1 | 408 |
|
699 | 409 |
!ProcessorScheduler methodsFor:'I/O event actions'! |
410 |
||
411 |
disableFd:aFileDescriptor |
|
412 |
"disable block events on aFileDescriptor. |
|
413 |
This is a leftover support for pure-event systems and may vanish." |
|
414 |
||
415 |
|idx "{Class: SmallInteger }" |
|
416 |
wasBlocked| |
|
1 | 417 |
|
93 | 418 |
wasBlocked := OperatingSystem blockInterrupts. |
699 | 419 |
idx := readFdArray identityIndexOf:aFileDescriptor startingAt:1. |
420 |
idx ~~ 0 ifTrue:[ |
|
2831
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
421 |
useIOInterrupts ifTrue:[ |
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
422 |
OperatingSystem disableIOInterruptsOn:aFileDescriptor |
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
423 |
]. |
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
424 |
readFdArray at:idx put:nil. |
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
425 |
readCheckArray at:idx put:nil. |
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
426 |
readSemaphoreArray at:idx put:nil |
93 | 427 |
]. |
428 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
2831
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
429 |
|
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
430 |
"Modified: 4.8.1997 / 15:16:00 / cg" |
24 | 431 |
! |
432 |
||
699 | 433 |
enableIOAction:aBlock onInput:aFileDescriptor |
434 |
"half-obsolete event support: arrange for aBlock to be |
|
435 |
evaluated when input on aFileDescriptor arrives. |
|
436 |
This is a leftover support for pure-event systems and may vanish." |
|
1 | 437 |
|
699 | 438 |
|idx "{Class: SmallInteger }" |
439 |
wasBlocked| |
|
10 | 440 |
|
3116 | 441 |
aFileDescriptor < 0 ifTrue:[ |
442 |
'Processor [warning]: ignored invalid fd for IO action.' errorPrintCR. |
|
443 |
thisContext fullPrintAll. |
|
444 |
^ self |
|
445 |
]. |
|
446 |
||
93 | 447 |
wasBlocked := OperatingSystem blockInterrupts. |
699 | 448 |
(readFdArray identityIndexOf:aFileDescriptor startingAt:1) == 0 ifTrue:[ |
2831
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
449 |
idx := readFdArray identityIndexOf:nil startingAt:1. |
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
450 |
idx ~~ 0 ifTrue:[ |
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
451 |
readFdArray at:idx put:aFileDescriptor. |
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
452 |
readCheckArray at:idx put:aBlock. |
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
453 |
readSemaphoreArray at:idx put:nil |
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
454 |
] ifFalse:[ |
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
455 |
readFdArray := readFdArray copyWith:aFileDescriptor. |
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
456 |
readCheckArray := readCheckArray copyWith:aBlock. |
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
457 |
readSemaphoreArray := readSemaphoreArray copyWith:nil. |
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
458 |
]. |
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
459 |
useIOInterrupts ifTrue:[ |
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
460 |
OperatingSystem enableIOInterruptsOn:aFileDescriptor |
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
461 |
]. |
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
462 |
|
93 | 463 |
]. |
464 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
2831
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
465 |
|
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
466 |
"Modified: 4.8.1997 / 15:17:28 / cg" |
1 | 467 |
! ! |
468 |
||
469 |
!ProcessorScheduler methodsFor:'accessing'! |
|
470 |
||
69 | 471 |
activePriority |
472 |
"return the priority of the currently running process. |
|
159 | 473 |
GNU-ST & ST-80 compatibility; this is the same as currentPriority" |
69 | 474 |
|
475 |
^ currentPriority |
|
476 |
! |
|
477 |
||
25 | 478 |
activeProcess |
10 | 479 |
"return the currently running process" |
480 |
||
25 | 481 |
^ activeProcess |
1 | 482 |
|
25 | 483 |
"Processor activeProcess" |
181 | 484 |
! |
485 |
||
2262 | 486 |
activeProcessId |
487 |
"return the currently running process's ID. |
|
488 |
The same as returned by 'Processor activeProcess id'; |
|
489 |
added for to avoid another send in semaphores debugging support." |
|
490 |
||
491 |
^ activeProcessId |
|
492 |
! |
|
493 |
||
699 | 494 |
currentPriority |
495 |
"return the priority of the currently running process" |
|
496 |
||
497 |
^ currentPriority |
|
498 |
||
499 |
"Processor currentPriority" |
|
500 |
! |
|
501 |
||
181 | 502 |
interruptedProcess |
503 |
"returns the process which was interrupted by the active one" |
|
504 |
||
505 |
^ interruptedProcess |
|
10 | 506 |
! ! |
507 |
||
699 | 508 |
!ProcessorScheduler methodsFor:'background processing'! |
1 | 509 |
|
699 | 510 |
addIdleBlock:aBlock |
511 |
"add the argument, aBlock to the list of idle-actions. |
|
512 |
Idle blocks are evaluated whenever no other process is runnable, |
|
513 |
and no events are pending. |
|
514 |
Use of idle blocks is not recommended, use a low priority processes |
|
515 |
instead, which has the same effect. Idle blcoks are still included |
|
516 |
to support background actions in pure-event systems, where no processes |
|
517 |
are available. |
|
518 |
Support for idle-blocks may vanish." |
|
10 | 519 |
|
699 | 520 |
|wasBlocked| |
521 |
||
522 |
wasBlocked := OperatingSystem blockInterrupts. |
|
523 |
idleActions isNil ifTrue:[ |
|
524 |
idleActions := OrderedCollection new |
|
525 |
]. |
|
526 |
idleActions add:aBlock. |
|
527 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
528 |
! |
|
1 | 529 |
|
699 | 530 |
removeIdleBlock:aBlock |
531 |
"remove the argument, aBlock from the list of idle-blocks. |
|
532 |
Support for idle-blocks may vanish - use low prio processes instead." |
|
533 |
||
534 |
|wasBlocked| |
|
535 |
||
536 |
wasBlocked := OperatingSystem blockInterrupts. |
|
537 |
idleActions notNil ifTrue:[ |
|
2353 | 538 |
idleActions removeIdentical:aBlock ifAbsent:[] |
10 | 539 |
]. |
699 | 540 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
2353 | 541 |
|
542 |
"Modified: 1.2.1997 / 12:09:46 / cg" |
|
699 | 543 |
! ! |
544 |
||
10 | 545 |
!ProcessorScheduler methodsFor:'dispatching'! |
546 |
||
547 |
dispatch |
|
93 | 548 |
"It handles timeouts and switches to the highest prio runnable process" |
44 | 549 |
|
829
fc386319f41c
removed external function defs (soon no longer allowed)
Claus Gittinger <cg@exept.de>
parents:
827
diff
changeset
|
550 |
|any millis pri p nActions "{ Class: SmallInteger }" |
fc386319f41c
removed external function defs (soon no longer allowed)
Claus Gittinger <cg@exept.de>
parents:
827
diff
changeset
|
551 |
checkBlock sema| |
10 | 552 |
|
93 | 553 |
" |
554 |
handle all timeout actions |
|
555 |
" |
|
27 | 556 |
anyTimeouts ifTrue:[ |
2831
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
557 |
self evaluateTimeouts |
10 | 558 |
]. |
559 |
||
231 | 560 |
"first do a quick check for semaphores using checkActions - this is needed for |
302 | 561 |
devices like the X-connection, where some events might be in the event |
2618 | 562 |
queue but the sockets input queue is empty. |
563 |
Without these checks, a select might block even though there is work to do |
|
93 | 564 |
" |
10 | 565 |
any := false. |
231 | 566 |
nActions := readCheckArray size. |
10 | 567 |
1 to:nActions do:[:index | |
2831
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
568 |
checkBlock := readCheckArray at:index. |
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
569 |
(checkBlock notNil and:[checkBlock value]) ifTrue:[ |
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
570 |
sema := readSemaphoreArray at:index. |
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
571 |
sema notNil ifTrue:[ |
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
572 |
sema signalOnce. |
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
573 |
]. |
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
574 |
any := true. |
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
575 |
] |
10 | 576 |
]. |
577 |
||
231 | 578 |
"now, someone might be runnable ..." |
10 | 579 |
|
13 | 580 |
p := self highestPriorityRunnableProcess. |
10 | 581 |
p isNil ifTrue:[ |
2831
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
582 |
"/ no one runnable, hard wait for event or timeout |
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
583 |
|
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
584 |
self waitForEventOrTimeout. |
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
585 |
|
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
586 |
"/ check for OS process termination |
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
587 |
gotChildSignalInterrupt ifTrue:[ |
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
588 |
gotChildSignalInterrupt := false. |
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
589 |
self handleChildSignalInterrupt |
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
590 |
]. |
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
591 |
^ self |
10 | 592 |
]. |
593 |
||
13 | 594 |
pri := p priority. |
595 |
||
302 | 596 |
" |
597 |
want to give control to the process p. |
|
10 | 598 |
If the switched-to processes priority is lower than the |
599 |
userSchedulingPriority, we have to make certain, that the |
|
600 |
next input or timer will bring us back for a reschedule. |
|
601 |
This is done by enabling ioInterrupts for all file descriptors. |
|
302 | 602 |
If ioInterrupts are not available (OS does not support them), |
603 |
we schedule a timer interrupt to interrupt us after 1/20s of a second |
|
604 |
- effectively polling the filedescriptors 20 times a second. |
|
605 |
(which is bad, since low prio processes will be hurt in performance) |
|
606 |
Therefore, dont let benchmarks run with low prio ... |
|
607 |
||
231 | 608 |
Higher prio processes must be suspended, |
302 | 609 |
same prio ones must yield or suspend to get back control |
610 |
" |
|
10 | 611 |
|
93 | 612 |
" |
613 |
uncommenting this will make timeouts interrupt the current process |
|
614 |
(i.e. as if the interrupt runs at TimingPrio); |
|
615 |
if left commented, they are handled at UserSchedulingPrio. |
|
13 | 616 |
this will all change, when timeouts are removed and all is process driven |
231 | 617 |
(a future version will have a process running to handle a timeout queue) |
13 | 618 |
" |
619 |
||
620 |
" |
|
621 |
pri < TimingPriority ifTrue:[ |
|
2831
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
622 |
anyTimeouts ifTrue:[ |
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
623 |
millis := self timeToNextTimeout. |
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
624 |
millis == 0 ifTrue:[^ self]. |
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
625 |
] |
13 | 626 |
]. |
627 |
" |
|
628 |
||
93 | 629 |
" |
630 |
if the process to run has a lower than UserInterruptPriority, |
|
302 | 631 |
arrange for an interrupt to occur on I/O. |
231 | 632 |
This is done by enabling IO-signals (if the OS supports them) |
93 | 633 |
or by installing a poll-interrupt after 50ms (if the OS does not). |
634 |
" |
|
635 |
pri < UserInterruptPriority ifTrue:[ |
|
636 |
||
637 |
"comment out this if above is uncommented" |
|
2831
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
638 |
anyTimeouts ifTrue:[ |
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
639 |
millis := self timeToNextTimeout. |
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
640 |
millis == 0 ifTrue:[^ self]. |
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
641 |
]. |
93 | 642 |
"---" |
10 | 643 |
|
2831
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
644 |
useIOInterrupts ifTrue:[ |
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
645 |
"/ readFdArray do:[:fd | |
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
646 |
"/ (fd notNil and:[fd >= 0]) ifTrue:[ |
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
647 |
"/ OperatingSystem enableIOInterruptsOn:fd |
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
648 |
"/ ]. |
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
649 |
"/ ]. |
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
650 |
] ifFalse:[ |
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
651 |
millis notNil ifTrue:[ |
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
652 |
millis := millis min:EventPollingInterval |
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
653 |
] ifFalse:[ |
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
654 |
millis := EventPollingInterval |
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
655 |
] |
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
656 |
] |
13 | 657 |
]. |
10 | 658 |
|
13 | 659 |
millis notNil ifTrue:[ |
2831
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
660 |
"schedule a clock interrupt after millis milliseconds" |
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
661 |
OperatingSystem enableTimer:millis rounded. |
10 | 662 |
]. |
663 |
||
231 | 664 |
" |
665 |
now let the process run - will come back here by reschedule |
|
666 |
from ioInterrupt or timerInterrupt ... (running at max+1) |
|
667 |
" |
|
10 | 668 |
self threadSwitch:p. |
669 |
||
804
264d440a67a0
Fixes when useIOInterrupts == true.
Stefan Vogel <sv@exept.de>
parents:
786
diff
changeset
|
670 |
"... when we arrive here, we are back on stage. |
2831
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
671 |
Either by an ALARM or IO signal, or by a suspend of another process |
804
264d440a67a0
Fixes when useIOInterrupts == true.
Stefan Vogel <sv@exept.de>
parents:
786
diff
changeset
|
672 |
" |
10 | 673 |
|
674 |
millis notNil ifTrue:[ |
|
2831
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
675 |
OperatingSystem disableTimer. |
1154
96bb8fce61cf
Fix removeCorruptedFds to clear LastErrorNumber. Handle ChildSignalInterrupts in Scheduler's context, to avoid errno corruption.
Stefan Vogel <sv@exept.de>
parents:
1133
diff
changeset
|
676 |
]. |
96bb8fce61cf
Fix removeCorruptedFds to clear LastErrorNumber. Handle ChildSignalInterrupts in Scheduler's context, to avoid errno corruption.
Stefan Vogel <sv@exept.de>
parents:
1133
diff
changeset
|
677 |
|
96bb8fce61cf
Fix removeCorruptedFds to clear LastErrorNumber. Handle ChildSignalInterrupts in Scheduler's context, to avoid errno corruption.
Stefan Vogel <sv@exept.de>
parents:
1133
diff
changeset
|
678 |
"/ check for OS process termination |
96bb8fce61cf
Fix removeCorruptedFds to clear LastErrorNumber. Handle ChildSignalInterrupts in Scheduler's context, to avoid errno corruption.
Stefan Vogel <sv@exept.de>
parents:
1133
diff
changeset
|
679 |
gotChildSignalInterrupt ifTrue:[ |
2831
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
680 |
gotChildSignalInterrupt := false. |
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
681 |
self handleChildSignalInterrupt |
804
264d440a67a0
Fixes when useIOInterrupts == true.
Stefan Vogel <sv@exept.de>
parents:
786
diff
changeset
|
682 |
]. |
264d440a67a0
Fixes when useIOInterrupts == true.
Stefan Vogel <sv@exept.de>
parents:
786
diff
changeset
|
683 |
|
264d440a67a0
Fixes when useIOInterrupts == true.
Stefan Vogel <sv@exept.de>
parents:
786
diff
changeset
|
684 |
"/ check for new input |
264d440a67a0
Fixes when useIOInterrupts == true.
Stefan Vogel <sv@exept.de>
parents:
786
diff
changeset
|
685 |
|
264d440a67a0
Fixes when useIOInterrupts == true.
Stefan Vogel <sv@exept.de>
parents:
786
diff
changeset
|
686 |
(gotIOInterrupt or:[useIOInterrupts not]) ifTrue:[ |
2831
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
687 |
gotIOInterrupt := false. |
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
688 |
self checkForInputWithTimeout:0. |
10 | 689 |
] |
768
20434b8239f3
stefans modalBox changes (no more polling)
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
690 |
|
1154
96bb8fce61cf
Fix removeCorruptedFds to clear LastErrorNumber. Handle ChildSignalInterrupts in Scheduler's context, to avoid errno corruption.
Stefan Vogel <sv@exept.de>
parents:
1133
diff
changeset
|
691 |
"Modified: 12.4.1996 / 10:14:18 / stefan" |
2831
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
692 |
"Modified: 4.8.1997 / 15:34:09 / cg" |
699 | 693 |
! |
694 |
||
695 |
dispatchLoop |
|
696 |
"central dispatch loop; the scheduler process is always staying in |
|
697 |
this method, looping forever." |
|
698 |
||
806
409a8c189e01
also handle termination of the scheduler process
Claus Gittinger <cg@exept.de>
parents:
804
diff
changeset
|
699 |
|dispatchAction handlerAction ignoredSignals| |
786 | 700 |
|
699 | 701 |
"avoid confusion if entered twice" |
702 |
||
703 |
dispatching == true ifTrue:[^ self]. |
|
704 |
dispatching := true. |
|
705 |
||
964
6d87e84d86ac
in standAloneMode: exit dispatch if last process dies and no more sema/timer waits are pending
Claus Gittinger <cg@exept.de>
parents:
840
diff
changeset
|
706 |
"/ create the relevant blocks & signalSet outside of the |
6d87e84d86ac
in standAloneMode: exit dispatch if last process dies and no more sema/timer waits are pending
Claus Gittinger <cg@exept.de>
parents:
840
diff
changeset
|
707 |
"/ while-loop |
6d87e84d86ac
in standAloneMode: exit dispatch if last process dies and no more sema/timer waits are pending
Claus Gittinger <cg@exept.de>
parents:
840
diff
changeset
|
708 |
"/ (thanks to stefans objectAllocation monitor, |
6d87e84d86ac
in standAloneMode: exit dispatch if last process dies and no more sema/timer waits are pending
Claus Gittinger <cg@exept.de>
parents:
840
diff
changeset
|
709 |
"/ this safes a bit of memory allocation in the scheduler) |
6d87e84d86ac
in standAloneMode: exit dispatch if last process dies and no more sema/timer waits are pending
Claus Gittinger <cg@exept.de>
parents:
840
diff
changeset
|
710 |
|
786 | 711 |
dispatchAction := [self dispatch]. |
964
6d87e84d86ac
in standAloneMode: exit dispatch if last process dies and no more sema/timer waits are pending
Claus Gittinger <cg@exept.de>
parents:
840
diff
changeset
|
712 |
|
806
409a8c189e01
also handle termination of the scheduler process
Claus Gittinger <cg@exept.de>
parents:
804
diff
changeset
|
713 |
handlerAction := [:ex | |
2534 | 714 |
('Processor [info]: ignored signal (', ex signal printString, ')') infoPrintCR. |
715 |
ex return |
|
716 |
]. |
|
806
409a8c189e01
also handle termination of the scheduler process
Claus Gittinger <cg@exept.de>
parents:
804
diff
changeset
|
717 |
|
409a8c189e01
also handle termination of the scheduler process
Claus Gittinger <cg@exept.de>
parents:
804
diff
changeset
|
718 |
ignoredSignals := SignalSet |
2534 | 719 |
with:(Process terminateSignal) |
720 |
with:AbortSignal. |
|
786 | 721 |
|
722 |
"/ |
|
723 |
"/ I made this an extra call to dispatch; this allows recompilation |
|
724 |
"/ of the dispatch-handling code in the running system. |
|
725 |
"/ |
|
964
6d87e84d86ac
in standAloneMode: exit dispatch if last process dies and no more sema/timer waits are pending
Claus Gittinger <cg@exept.de>
parents:
840
diff
changeset
|
726 |
[dispatching] whileTrue:[ |
2534 | 727 |
ignoredSignals handle:handlerAction do:dispatchAction |
964
6d87e84d86ac
in standAloneMode: exit dispatch if last process dies and no more sema/timer waits are pending
Claus Gittinger <cg@exept.de>
parents:
840
diff
changeset
|
728 |
]. |
6d87e84d86ac
in standAloneMode: exit dispatch if last process dies and no more sema/timer waits are pending
Claus Gittinger <cg@exept.de>
parents:
840
diff
changeset
|
729 |
|
6d87e84d86ac
in standAloneMode: exit dispatch if last process dies and no more sema/timer waits are pending
Claus Gittinger <cg@exept.de>
parents:
840
diff
changeset
|
730 |
"/ we arrive here in standalone Apps, |
6d87e84d86ac
in standAloneMode: exit dispatch if last process dies and no more sema/timer waits are pending
Claus Gittinger <cg@exept.de>
parents:
840
diff
changeset
|
731 |
"/ when the last process at or above UserSchedulingPriority process died. |
6d87e84d86ac
in standAloneMode: exit dispatch if last process dies and no more sema/timer waits are pending
Claus Gittinger <cg@exept.de>
parents:
840
diff
changeset
|
732 |
"/ regular ST/X stays in above loop forever |
6d87e84d86ac
in standAloneMode: exit dispatch if last process dies and no more sema/timer waits are pending
Claus Gittinger <cg@exept.de>
parents:
840
diff
changeset
|
733 |
|
2137 | 734 |
'Processor [info]: finish dispatch (no more processes)' infoPrintCR. |
964
6d87e84d86ac
in standAloneMode: exit dispatch if last process dies and no more sema/timer waits are pending
Claus Gittinger <cg@exept.de>
parents:
840
diff
changeset
|
735 |
|
1679
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
736 |
"Modified: 23.9.1996 / 14:19:56 / stefan" |
2137 | 737 |
"Modified: 10.1.1997 / 19:10:53 / cg" |
964
6d87e84d86ac
in standAloneMode: exit dispatch if last process dies and no more sema/timer waits are pending
Claus Gittinger <cg@exept.de>
parents:
840
diff
changeset
|
738 |
! |
6d87e84d86ac
in standAloneMode: exit dispatch if last process dies and no more sema/timer waits are pending
Claus Gittinger <cg@exept.de>
parents:
840
diff
changeset
|
739 |
|
6d87e84d86ac
in standAloneMode: exit dispatch if last process dies and no more sema/timer waits are pending
Claus Gittinger <cg@exept.de>
parents:
840
diff
changeset
|
740 |
exitWhenNoMoreUserProcesses:aBoolean |
2193 | 741 |
"set/clear the flag, which controls if the scheduler should exit and return |
742 |
when the last user process finishes (and therefore exit the smalltalk system). |
|
743 |
A userProcess is defined as a process with a non-zero processGroup. |
|
744 |
This flag is typically set for standAlone operation, to terminate the (Unix-) |
|
745 |
process, when the last thread terminates." |
|
746 |
||
964
6d87e84d86ac
in standAloneMode: exit dispatch if last process dies and no more sema/timer waits are pending
Claus Gittinger <cg@exept.de>
parents:
840
diff
changeset
|
747 |
exitWhenNoMoreUserProcesses := aBoolean |
827
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
807
diff
changeset
|
748 |
! ! |
806
409a8c189e01
also handle termination of the scheduler process
Claus Gittinger <cg@exept.de>
parents:
804
diff
changeset
|
749 |
|
3522
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
750 |
!ProcessorScheduler methodsFor:'initializing'! |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
751 |
|
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
752 |
initialize |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
753 |
"initialize the one-and-only ProcessorScheduler" |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
754 |
|
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
755 |
|nPrios "{ Class: SmallInteger }" |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
756 |
p l| |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
757 |
|
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
758 |
KnownProcesses isNil ifTrue:[ |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
759 |
KnownProcesses := WeakArray new:30. |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
760 |
KnownProcesses addDependent:self class. |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
761 |
KnownProcessIds := OrderedCollection new. |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
762 |
]. |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
763 |
|
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
764 |
" |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
765 |
create a collection with process lists; accessed using the priority as key |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
766 |
" |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
767 |
nPrios := SchedulingPriority. |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
768 |
quiescentProcessLists := Array new:nPrios. |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
769 |
"/ 1 to:nPrios do:[:pri | |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
770 |
"/ quiescentProcessLists at:pri put:(LinkedList new) |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
771 |
"/ ]. |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
772 |
|
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
773 |
readFdArray := Array with:nil. |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
774 |
readCheckArray := Array with:nil. |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
775 |
readSemaphoreArray := Array with:nil. |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
776 |
writeFdArray := Array with:nil. |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
777 |
writeSemaphoreArray := Array with:nil. |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
778 |
timeoutArray := Array with:nil. |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
779 |
timeoutSemaphoreArray := Array with:nil. |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
780 |
timeoutActionArray := Array with:nil. |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
781 |
timeoutProcessArray := Array with:nil. |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
782 |
anyTimeouts := false. |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
783 |
dispatching := false. |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
784 |
exitWhenNoMoreUserProcesses := false. "/ mhmh - how about true ? |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
785 |
useIOInterrupts := OperatingSystem supportsIOInterrupts. |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
786 |
gotIOInterrupt := false. |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
787 |
osChildExitActions := Dictionary new. |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
788 |
gotChildSignalInterrupt := false. |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
789 |
|
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
790 |
" |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
791 |
handcraft the first (dispatcher-) process - this one will never |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
792 |
block, but go into a select if there is nothing to do. |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
793 |
Also, it has a prio of max+1 - thus, it comes first when looking |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
794 |
for a runnable process. |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
795 |
" |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
796 |
currentPriority := SchedulingPriority. |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
797 |
p := Process basicNew. |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
798 |
p setId:0 state:#run. |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
799 |
p setPriority:currentPriority. |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
800 |
p name:'scheduler'. |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
801 |
|
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
802 |
scheduler := activeProcess := p. |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
803 |
activeProcessId := 0. |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
804 |
|
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
805 |
quiescentProcessLists at:currentPriority put:(l := LinkedList new). |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
806 |
l add:p. |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
807 |
|
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
808 |
" |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
809 |
let me handle IO and timer interrupts |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
810 |
" |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
811 |
ObjectMemory ioInterruptHandler:self. |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
812 |
ObjectMemory timerInterruptHandler:self. |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
813 |
ObjectMemory childSignalInterruptHandler:self. |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
814 |
|
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
815 |
"Modified: 29.7.1996 / 12:10:59 / cg" |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
816 |
"Modified: 7.1.1997 / 16:48:26 / stefan" |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
817 |
! |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
818 |
|
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
819 |
reinitialize |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
820 |
"all previous processes (except those marked as restartable) are made dead |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
821 |
- each object should reinstall its process(s) upon restart; |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
822 |
especially, windowgroups have to. |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
823 |
In contrast to ST-80, restartable processes are restarted at the beginning |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
824 |
NOT continued where left. This is a consequence of the portable implementation |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
825 |
of ST/X, since in order to continue a process, we needed to know the |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
826 |
internals of the machines (and C-compilers) stack layout. |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
827 |
This was not done, favouring portability for process continuation. |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
828 |
In praxis, this is not much of a problem, since in almost every case, |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
829 |
the computation state can be saved in some object, and processing be |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
830 |
restarted from scratch, reinitializing things from this saved state." |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
831 |
|
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
832 |
" |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
833 |
lay all processes to rest, collect restartable ones |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
834 |
" |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
835 |
processesToRestart := OrderedCollection new. |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
836 |
KnownProcesses do:[:p | |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
837 |
(p notNil and:[p ~~ 0]) ifTrue:[ |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
838 |
"how, exactly should this be done ?" |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
839 |
|
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
840 |
p isRestartable == true ifTrue:[ |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
841 |
p nextLink:nil. |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
842 |
processesToRestart add:p |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
843 |
] ifFalse:[ |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
844 |
p setId:nil state:#dead |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
845 |
] |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
846 |
]. |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
847 |
]. |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
848 |
scheduler setId:nil state:#dead. |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
849 |
|
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
850 |
" |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
851 |
now, start from scratch |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
852 |
" |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
853 |
KnownProcesses := nil. |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
854 |
self initialize. |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
855 |
|
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
856 |
"Modified: / 7.6.1998 / 02:05:47 / cg" |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
857 |
! |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
858 |
|
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
859 |
restartRestartableProcesses |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
860 |
"restart those that can be. |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
861 |
This must be done as a second step, to make certain that all |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
862 |
of the GUI classes are intitialized first (and, especially the |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
863 |
event dispatching mechanism is running)" |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
864 |
|
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
865 |
|procs| |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
866 |
|
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
867 |
procs := processesToRestart. |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
868 |
procs notNil ifTrue:[ |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
869 |
processesToRestart := nil. |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
870 |
|
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
871 |
procs do:[:p | |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
872 |
p imageRestart |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
873 |
] |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
874 |
] |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
875 |
|
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
876 |
"Created: / 7.6.1998 / 02:06:52 / cg" |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
877 |
"Modified: / 7.6.1998 / 02:07:59 / cg" |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
878 |
! ! |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
879 |
|
827
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
807
diff
changeset
|
880 |
!ProcessorScheduler methodsFor:'os process handling'! |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
807
diff
changeset
|
881 |
|
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
807
diff
changeset
|
882 |
childSignalInterrupt |
2116
1bcb6ee86fca
fixed pending sigChild problem;
Claus Gittinger <cg@exept.de>
parents:
2111
diff
changeset
|
883 |
"{ Pragma: +returnable }" |
1bcb6ee86fca
fixed pending sigChild problem;
Claus Gittinger <cg@exept.de>
parents:
2111
diff
changeset
|
884 |
|
1154
96bb8fce61cf
Fix removeCorruptedFds to clear LastErrorNumber. Handle ChildSignalInterrupts in Scheduler's context, to avoid errno corruption.
Stefan Vogel <sv@exept.de>
parents:
1133
diff
changeset
|
885 |
"child changed state - switch to scheduler process which will decide |
96bb8fce61cf
Fix removeCorruptedFds to clear LastErrorNumber. Handle ChildSignalInterrupts in Scheduler's context, to avoid errno corruption.
Stefan Vogel <sv@exept.de>
parents:
1133
diff
changeset
|
886 |
what to do now." |
96bb8fce61cf
Fix removeCorruptedFds to clear LastErrorNumber. Handle ChildSignalInterrupts in Scheduler's context, to avoid errno corruption.
Stefan Vogel <sv@exept.de>
parents:
1133
diff
changeset
|
887 |
|
96bb8fce61cf
Fix removeCorruptedFds to clear LastErrorNumber. Handle ChildSignalInterrupts in Scheduler's context, to avoid errno corruption.
Stefan Vogel <sv@exept.de>
parents:
1133
diff
changeset
|
888 |
gotChildSignalInterrupt := true. |
2966 | 889 |
activeProcess ~~ scheduler ifTrue:[ |
890 |
interruptedProcess := activeProcess. |
|
891 |
self threadSwitch:scheduler |
|
892 |
] |
|
1154
96bb8fce61cf
Fix removeCorruptedFds to clear LastErrorNumber. Handle ChildSignalInterrupts in Scheduler's context, to avoid errno corruption.
Stefan Vogel <sv@exept.de>
parents:
1133
diff
changeset
|
893 |
|
96bb8fce61cf
Fix removeCorruptedFds to clear LastErrorNumber. Handle ChildSignalInterrupts in Scheduler's context, to avoid errno corruption.
Stefan Vogel <sv@exept.de>
parents:
1133
diff
changeset
|
894 |
"Modified: 12.4.1996 / 10:12:18 / stefan" |
96bb8fce61cf
Fix removeCorruptedFds to clear LastErrorNumber. Handle ChildSignalInterrupts in Scheduler's context, to avoid errno corruption.
Stefan Vogel <sv@exept.de>
parents:
1133
diff
changeset
|
895 |
! |
96bb8fce61cf
Fix removeCorruptedFds to clear LastErrorNumber. Handle ChildSignalInterrupts in Scheduler's context, to avoid errno corruption.
Stefan Vogel <sv@exept.de>
parents:
1133
diff
changeset
|
896 |
|
96bb8fce61cf
Fix removeCorruptedFds to clear LastErrorNumber. Handle ChildSignalInterrupts in Scheduler's context, to avoid errno corruption.
Stefan Vogel <sv@exept.de>
parents:
1133
diff
changeset
|
897 |
handleChildSignalInterrupt |
827
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
807
diff
changeset
|
898 |
"child changed state - execute child termination blocks. |
840
523533898acd
Reset sigCHLD interrupt handler, when no more processes are being waited for.
Stefan Vogel <sv@exept.de>
parents:
829
diff
changeset
|
899 |
If child is no longer alive, remove action block." |
523533898acd
Reset sigCHLD interrupt handler, when no more processes are being waited for.
Stefan Vogel <sv@exept.de>
parents:
829
diff
changeset
|
900 |
|
523533898acd
Reset sigCHLD interrupt handler, when no more processes are being waited for.
Stefan Vogel <sv@exept.de>
parents:
829
diff
changeset
|
901 |
|osProcessStatus blocking wasBlocked| |
827
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
807
diff
changeset
|
902 |
|
840
523533898acd
Reset sigCHLD interrupt handler, when no more processes are being waited for.
Stefan Vogel <sv@exept.de>
parents:
829
diff
changeset
|
903 |
blocking := OperatingSystem blockingChildProcessWait. |
827
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
807
diff
changeset
|
904 |
|
840
523533898acd
Reset sigCHLD interrupt handler, when no more processes are being waited for.
Stefan Vogel <sv@exept.de>
parents:
829
diff
changeset
|
905 |
"/ no interrupt processing, to avoid races with monitorPid |
523533898acd
Reset sigCHLD interrupt handler, when no more processes are being waited for.
Stefan Vogel <sv@exept.de>
parents:
829
diff
changeset
|
906 |
wasBlocked := OperatingSystem blockInterrupts. |
827
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
807
diff
changeset
|
907 |
[ |
1679
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
908 |
[ |
2614 | 909 |
osProcessStatus := OperatingSystem childProcessWait:blocking pid:nil. |
1679
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
910 |
osProcessStatus notNil ifTrue:[ |
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
911 |
|pid action| |
840
523533898acd
Reset sigCHLD interrupt handler, when no more processes are being waited for.
Stefan Vogel <sv@exept.de>
parents:
829
diff
changeset
|
912 |
|
1679
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
913 |
pid := osProcessStatus pid. |
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
914 |
osProcessStatus stillAlive ifTrue:[ |
2966 | 915 |
action := osChildExitActions at:pid ifAbsent:nil. |
1679
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
916 |
] ifFalse:[ |
2966 | 917 |
action := osChildExitActions removeKey:pid ifAbsent:nil. |
1679
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
918 |
]. |
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
919 |
action notNil ifTrue:[ |
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
920 |
action value:osProcessStatus |
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
921 |
]. |
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
922 |
]. |
827
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
807
diff
changeset
|
923 |
|
1679
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
924 |
"/ if pollChildProcesses does block, poll only one status change. |
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
925 |
"/ we will get another SIGCHLD for other status changes. |
840
523533898acd
Reset sigCHLD interrupt handler, when no more processes are being waited for.
Stefan Vogel <sv@exept.de>
parents:
829
diff
changeset
|
926 |
|
1679
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
927 |
osProcessStatus notNil and:[blocking not] |
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
928 |
] whileTrue. |
840
523533898acd
Reset sigCHLD interrupt handler, when no more processes are being waited for.
Stefan Vogel <sv@exept.de>
parents:
829
diff
changeset
|
929 |
|
1679
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
930 |
"/ if there are no more waiters, disable SIGCHILD handler. |
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
931 |
"/ this helps us with synchronous waiters (e.g. pclose), |
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
932 |
"/ But they should block SIGCHLD anyway. |
840
523533898acd
Reset sigCHLD interrupt handler, when no more processes are being waited for.
Stefan Vogel <sv@exept.de>
parents:
829
diff
changeset
|
933 |
|
1679
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
934 |
osChildExitActions isEmpty ifTrue:[ |
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
935 |
OperatingSystem disableChildSignalInterrupts. |
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
936 |
]. |
1032 | 937 |
] valueNowOrOnUnwindDo:[ |
1679
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
938 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
1032 | 939 |
] |
827
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
807
diff
changeset
|
940 |
|
840
523533898acd
Reset sigCHLD interrupt handler, when no more processes are being waited for.
Stefan Vogel <sv@exept.de>
parents:
829
diff
changeset
|
941 |
"Modified: 5.1.1996 / 16:56:11 / stefan" |
1032 | 942 |
"Modified: 28.2.1996 / 21:36:31 / cg" |
1154
96bb8fce61cf
Fix removeCorruptedFds to clear LastErrorNumber. Handle ChildSignalInterrupts in Scheduler's context, to avoid errno corruption.
Stefan Vogel <sv@exept.de>
parents:
1133
diff
changeset
|
943 |
"Created: 12.4.1996 / 10:08:21 / stefan" |
827
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
807
diff
changeset
|
944 |
! |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
807
diff
changeset
|
945 |
|
2499
95392696facc
Fix race condition when waiting for SIGCHLD.
Stefan Vogel <sv@exept.de>
parents:
2468
diff
changeset
|
946 |
monitor:aBlockReturningPid action:actionBlock |
2611
9a575397bf9a
fixed davids monitorPid (dont wait a second; dont do busy poll ...)
Claus Gittinger <cg@exept.de>
parents:
2534
diff
changeset
|
947 |
"Helper for executing and waiting for OS processes. |
2499
95392696facc
Fix race condition when waiting for SIGCHLD.
Stefan Vogel <sv@exept.de>
parents:
2468
diff
changeset
|
948 |
aBlockReturningPid is evaluated and supposed to return |
95392696facc
Fix race condition when waiting for SIGCHLD.
Stefan Vogel <sv@exept.de>
parents:
2468
diff
changeset
|
949 |
the process-id of an OS-process or nil. |
95392696facc
Fix race condition when waiting for SIGCHLD.
Stefan Vogel <sv@exept.de>
parents:
2468
diff
changeset
|
950 |
To avoid race conditions, the OS-process must be started |
95392696facc
Fix race condition when waiting for SIGCHLD.
Stefan Vogel <sv@exept.de>
parents:
2468
diff
changeset
|
951 |
within the block. |
95392696facc
Fix race condition when waiting for SIGCHLD.
Stefan Vogel <sv@exept.de>
parents:
2468
diff
changeset
|
952 |
ActionBlock will be called with an OSProcessStatus as arg if the |
95392696facc
Fix race condition when waiting for SIGCHLD.
Stefan Vogel <sv@exept.de>
parents:
2468
diff
changeset
|
953 |
status of the OS process changes (e.g. the process terminates). |
2611
9a575397bf9a
fixed davids monitorPid (dont wait a second; dont do busy poll ...)
Claus Gittinger <cg@exept.de>
parents:
2534
diff
changeset
|
954 |
The method returns the value from aBlockReturningPid (i.e a pid or nil)." |
9a575397bf9a
fixed davids monitorPid (dont wait a second; dont do busy poll ...)
Claus Gittinger <cg@exept.de>
parents:
2534
diff
changeset
|
955 |
|
2926 | 956 |
|pid blocked osProcessStatus| |
827
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
807
diff
changeset
|
957 |
|
2962 | 958 |
OperatingSystem supportsChildInterrupts ifTrue:[ |
3270
fd52c625f87c
fixed monitoring for non-sigChild systems (WIN32)
Claus Gittinger <cg@exept.de>
parents:
3246
diff
changeset
|
959 |
"/ SIGCHLD is supported, |
fd52c625f87c
fixed monitoring for non-sigChild systems (WIN32)
Claus Gittinger <cg@exept.de>
parents:
3246
diff
changeset
|
960 |
"/ aBlock will be evaluated, as soon as a SIGCHLD interrupt for pid has been received. |
fd52c625f87c
fixed monitoring for non-sigChild systems (WIN32)
Claus Gittinger <cg@exept.de>
parents:
3246
diff
changeset
|
961 |
|
fd52c625f87c
fixed monitoring for non-sigChild systems (WIN32)
Claus Gittinger <cg@exept.de>
parents:
3246
diff
changeset
|
962 |
OperatingSystem enableChildSignalInterrupts. |
fd52c625f87c
fixed monitoring for non-sigChild systems (WIN32)
Claus Gittinger <cg@exept.de>
parents:
3246
diff
changeset
|
963 |
blocked := OperatingSystem blockInterrupts. |
fd52c625f87c
fixed monitoring for non-sigChild systems (WIN32)
Claus Gittinger <cg@exept.de>
parents:
3246
diff
changeset
|
964 |
pid := aBlockReturningPid value. |
fd52c625f87c
fixed monitoring for non-sigChild systems (WIN32)
Claus Gittinger <cg@exept.de>
parents:
3246
diff
changeset
|
965 |
pid notNil ifTrue:[ |
fd52c625f87c
fixed monitoring for non-sigChild systems (WIN32)
Claus Gittinger <cg@exept.de>
parents:
3246
diff
changeset
|
966 |
osChildExitActions at:pid put:actionBlock. |
fd52c625f87c
fixed monitoring for non-sigChild systems (WIN32)
Claus Gittinger <cg@exept.de>
parents:
3246
diff
changeset
|
967 |
]. |
fd52c625f87c
fixed monitoring for non-sigChild systems (WIN32)
Claus Gittinger <cg@exept.de>
parents:
3246
diff
changeset
|
968 |
blocked ifFalse:[ |
fd52c625f87c
fixed monitoring for non-sigChild systems (WIN32)
Claus Gittinger <cg@exept.de>
parents:
3246
diff
changeset
|
969 |
OperatingSystem unblockInterrupts. |
fd52c625f87c
fixed monitoring for non-sigChild systems (WIN32)
Claus Gittinger <cg@exept.de>
parents:
3246
diff
changeset
|
970 |
]. |
840
523533898acd
Reset sigCHLD interrupt handler, when no more processes are being waited for.
Stefan Vogel <sv@exept.de>
parents:
829
diff
changeset
|
971 |
] ifFalse:[ |
3270
fd52c625f87c
fixed monitoring for non-sigChild systems (WIN32)
Claus Gittinger <cg@exept.de>
parents:
3246
diff
changeset
|
972 |
"/ SIGCHLD is not supported, fork a high prio process |
fd52c625f87c
fixed monitoring for non-sigChild systems (WIN32)
Claus Gittinger <cg@exept.de>
parents:
3246
diff
changeset
|
973 |
"/ to poll for for the exit of pid. |
fd52c625f87c
fixed monitoring for non-sigChild systems (WIN32)
Claus Gittinger <cg@exept.de>
parents:
3246
diff
changeset
|
974 |
|
fd52c625f87c
fixed monitoring for non-sigChild systems (WIN32)
Claus Gittinger <cg@exept.de>
parents:
3246
diff
changeset
|
975 |
blocked := OperatingSystem blockInterrupts. |
fd52c625f87c
fixed monitoring for non-sigChild systems (WIN32)
Claus Gittinger <cg@exept.de>
parents:
3246
diff
changeset
|
976 |
pid := aBlockReturningPid value. |
fd52c625f87c
fixed monitoring for non-sigChild systems (WIN32)
Claus Gittinger <cg@exept.de>
parents:
3246
diff
changeset
|
977 |
pid notNil ifTrue:[ |
fd52c625f87c
fixed monitoring for non-sigChild systems (WIN32)
Claus Gittinger <cg@exept.de>
parents:
3246
diff
changeset
|
978 |
osChildExitActions at:pid put:actionBlock. |
fd52c625f87c
fixed monitoring for non-sigChild systems (WIN32)
Claus Gittinger <cg@exept.de>
parents:
3246
diff
changeset
|
979 |
]. |
fd52c625f87c
fixed monitoring for non-sigChild systems (WIN32)
Claus Gittinger <cg@exept.de>
parents:
3246
diff
changeset
|
980 |
blocked ifFalse:[ |
fd52c625f87c
fixed monitoring for non-sigChild systems (WIN32)
Claus Gittinger <cg@exept.de>
parents:
3246
diff
changeset
|
981 |
OperatingSystem unblockInterrupts. |
fd52c625f87c
fixed monitoring for non-sigChild systems (WIN32)
Claus Gittinger <cg@exept.de>
parents:
3246
diff
changeset
|
982 |
]. |
fd52c625f87c
fixed monitoring for non-sigChild systems (WIN32)
Claus Gittinger <cg@exept.de>
parents:
3246
diff
changeset
|
983 |
|
fd52c625f87c
fixed monitoring for non-sigChild systems (WIN32)
Claus Gittinger <cg@exept.de>
parents:
3246
diff
changeset
|
984 |
[ |
fd52c625f87c
fixed monitoring for non-sigChild systems (WIN32)
Claus Gittinger <cg@exept.de>
parents:
3246
diff
changeset
|
985 |
[ |
fd52c625f87c
fixed monitoring for non-sigChild systems (WIN32)
Claus Gittinger <cg@exept.de>
parents:
3246
diff
changeset
|
986 |
|polling| |
fd52c625f87c
fixed monitoring for non-sigChild systems (WIN32)
Claus Gittinger <cg@exept.de>
parents:
3246
diff
changeset
|
987 |
|
fd52c625f87c
fixed monitoring for non-sigChild systems (WIN32)
Claus Gittinger <cg@exept.de>
parents:
3246
diff
changeset
|
988 |
polling := true. |
fd52c625f87c
fixed monitoring for non-sigChild systems (WIN32)
Claus Gittinger <cg@exept.de>
parents:
3246
diff
changeset
|
989 |
[polling] whileTrue:[ |
fd52c625f87c
fixed monitoring for non-sigChild systems (WIN32)
Claus Gittinger <cg@exept.de>
parents:
3246
diff
changeset
|
990 |
Delay waitForMilliseconds:EventPollingInterval. |
fd52c625f87c
fixed monitoring for non-sigChild systems (WIN32)
Claus Gittinger <cg@exept.de>
parents:
3246
diff
changeset
|
991 |
(osChildExitActions includesKey:pid) ifFalse:[ |
fd52c625f87c
fixed monitoring for non-sigChild systems (WIN32)
Claus Gittinger <cg@exept.de>
parents:
3246
diff
changeset
|
992 |
polling := false. |
fd52c625f87c
fixed monitoring for non-sigChild systems (WIN32)
Claus Gittinger <cg@exept.de>
parents:
3246
diff
changeset
|
993 |
] ifTrue:[ |
fd52c625f87c
fixed monitoring for non-sigChild systems (WIN32)
Claus Gittinger <cg@exept.de>
parents:
3246
diff
changeset
|
994 |
osProcessStatus := OperatingSystem childProcessWait:false pid:pid. |
fd52c625f87c
fixed monitoring for non-sigChild systems (WIN32)
Claus Gittinger <cg@exept.de>
parents:
3246
diff
changeset
|
995 |
osProcessStatus notNil ifTrue:[ |
fd52c625f87c
fixed monitoring for non-sigChild systems (WIN32)
Claus Gittinger <cg@exept.de>
parents:
3246
diff
changeset
|
996 |
(osProcessStatus pid = pid) ifTrue:[ |
fd52c625f87c
fixed monitoring for non-sigChild systems (WIN32)
Claus Gittinger <cg@exept.de>
parents:
3246
diff
changeset
|
997 |
osChildExitActions removeKey:pid ifAbsent:nil. |
fd52c625f87c
fixed monitoring for non-sigChild systems (WIN32)
Claus Gittinger <cg@exept.de>
parents:
3246
diff
changeset
|
998 |
actionBlock value:osProcessStatus. |
fd52c625f87c
fixed monitoring for non-sigChild systems (WIN32)
Claus Gittinger <cg@exept.de>
parents:
3246
diff
changeset
|
999 |
polling := false. |
fd52c625f87c
fixed monitoring for non-sigChild systems (WIN32)
Claus Gittinger <cg@exept.de>
parents:
3246
diff
changeset
|
1000 |
] ifFalse:[ |
fd52c625f87c
fixed monitoring for non-sigChild systems (WIN32)
Claus Gittinger <cg@exept.de>
parents:
3246
diff
changeset
|
1001 |
osProcessStatus stillAlive |
fd52c625f87c
fixed monitoring for non-sigChild systems (WIN32)
Claus Gittinger <cg@exept.de>
parents:
3246
diff
changeset
|
1002 |
] |
fd52c625f87c
fixed monitoring for non-sigChild systems (WIN32)
Claus Gittinger <cg@exept.de>
parents:
3246
diff
changeset
|
1003 |
] |
fd52c625f87c
fixed monitoring for non-sigChild systems (WIN32)
Claus Gittinger <cg@exept.de>
parents:
3246
diff
changeset
|
1004 |
]. |
fd52c625f87c
fixed monitoring for non-sigChild systems (WIN32)
Claus Gittinger <cg@exept.de>
parents:
3246
diff
changeset
|
1005 |
] |
fd52c625f87c
fixed monitoring for non-sigChild systems (WIN32)
Claus Gittinger <cg@exept.de>
parents:
3246
diff
changeset
|
1006 |
] valueOnUnwindDo:[ |
fd52c625f87c
fixed monitoring for non-sigChild systems (WIN32)
Claus Gittinger <cg@exept.de>
parents:
3246
diff
changeset
|
1007 |
osChildExitActions removeKey:pid ifAbsent:nil |
fd52c625f87c
fixed monitoring for non-sigChild systems (WIN32)
Claus Gittinger <cg@exept.de>
parents:
3246
diff
changeset
|
1008 |
] |
fd52c625f87c
fixed monitoring for non-sigChild systems (WIN32)
Claus Gittinger <cg@exept.de>
parents:
3246
diff
changeset
|
1009 |
] forkAt:TimingPriority. |
840
523533898acd
Reset sigCHLD interrupt handler, when no more processes are being waited for.
Stefan Vogel <sv@exept.de>
parents:
829
diff
changeset
|
1010 |
]. |
2499
95392696facc
Fix race condition when waiting for SIGCHLD.
Stefan Vogel <sv@exept.de>
parents:
2468
diff
changeset
|
1011 |
^ pid |
95392696facc
Fix race condition when waiting for SIGCHLD.
Stefan Vogel <sv@exept.de>
parents:
2468
diff
changeset
|
1012 |
|
3270
fd52c625f87c
fixed monitoring for non-sigChild systems (WIN32)
Claus Gittinger <cg@exept.de>
parents:
3246
diff
changeset
|
1013 |
"Created: / 25.3.1997 / 10:54:56 / stefan" |
fd52c625f87c
fixed monitoring for non-sigChild systems (WIN32)
Claus Gittinger <cg@exept.de>
parents:
3246
diff
changeset
|
1014 |
"Modified: / 25.3.1997 / 11:21:05 / stefan" |
fd52c625f87c
fixed monitoring for non-sigChild systems (WIN32)
Claus Gittinger <cg@exept.de>
parents:
3246
diff
changeset
|
1015 |
"Modified: / 15.4.1997 / 11:55:57 / David" |
fd52c625f87c
fixed monitoring for non-sigChild systems (WIN32)
Claus Gittinger <cg@exept.de>
parents:
3246
diff
changeset
|
1016 |
"Modified: / 28.1.1998 / 18:13:23 / cg" |
1166
f5affd8cb289
added #unmonitorPid: - there still is trouble with zombie subchilds, if a process is killed via #killProcess:
Claus Gittinger <cg@exept.de>
parents:
1154
diff
changeset
|
1017 |
! |
f5affd8cb289
added #unmonitorPid: - there still is trouble with zombie subchilds, if a process is killed via #killProcess:
Claus Gittinger <cg@exept.de>
parents:
1154
diff
changeset
|
1018 |
|
f5affd8cb289
added #unmonitorPid: - there still is trouble with zombie subchilds, if a process is killed via #killProcess:
Claus Gittinger <cg@exept.de>
parents:
1154
diff
changeset
|
1019 |
unmonitorPid:pid |
f5affd8cb289
added #unmonitorPid: - there still is trouble with zombie subchilds, if a process is killed via #killProcess:
Claus Gittinger <cg@exept.de>
parents:
1154
diff
changeset
|
1020 |
"remove a monitor for a child process" |
f5affd8cb289
added #unmonitorPid: - there still is trouble with zombie subchilds, if a process is killed via #killProcess:
Claus Gittinger <cg@exept.de>
parents:
1154
diff
changeset
|
1021 |
|
2966 | 1022 |
osChildExitActions removeKey:pid ifAbsent:nil. |
1166
f5affd8cb289
added #unmonitorPid: - there still is trouble with zombie subchilds, if a process is killed via #killProcess:
Claus Gittinger <cg@exept.de>
parents:
1154
diff
changeset
|
1023 |
|
f5affd8cb289
added #unmonitorPid: - there still is trouble with zombie subchilds, if a process is killed via #killProcess:
Claus Gittinger <cg@exept.de>
parents:
1154
diff
changeset
|
1024 |
"Created: 12.4.1996 / 19:01:59 / cg" |
699 | 1025 |
! ! |
1026 |
||
1027 |
!ProcessorScheduler methodsFor:'primitive process primitives'! |
|
1028 |
||
1029 |
scheduleForInterrupt:aProcess |
|
1030 |
"make aProcess evaluate its pushed interrupt block(s)" |
|
1031 |
||
1092
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
1032 |
self scheduleInterruptActionsOf:aProcess. |
699 | 1033 |
" |
1034 |
and, make the process runnable |
|
1035 |
" |
|
1036 |
aProcess state ~~ #stopped ifTrue:[ |
|
1679
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
1037 |
" |
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
1038 |
and, make the process runnable |
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
1039 |
" |
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
1040 |
self resume:aProcess |
699 | 1041 |
] |
1092
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
1042 |
|
1473 | 1043 |
"Modified: 17.6.1996 / 14:40:52 / cg" |
1092
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
1044 |
! |
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
1045 |
|
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
1046 |
scheduleInterruptActionsOf:aProcess |
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
1047 |
"make aProcess evaluate its pushed interrupt block(s) |
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
1048 |
when resumed." |
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
1049 |
|
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
1050 |
|id| |
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
1051 |
|
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
1052 |
aProcess isNil ifTrue:[^ self]. |
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
1053 |
aProcess == activeProcess ifTrue:[^ self]. |
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
1054 |
|
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
1055 |
id := aProcess id. |
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
1056 |
self class threadInterrupt:id. |
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
1057 |
|
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
1058 |
"Created: 5.3.1996 / 17:25:55 / cg" |
699 | 1059 |
! |
1060 |
||
1061 |
threadSwitch:aProcess |
|
1062 |
"continue execution in aProcess. |
|
1783
be7402f74d94
hide timerInterrupt & ioInterrupt contexts when switching
Claus Gittinger <cg@exept.de>
parents:
1780
diff
changeset
|
1063 |
WARNING: this is a low level entry, no process administration is done here" |
699 | 1064 |
|
2262 | 1065 |
|id pri ok oldProcess oldPri oldId p singleStep wasBlocked| |
699 | 1066 |
|
1067 |
(aProcess isNil or:[aProcess == activeProcess]) ifTrue:[^ self]. |
|
1068 |
||
1069 |
wasBlocked := OperatingSystem blockInterrupts. |
|
1070 |
||
1071 |
oldProcess := activeProcess. |
|
2262 | 1072 |
oldId := activeProcessId. |
699 | 1073 |
oldPri := currentPriority. |
1074 |
||
1075 |
id := aProcess id. |
|
1076 |
pri := aProcess priority. |
|
1077 |
singleStep := aProcess isSingleStepping. |
|
1078 |
aProcess state:#active. |
|
1079 |
oldProcess setStateTo:#run if:#active. |
|
1080 |
||
1081 |
" |
|
1082 |
no interrupts now - activeProcess has already been changed |
|
1083 |
(dont add any message sends here) |
|
1084 |
" |
|
1085 |
activeProcess := aProcess. |
|
2262 | 1086 |
activeProcessId := id. |
699 | 1087 |
currentPriority := pri. |
1088 |
%{ |
|
1089 |
extern OBJ ___threadSwitch(); |
|
1090 |
||
1091 |
if (__isSmallInteger(id)) { |
|
2534 | 1092 |
ok = ___threadSwitch(__context, __intVal(id), (singleStep == true) ? 1 : 0); |
699 | 1093 |
} else { |
2534 | 1094 |
ok = false; |
699 | 1095 |
} |
1096 |
%}. |
|
1097 |
"time passes spent in some other process ... |
|
1098 |
... here again" |
|
1099 |
||
1100 |
p := activeProcess. |
|
1101 |
activeProcess := oldProcess. |
|
2262 | 1102 |
activeProcessId := oldId. |
699 | 1103 |
currentPriority := oldProcess priority. |
1104 |
||
1105 |
ok ifFalse:[ |
|
2534 | 1106 |
" |
1107 |
switch failed for some reason - |
|
1108 |
destroy the bad process |
|
1109 |
" |
|
3312 | 1110 |
(id := p id) ~~ 0 ifTrue:[ |
1111 |
id notNil ifTrue:[ |
|
1112 |
'Processor [warning]: problem with process ' errorPrint. |
|
1113 |
id errorPrint. |
|
2534 | 1114 |
p name notNil ifTrue:[ |
1115 |
' (' errorPrint. p name errorPrint. ')' errorPrint. |
|
1116 |
]. |
|
1117 |
'; hard-terminate it.' errorPrintCR. |
|
3312 | 1118 |
'Processor [info]: cleanup may take a while if stack is huge' infoPrintCR. |
1119 |
p state:#suspended. |
|
1120 |
self terminateNoSignal:p. |
|
1121 |
] |
|
2534 | 1122 |
] |
699 | 1123 |
]. |
1124 |
zombie notNil ifTrue:[ |
|
2534 | 1125 |
self class threadDestroy:zombie. |
1126 |
zombie := nil |
|
1783
be7402f74d94
hide timerInterrupt & ioInterrupt contexts when switching
Claus Gittinger <cg@exept.de>
parents:
1780
diff
changeset
|
1127 |
]. |
be7402f74d94
hide timerInterrupt & ioInterrupt contexts when switching
Claus Gittinger <cg@exept.de>
parents:
1780
diff
changeset
|
1128 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
1787
32632b6f969d
remember threadSwitch:from: idea for later implementation;
Claus Gittinger <cg@exept.de>
parents:
1783
diff
changeset
|
1129 |
! ! |
32632b6f969d
remember threadSwitch:from: idea for later implementation;
Claus Gittinger <cg@exept.de>
parents:
1783
diff
changeset
|
1130 |
|
1981
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1131 |
!ProcessorScheduler methodsFor:'priority constants'! |
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1132 |
|
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1133 |
highIOPriority |
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1134 |
"not currently used - for ST80 compatibility only" |
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1135 |
|
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1136 |
^ 16 "claus: is this ok ?" |
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1137 |
|
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1138 |
"Created: 15.11.1996 / 11:42:39 / cg" |
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1139 |
! |
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1140 |
|
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1141 |
highestPriority |
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1142 |
"return the highest priority value (normal) processes can have." |
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1143 |
|
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1144 |
"must be below schedulingPriority - |
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1145 |
otherwise scheduler could be blocked ... |
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1146 |
" |
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1147 |
^ HighestPriority |
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1148 |
! |
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1149 |
|
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1150 |
lowIOPriority |
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1151 |
"not currently used - for ST80 compatibility only" |
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1152 |
|
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1153 |
^ 2 "claus: is this ok ?" |
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1154 |
! |
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1155 |
|
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1156 |
lowestPriority |
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1157 |
"return the lowest priority value" |
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1158 |
|
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1159 |
^ 1 "do not change this - its not variable" |
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1160 |
! |
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1161 |
|
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1162 |
schedulingPriority |
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1163 |
"return the priority at which the scheduler runs." |
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1164 |
|
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1165 |
"must be above highestPriority - |
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1166 |
otherwise scheduler could be blocked ... |
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1167 |
" |
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1168 |
^ SchedulingPriority |
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1169 |
! |
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1170 |
|
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1171 |
systemBackgroundPriority |
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1172 |
"return the priority, at which background system processing |
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1173 |
should take place. |
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1174 |
Not currently used - for ST80 compatibility only" |
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1175 |
|
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1176 |
^ 4 |
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1177 |
! |
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1178 |
|
2190 | 1179 |
timeSlicingPriorityLimit |
1180 |
"return the priority, above which no timeslicing takes place |
|
1181 |
(i.e. processes running at a higher priority are not preempted). |
|
1182 |
This is only effective, if preemption is enabled." |
|
1183 |
||
1184 |
^ TimeSlicingPriorityLimit |
|
1185 |
! |
|
1186 |
||
2191 | 1187 |
timingPriority |
1188 |
"return the priority, at which all timing takes place (messageTally, |
|
1189 |
delay etc.)" |
|
1190 |
||
1191 |
^ TimingPriority |
|
1192 |
! |
|
1193 |
||
1981
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1194 |
userBackgroundPriority |
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1195 |
"return the priority, at which background user (non-interactive) processing |
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1196 |
should take place. |
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1197 |
Not currently used - for ST80 compatibility only" |
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1198 |
|
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1199 |
^ 6 |
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1200 |
! |
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1201 |
|
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1202 |
userInterruptPriority |
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1203 |
"return the priority, at which the event scheduler runs - i.e. |
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1204 |
all processes running at a lower priority are interruptable by Cntl-C |
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1205 |
or the timer. Processes running at higher prio will not be interrupted." |
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1206 |
|
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1207 |
^ UserInterruptPriority |
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1208 |
! |
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1209 |
|
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1210 |
userSchedulingPriority |
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1211 |
"return the priority, at which all normal user (interactive) processing |
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1212 |
takes place" |
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1213 |
|
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1214 |
^ UserSchedulingPriority |
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1215 |
! ! |
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1216 |
|
699 | 1217 |
!ProcessorScheduler methodsFor:'private'! |
1218 |
||
1219 |
remember:aProcess |
|
1220 |
"remember aProcess for later disposal (where the underlying |
|
1221 |
system resources have to be freed)." |
|
1222 |
||
1223 |
|newShadow oldId wasBlocked |
|
1224 |
oldSize "{ Class: SmallInteger }" |
|
1225 |
index "{ Class: SmallInteger }" |
|
1787
32632b6f969d
remember threadSwitch:from: idea for later implementation;
Claus Gittinger <cg@exept.de>
parents:
1783
diff
changeset
|
1226 |
sz "{ Class: SmallInteger }" | |
699 | 1227 |
|
1228 |
wasBlocked := OperatingSystem blockInterrupts. |
|
1229 |
index := 1. |
|
1230 |
sz := KnownProcessIds size. |
|
1231 |
[index <= sz] whileTrue:[ |
|
2534 | 1232 |
(KnownProcesses at:index) isNil ifTrue:[ |
1233 |
oldId := KnownProcessIds at:index. |
|
1234 |
oldId notNil ifTrue:[ |
|
1235 |
self class threadDestroy:oldId. |
|
1236 |
]. |
|
1237 |
KnownProcesses at:index put:aProcess. |
|
1238 |
KnownProcessIds at:index put:aProcess id. |
|
1239 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
1240 |
^ self |
|
1241 |
]. |
|
1242 |
index := index + 1 |
|
699 | 1243 |
]. |
1244 |
||
1245 |
KnownProcessIds grow:index. |
|
1246 |
KnownProcessIds at:index put:aProcess id. |
|
1247 |
||
1248 |
oldSize := KnownProcesses size. |
|
1249 |
(index > oldSize) ifTrue:[ |
|
2534 | 1250 |
newShadow := WeakArray new:(oldSize * 2). |
1251 |
newShadow addDependent:self class. |
|
1252 |
newShadow replaceFrom:1 with:KnownProcesses. |
|
1253 |
KnownProcesses := newShadow |
|
699 | 1254 |
]. |
1255 |
KnownProcesses at:index put:aProcess. |
|
1256 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
2091
c11bb3e29a1b
Use dependent mechamism of WeakArray instead of #watcher.
Stefan Vogel <sv@exept.de>
parents:
1981
diff
changeset
|
1257 |
|
c11bb3e29a1b
Use dependent mechamism of WeakArray instead of #watcher.
Stefan Vogel <sv@exept.de>
parents:
1981
diff
changeset
|
1258 |
"Modified: 7.1.1997 / 16:48:39 / stefan" |
699 | 1259 |
! |
1260 |
||
1261 |
unRemember:aProcess |
|
1262 |
"forget aProcess - dispose processing will not consider this one" |
|
1263 |
||
1264 |
|index wasBlocked| |
|
1265 |
||
1266 |
wasBlocked := OperatingSystem blockInterrupts. |
|
1267 |
index := KnownProcesses identityIndexOf:aProcess. |
|
1268 |
index ~~ 0 ifTrue:[ |
|
1269 |
KnownProcessIds at:index put:nil. |
|
1270 |
KnownProcesses at:index put:nil. |
|
1271 |
]. |
|
1272 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
1273 |
! ! |
|
1274 |
||
1275 |
!ProcessorScheduler methodsFor:'process creation'! |
|
1276 |
||
1277 |
newProcessFor:aProcess |
|
1278 |
"create a physical (VM-) process for aProcess. |
|
1279 |
Return true if ok, false if something went wrong. |
|
1280 |
The process is not scheduled; to start it running, |
|
1281 |
it needs a Process>>resume. Once resumed, the process will later |
|
1282 |
get control in its #start method." |
|
1283 |
||
1284 |
|id| |
|
1285 |
||
1286 |
id := self class threadCreate:aProcess withId:nil. |
|
1287 |
id isNil ifTrue:[^ false]. |
|
1288 |
||
1289 |
aProcess setId:id state:#light. "meaning: has no stack yet" |
|
1290 |
self remember:aProcess. |
|
1291 |
^ true |
|
1292 |
! |
|
1293 |
||
1294 |
newProcessFor:aProcess withId:idWant |
|
1295 |
"private entry for Process restart - do not use in your program" |
|
1296 |
||
1836
08a200835cc8
process restart is different if done at image restart time.
Claus Gittinger <cg@exept.de>
parents:
1793
diff
changeset
|
1297 |
idWant isNil ifTrue:[ |
2534 | 1298 |
^ self newProcessFor:aProcess |
1836
08a200835cc8
process restart is different if done at image restart time.
Claus Gittinger <cg@exept.de>
parents:
1793
diff
changeset
|
1299 |
]. |
08a200835cc8
process restart is different if done at image restart time.
Claus Gittinger <cg@exept.de>
parents:
1793
diff
changeset
|
1300 |
|
699 | 1301 |
(self class threadCreate:aProcess withId:idWant) ~~ idWant ifTrue:[ |
2534 | 1302 |
^ false |
699 | 1303 |
]. |
1304 |
||
1305 |
aProcess state:#light. "meaning: has no stack yet" |
|
1306 |
self remember:aProcess. |
|
1307 |
^ true |
|
1836
08a200835cc8
process restart is different if done at image restart time.
Claus Gittinger <cg@exept.de>
parents:
1793
diff
changeset
|
1308 |
|
08a200835cc8
process restart is different if done at image restart time.
Claus Gittinger <cg@exept.de>
parents:
1793
diff
changeset
|
1309 |
"Modified: 28.10.1996 / 19:14:28 / cg" |
699 | 1310 |
! ! |
1311 |
||
1312 |
!ProcessorScheduler methodsFor:'queries'! |
|
1313 |
||
1314 |
activeProcessIsSystemProcess |
|
1315 |
"return true if the active process is a system process, |
|
1316 |
which should not be suspended." |
|
1317 |
||
2637
0d8508bedf06
Move #isSystemProcess from ProcessorScheduler to Process.
Stefan Vogel <sv@exept.de>
parents:
2626
diff
changeset
|
1318 |
^ activeProcess isSystemProcess |
699 | 1319 |
|
1320 |
" |
|
1321 |
Processor activeProcessIsSystemProcess |
|
1322 |
" |
|
2637
0d8508bedf06
Move #isSystemProcess from ProcessorScheduler to Process.
Stefan Vogel <sv@exept.de>
parents:
2626
diff
changeset
|
1323 |
|
0d8508bedf06
Move #isSystemProcess from ProcessorScheduler to Process.
Stefan Vogel <sv@exept.de>
parents:
2626
diff
changeset
|
1324 |
"Modified: 17.4.1997 / 12:59:33 / stefan" |
699 | 1325 |
! |
1326 |
||
964
6d87e84d86ac
in standAloneMode: exit dispatch if last process dies and no more sema/timer waits are pending
Claus Gittinger <cg@exept.de>
parents:
840
diff
changeset
|
1327 |
anyUserProcessAtAll |
1571
8d00e6b97ca7
changed #anyUserProcessAtAll,
Claus Gittinger <cg@exept.de>
parents:
1473
diff
changeset
|
1328 |
"return true, if there is any process still running with a |
8d00e6b97ca7
changed #anyUserProcessAtAll,
Claus Gittinger <cg@exept.de>
parents:
1473
diff
changeset
|
1329 |
non-zero processGroup (i.e. any non-system process). |
964
6d87e84d86ac
in standAloneMode: exit dispatch if last process dies and no more sema/timer waits are pending
Claus Gittinger <cg@exept.de>
parents:
840
diff
changeset
|
1330 |
This is used to determine if we should stop scheduling |
2193 | 1331 |
in standAlone applications. |
1332 |
A userProcess has a non-zero processGroup." |
|
964
6d87e84d86ac
in standAloneMode: exit dispatch if last process dies and no more sema/timer waits are pending
Claus Gittinger <cg@exept.de>
parents:
840
diff
changeset
|
1333 |
|
987 | 1334 |
|listArray l prio "{ Class: SmallInteger }" | |
964
6d87e84d86ac
in standAloneMode: exit dispatch if last process dies and no more sema/timer waits are pending
Claus Gittinger <cg@exept.de>
parents:
840
diff
changeset
|
1335 |
|
6d87e84d86ac
in standAloneMode: exit dispatch if last process dies and no more sema/timer waits are pending
Claus Gittinger <cg@exept.de>
parents:
840
diff
changeset
|
1336 |
prio := HighestPriority. |
6d87e84d86ac
in standAloneMode: exit dispatch if last process dies and no more sema/timer waits are pending
Claus Gittinger <cg@exept.de>
parents:
840
diff
changeset
|
1337 |
listArray := quiescentProcessLists. |
1571
8d00e6b97ca7
changed #anyUserProcessAtAll,
Claus Gittinger <cg@exept.de>
parents:
1473
diff
changeset
|
1338 |
|
8d00e6b97ca7
changed #anyUserProcessAtAll,
Claus Gittinger <cg@exept.de>
parents:
1473
diff
changeset
|
1339 |
[prio >= 1] whileTrue:[ |
1679
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
1340 |
l := listArray at:prio. |
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
1341 |
l notNil ifTrue:[ |
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
1342 |
l do:[:aProcess | |
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
1343 |
aProcess processGroupId ~~ 0 ifTrue:[ |
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
1344 |
^ true. |
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
1345 |
] |
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
1346 |
] |
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
1347 |
]. |
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
1348 |
prio := prio - 1 |
964
6d87e84d86ac
in standAloneMode: exit dispatch if last process dies and no more sema/timer waits are pending
Claus Gittinger <cg@exept.de>
parents:
840
diff
changeset
|
1349 |
]. |
6d87e84d86ac
in standAloneMode: exit dispatch if last process dies and no more sema/timer waits are pending
Claus Gittinger <cg@exept.de>
parents:
840
diff
changeset
|
1350 |
^ false |
1571
8d00e6b97ca7
changed #anyUserProcessAtAll,
Claus Gittinger <cg@exept.de>
parents:
1473
diff
changeset
|
1351 |
|
8d00e6b97ca7
changed #anyUserProcessAtAll,
Claus Gittinger <cg@exept.de>
parents:
1473
diff
changeset
|
1352 |
" |
8d00e6b97ca7
changed #anyUserProcessAtAll,
Claus Gittinger <cg@exept.de>
parents:
1473
diff
changeset
|
1353 |
Processor anyUserProcessAtAll |
8d00e6b97ca7
changed #anyUserProcessAtAll,
Claus Gittinger <cg@exept.de>
parents:
1473
diff
changeset
|
1354 |
" |
8d00e6b97ca7
changed #anyUserProcessAtAll,
Claus Gittinger <cg@exept.de>
parents:
1473
diff
changeset
|
1355 |
|
1618 | 1356 |
"Modified: 29.7.1996 / 11:49:17 / cg" |
964
6d87e84d86ac
in standAloneMode: exit dispatch if last process dies and no more sema/timer waits are pending
Claus Gittinger <cg@exept.de>
parents:
840
diff
changeset
|
1357 |
! |
6d87e84d86ac
in standAloneMode: exit dispatch if last process dies and no more sema/timer waits are pending
Claus Gittinger <cg@exept.de>
parents:
840
diff
changeset
|
1358 |
|
699 | 1359 |
highestPriorityRunnableProcess |
1360 |
"return the highest prio runnable process" |
|
1361 |
||
1362 |
|listArray l p prio "{ Class: SmallInteger }" | |
|
1363 |
||
1364 |
prio := HighestPriority. |
|
1365 |
listArray := quiescentProcessLists. |
|
1366 |
[prio >= 1] whileTrue:[ |
|
2534 | 1367 |
l := listArray at:prio. |
1368 |
l notNil ifTrue:[ |
|
1369 |
l isEmpty ifFalse:[ |
|
1370 |
p := l first. |
|
1371 |
" |
|
1372 |
if it got corrupted somehow ... |
|
1373 |
" |
|
1374 |
p id isNil ifTrue:[ |
|
1375 |
'Processor [warning]: process with nil id removed' errorPrintCR. |
|
1376 |
l removeFirst. |
|
1377 |
^ nil. |
|
1378 |
]. |
|
1379 |
^ p |
|
1380 |
] |
|
1381 |
]. |
|
1382 |
prio := prio - 1 |
|
699 | 1383 |
]. |
1384 |
^ nil |
|
1086 | 1385 |
|
2385 | 1386 |
"Modified: 12.2.1997 / 12:41:49 / cg" |
699 | 1387 |
! |
1388 |
||
1177 | 1389 |
isPureEventDriven |
1390 |
"this is temporary - (maybe not :-). |
|
1391 |
you can run ST/X either with or without processes. |
|
1392 |
Without, there is conceptionally a single process handling all |
|
1393 |
outside events and timeouts. This has some negative implications |
|
1394 |
(Debugger is ugly), but allows a fully portable ST/X without any |
|
1395 |
assembler support - i.e. quick portability. |
|
1396 |
The PureEvent flag will automatically be set if the runtime system |
|
1397 |
does not support threads - otherwise, it can be set manually |
|
1398 |
(from rc-file). |
|
1399 |
" |
|
1400 |
||
1401 |
^ PureEventDriven |
|
1402 |
||
1403 |
"Created: 13.4.1996 / 20:31:31 / cg" |
|
1404 |
! |
|
1405 |
||
2191 | 1406 |
isTimeSlicing |
1407 |
"return true, if in timeslicing mode" |
|
1408 |
||
1409 |
^ timeSliceProcess notNil |
|
1410 |
||
1411 |
" |
|
1412 |
Processor isTimeSlicing |
|
1413 |
" |
|
1414 |
||
1415 |
"Modified: 17.1.1997 / 17:48:41 / cg" |
|
699 | 1416 |
! ! |
1417 |
||
1418 |
!ProcessorScheduler methodsFor:'scheduling'! |
|
1419 |
||
1420 |
changePriority:prio for:aProcess |
|
1421 |
"change the priority of aProcess" |
|
1422 |
||
1423 |
|oldList newList oldPrio newPrio wasBlocked| |
|
1424 |
||
1425 |
oldPrio := aProcess priority. |
|
1426 |
oldPrio == prio ifTrue:[^ self]. |
|
1042 | 1427 |
aProcess == scheduler ifTrue:[^ self]. |
699 | 1428 |
|
1429 |
" |
|
1430 |
check for valid argument |
|
1431 |
" |
|
1432 |
newPrio := prio. |
|
1433 |
newPrio < 1 ifTrue:[ |
|
2534 | 1434 |
newPrio := 1. |
699 | 1435 |
] ifFalse:[ |
2534 | 1436 |
newPrio > HighestPriority ifTrue:[ |
1437 |
newPrio := HighestPriority |
|
1438 |
] |
|
699 | 1439 |
]. |
1440 |
||
1042 | 1441 |
[ |
2534 | 1442 |
wasBlocked := OperatingSystem blockInterrupts. |
1443 |
||
1444 |
aProcess setPriority:newPrio. |
|
1445 |
||
1446 |
oldList := quiescentProcessLists at:oldPrio. |
|
1447 |
oldList notNil ifTrue:[ |
|
1448 |
(oldList remove:aProcess ifAbsent:nil) notNil ifTrue:[ |
|
1449 |
newList := quiescentProcessLists at:newPrio. |
|
1450 |
newList isNil ifTrue:[ |
|
1451 |
quiescentProcessLists at:newPrio put:(newList := LinkedList new). |
|
1452 |
]. |
|
1453 |
newList addLast:aProcess. |
|
1454 |
||
1455 |
"if its the current process lowering its prio |
|
1456 |
or another one raising, we have to reschedule" |
|
1457 |
||
1458 |
aProcess == activeProcess ifTrue:[ |
|
1459 |
currentPriority := newPrio. |
|
1460 |
newPrio < oldPrio ifTrue:[ |
|
1461 |
self threadSwitch:scheduler. |
|
1462 |
] |
|
1463 |
] ifFalse:[ |
|
1464 |
newPrio > currentPriority ifTrue:[ |
|
1465 |
self threadSwitch:aProcess. |
|
1466 |
] |
|
1467 |
]. |
|
1468 |
] |
|
1469 |
] |
|
1042 | 1470 |
] valueNowOrOnUnwindDo:[ |
2534 | 1471 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
1042 | 1472 |
] |
1032 | 1473 |
|
2468 | 1474 |
"Modified: 20.3.1997 / 16:02:00 / cg" |
699 | 1475 |
! |
1476 |
||
1477 |
interruptActive |
|
1783
be7402f74d94
hide timerInterrupt & ioInterrupt contexts when switching
Claus Gittinger <cg@exept.de>
parents:
1780
diff
changeset
|
1478 |
"interrupt the current process |
be7402f74d94
hide timerInterrupt & ioInterrupt contexts when switching
Claus Gittinger <cg@exept.de>
parents:
1780
diff
changeset
|
1479 |
- this message is sent by the VM, when a process is about to be switched to, |
be7402f74d94
hide timerInterrupt & ioInterrupt contexts when switching
Claus Gittinger <cg@exept.de>
parents:
1780
diff
changeset
|
1480 |
and that process has the interrupted flag bit set. |
be7402f74d94
hide timerInterrupt & ioInterrupt contexts when switching
Claus Gittinger <cg@exept.de>
parents:
1780
diff
changeset
|
1481 |
Pass the interrupt to the process, which may do whatever it likes with it." |
be7402f74d94
hide timerInterrupt & ioInterrupt contexts when switching
Claus Gittinger <cg@exept.de>
parents:
1780
diff
changeset
|
1482 |
|
1791 | 1483 |
|s| |
1484 |
||
1485 |
"/ hide those intermediate scheduler contexts; |
|
1486 |
"/ the interrupt block should think it was called right |
|
1487 |
"/ from the originally interrupted context |
|
1488 |
||
1489 |
s := thisContext sender. |
|
1490 |
s selector == #threadSwitch: ifTrue:[ |
|
2534 | 1491 |
s := s sender. |
1492 |
s selector == #timerInterrupt ifTrue:[ |
|
1493 |
s := s sender |
|
1494 |
] |
|
1791 | 1495 |
]. |
1496 |
||
2727 | 1497 |
"/ the returned value here has a subtle effect: |
1498 |
"/ if false, the interrupt is assumed to be not taken, |
|
1499 |
"/ and will be redelivered. |
|
1500 |
||
2724 | 1501 |
^ activeProcess interruptedIn:s |
1783
be7402f74d94
hide timerInterrupt & ioInterrupt contexts when switching
Claus Gittinger <cg@exept.de>
parents:
1780
diff
changeset
|
1502 |
|
1793 | 1503 |
"Modified: 20.10.1996 / 17:06:48 / cg" |
699 | 1504 |
! |
1505 |
||
3273
343ecdba9817
added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents:
3271
diff
changeset
|
1506 |
makeRunnable:aProcess |
343ecdba9817
added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents:
3271
diff
changeset
|
1507 |
"set aProcess runnable - but do not reschedule." |
343ecdba9817
added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents:
3271
diff
changeset
|
1508 |
|
343ecdba9817
added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents:
3271
diff
changeset
|
1509 |
|l pri wasBlocked| |
343ecdba9817
added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents:
3271
diff
changeset
|
1510 |
|
343ecdba9817
added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents:
3271
diff
changeset
|
1511 |
"ignore, if process is already dead" |
343ecdba9817
added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents:
3271
diff
changeset
|
1512 |
(aProcess isNil or:[aProcess id isNil]) ifTrue:[^ self]. |
343ecdba9817
added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents:
3271
diff
changeset
|
1513 |
|
343ecdba9817
added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents:
3271
diff
changeset
|
1514 |
|
343ecdba9817
added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents:
3271
diff
changeset
|
1515 |
aProcess == activeProcess ifTrue:[ |
343ecdba9817
added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents:
3271
diff
changeset
|
1516 |
"special handling for waiting schedulers" |
343ecdba9817
added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents:
3271
diff
changeset
|
1517 |
aProcess == scheduler ifTrue:[ |
343ecdba9817
added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents:
3271
diff
changeset
|
1518 |
suspendScheduler := false. |
343ecdba9817
added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents:
3271
diff
changeset
|
1519 |
]. |
343ecdba9817
added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents:
3271
diff
changeset
|
1520 |
^ self |
343ecdba9817
added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents:
3271
diff
changeset
|
1521 |
]. |
343ecdba9817
added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents:
3271
diff
changeset
|
1522 |
|
343ecdba9817
added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents:
3271
diff
changeset
|
1523 |
wasBlocked := OperatingSystem blockInterrupts. |
343ecdba9817
added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents:
3271
diff
changeset
|
1524 |
|
343ecdba9817
added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents:
3271
diff
changeset
|
1525 |
pri := aProcess priority. |
343ecdba9817
added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents:
3271
diff
changeset
|
1526 |
|
343ecdba9817
added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents:
3271
diff
changeset
|
1527 |
l := quiescentProcessLists at:pri. |
343ecdba9817
added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents:
3271
diff
changeset
|
1528 |
"if already running, ignore" |
343ecdba9817
added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents:
3271
diff
changeset
|
1529 |
l notNil ifTrue:[ |
343ecdba9817
added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents:
3271
diff
changeset
|
1530 |
(l identityIndexOf:aProcess) ~~ 0 ifTrue:[ |
343ecdba9817
added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents:
3271
diff
changeset
|
1531 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
343ecdba9817
added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents:
3271
diff
changeset
|
1532 |
^ self |
343ecdba9817
added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents:
3271
diff
changeset
|
1533 |
] |
343ecdba9817
added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents:
3271
diff
changeset
|
1534 |
] ifFalse:[ |
343ecdba9817
added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents:
3271
diff
changeset
|
1535 |
l := LinkedList new. |
343ecdba9817
added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents:
3271
diff
changeset
|
1536 |
quiescentProcessLists at:pri put:l. |
343ecdba9817
added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents:
3271
diff
changeset
|
1537 |
]. |
343ecdba9817
added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents:
3271
diff
changeset
|
1538 |
l addLast:aProcess. |
343ecdba9817
added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents:
3271
diff
changeset
|
1539 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
343ecdba9817
added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents:
3271
diff
changeset
|
1540 |
|
343ecdba9817
added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents:
3271
diff
changeset
|
1541 |
aProcess state:#run |
343ecdba9817
added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents:
3271
diff
changeset
|
1542 |
|
343ecdba9817
added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents:
3271
diff
changeset
|
1543 |
"Modified: / 29.7.1996 / 12:07:37 / cg" |
343ecdba9817
added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents:
3271
diff
changeset
|
1544 |
"Created: / 4.2.1998 / 20:58:28 / cg" |
343ecdba9817
added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents:
3271
diff
changeset
|
1545 |
! |
343ecdba9817
added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents:
3271
diff
changeset
|
1546 |
|
699 | 1547 |
processTermination |
1548 |
"sent by VM if the current process finished its startup block |
|
1549 |
without proper process termination. Lay him to rest now. |
|
1550 |
This can only happen, if something went wrong in Block>>newProcess, |
|
1551 |
since the block defined there always terminates itself." |
|
1552 |
||
1553 |
self terminateNoSignal:activeProcess. |
|
1554 |
self threadSwitch:scheduler |
|
1555 |
! |
|
1556 |
||
1557 |
reschedule |
|
1558 |
"switch to the highest prio runnable process. |
|
1559 |
The scheduler itself is always runnable, so we can do an unconditional switch |
|
2622 | 1560 |
to that one. This method is provided as a hook for primitive C code, |
1561 |
to allow giving up the CPU." |
|
699 | 1562 |
|
1563 |
^ self threadSwitch:scheduler |
|
1564 |
! |
|
1565 |
||
1566 |
resume:aProcess |
|
1567 |
"set aProcess runnable - |
|
1568 |
if its prio is higher than the currently running prio, switch to it." |
|
1569 |
||
1570 |
|l pri wasBlocked| |
|
1571 |
||
1679
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
1572 |
"ignore, if process is already dead" |
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
1573 |
(aProcess isNil or:[aProcess id isNil]) ifTrue:[^ self]. |
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
1574 |
|
699 | 1575 |
|
1679
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
1576 |
aProcess == activeProcess ifTrue:[ |
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
1577 |
"special handling for waiting schedulers" |
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
1578 |
aProcess == scheduler ifTrue:[ |
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
1579 |
suspendScheduler := false. |
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
1580 |
]. |
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
1581 |
^ self |
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
1582 |
]. |
699 | 1583 |
|
1584 |
wasBlocked := OperatingSystem blockInterrupts. |
|
1585 |
||
1586 |
pri := aProcess priority. |
|
1587 |
||
1588 |
l := quiescentProcessLists at:pri. |
|
1589 |
"if already running, ignore" |
|
1618 | 1590 |
l notNil ifTrue:[ |
1679
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
1591 |
(l identityIndexOf:aProcess) ~~ 0 ifTrue:[ |
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
1592 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
1593 |
^ self |
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
1594 |
] |
1618 | 1595 |
] ifFalse:[ |
1679
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
1596 |
l := LinkedList new. |
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
1597 |
quiescentProcessLists at:pri put:l. |
699 | 1598 |
]. |
1599 |
l addLast:aProcess. |
|
1600 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
1601 |
||
1602 |
(pri > currentPriority) ifTrue:[ |
|
1679
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
1603 |
" |
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
1604 |
its prio is higher; immediately transfer control to it |
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
1605 |
" |
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
1606 |
self threadSwitch:aProcess |
699 | 1607 |
] ifFalse:[ |
1679
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
1608 |
" |
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
1609 |
its prio is lower; it will have to wait for a while ... |
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
1610 |
" |
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
1611 |
aProcess state:#run |
699 | 1612 |
] |
1618 | 1613 |
|
1614 |
"Modified: 29.7.1996 / 12:07:37 / cg" |
|
699 | 1615 |
! |
1616 |
||
1617 |
resumeForSingleSend:aProcess |
|
1618 |
"like resume, but let the process execute a single send only. |
|
3271 | 1619 |
This will be used by the debugger for single stepping." |
699 | 1620 |
|
1621 |
(aProcess isNil or:[aProcess == activeProcess]) ifTrue:[^ self]. |
|
1622 |
aProcess singleStep:true. |
|
1623 |
self resume:aProcess |
|
3271 | 1624 |
|
1625 |
"Modified: / 3.2.1998 / 01:08:08 / stefan" |
|
699 | 1626 |
! |
1627 |
||
1628 |
suspend:aProcess |
|
1629 |
"remove the argument, aProcess from the list of runnable processes. |
|
752
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
750
diff
changeset
|
1630 |
If the process is the current one, reschedule. |
2155 | 1631 |
|
1632 |
Notice: |
|
2534 | 1633 |
This method should only be called by Process>>suspend or |
1634 |
Process>>suspendWithState:" |
|
699 | 1635 |
|
1636 |
|pri l p wasBlocked| |
|
1637 |
||
1638 |
" |
|
1639 |
some debugging stuff |
|
1640 |
" |
|
1641 |
aProcess isNil ifTrue:[ |
|
2534 | 1642 |
InvalidProcessSignal raiseWith:aProcess errorString:'PROCESSOR: nil suspend'. |
1643 |
^ self |
|
699 | 1644 |
]. |
1645 |
aProcess id isNil ifTrue:[ |
|
2534 | 1646 |
InvalidProcessSignal raiseWith:aProcess errorString:'PROCESSOR: bad suspend: already dead'. |
1647 |
self threadSwitch:scheduler. |
|
1648 |
^ self |
|
699 | 1649 |
]. |
1650 |
aProcess == scheduler ifTrue:[ |
|
2534 | 1651 |
"only scheduler may suspend itself" |
1652 |
activeProcess == scheduler ifTrue:[ |
|
1653 |
suspendScheduler := true. |
|
1654 |
[suspendScheduler] whileTrue:[ |
|
1655 |
self dispatch. |
|
1656 |
]. |
|
1657 |
^ self |
|
1658 |
]. |
|
1659 |
||
1660 |
InvalidProcessSignal raiseWith:aProcess errorString:'PROCESSOR: scheduler should never be suspended'. |
|
1661 |
^ self |
|
699 | 1662 |
]. |
1663 |
||
1664 |
wasBlocked := OperatingSystem blockInterrupts. |
|
1665 |
||
1666 |
pri := aProcess priority. |
|
1667 |
l := quiescentProcessLists at:pri. |
|
1668 |
||
1669 |
"notice: this is slightly faster than putting the if-code into |
|
752
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
750
diff
changeset
|
1670 |
the ifAbsent block, because [] is a shared cheap block, created at compile time |
699 | 1671 |
" |
1618 | 1672 |
(l isNil or:[(l remove:aProcess ifAbsent:[]) isNil]) ifTrue:[ |
2534 | 1673 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
1674 |
'Processor [warning]: bad suspend: not on run list' errorPrintCR. |
|
1675 |
"/ MiniDebugger enterWithMessage:'bad suspend: not on run list'. |
|
1676 |
self threadSwitch:scheduler. |
|
1677 |
^ self |
|
699 | 1678 |
]. |
1679 |
||
1680 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
1681 |
||
1682 |
(aProcess == activeProcess) ifTrue:[ |
|
2534 | 1683 |
"we can immediately switch sometimes" |
1684 |
l isEmpty ifFalse:[ |
|
1685 |
p := l first |
|
1686 |
] ifTrue:[ |
|
1687 |
p := scheduler |
|
1688 |
]. |
|
1689 |
self threadSwitch:p |
|
699 | 1690 |
]. |
752
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
750
diff
changeset
|
1691 |
|
1679
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
1692 |
"Modified: 23.9.1996 / 13:49:24 / stefan" |
2385 | 1693 |
"Modified: 12.2.1997 / 12:42:00 / cg" |
699 | 1694 |
! |
1695 |
||
1696 |
terminate:aProcess |
|
1697 |
"terminate aProcess. This is donen by sending aProcess the terminateSignal, |
|
1698 |
which will evaluate any unwind blocks and finally do a hard terminate." |
|
1699 |
||
1700 |
aProcess terminate |
|
1701 |
! |
|
1702 |
||
1703 |
terminateActive |
|
1704 |
"terminate the current process (i.e. the running process kills itself). |
|
1705 |
The active process is sent the terminateSignal so it will evaluate any |
|
1706 |
unwind blocks and finally do a hard terminate. |
|
1707 |
This is sent for regular termination and by the VM, if the hard-stack limit |
|
1708 |
is reached. (i.e. a process did not repair things in a recursionInterrupt and |
|
1709 |
continued to grow its stack)" |
|
1710 |
||
1711 |
activeProcess terminate |
|
1712 |
! |
|
1713 |
||
1714 |
terminateActiveNoSignal |
|
1715 |
"hard terminate the active process, without sending any |
|
1716 |
terminate signal thus no unwind blocks are evaluated." |
|
1717 |
||
1718 |
self terminateNoSignal:activeProcess |
|
1719 |
! |
|
1720 |
||
1721 |
terminateNoSignal:aProcess |
|
1722 |
"hard terminate aProcess without sending the terminate signal, thus |
|
1723 |
no unwind blocks or exitAction are performed in the process.. |
|
1724 |
If its not the current process, it is simply removed from its list |
|
1725 |
and physically destroyed. Otherwise (since we can't take away the chair |
|
1726 |
we are sitting on), a switch is forced and the process |
|
1727 |
will be physically destroyed by the next running process. |
|
1728 |
(see zombie handling)" |
|
1729 |
||
1730 |
|pri id l wasBlocked| |
|
1731 |
||
1732 |
aProcess isNil ifTrue:[^ self]. |
|
807
e51ce11ca948
and dont allow quickTerminate as well.
Claus Gittinger <cg@exept.de>
parents:
806
diff
changeset
|
1733 |
aProcess == scheduler ifTrue:[ |
2534 | 1734 |
InvalidProcessSignal raiseWith:aProcess errorString:'PROCESSOR: I will not terminate scheduler'. |
1735 |
^ self |
|
807
e51ce11ca948
and dont allow quickTerminate as well.
Claus Gittinger <cg@exept.de>
parents:
806
diff
changeset
|
1736 |
]. |
e51ce11ca948
and dont allow quickTerminate as well.
Claus Gittinger <cg@exept.de>
parents:
806
diff
changeset
|
1737 |
|
699 | 1738 |
id := aProcess id. |
1739 |
id isNil ifTrue:[^ self]. "already dead" |
|
1740 |
||
1741 |
aProcess setId:nil state:#dead. |
|
1742 |
||
1743 |
wasBlocked := OperatingSystem blockInterrupts. |
|
1744 |
||
1745 |
"remove the process from the runnable list" |
|
1746 |
||
1747 |
pri := aProcess priority. |
|
1748 |
l := quiescentProcessLists at:pri. |
|
2468 | 1749 |
(l remove:aProcess ifAbsent:nil) notNil ifTrue:[ |
2534 | 1750 |
l isEmpty ifTrue:[ |
1751 |
quiescentProcessLists at:pri put:nil |
|
1752 |
] |
|
699 | 1753 |
]. |
1754 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
1755 |
||
1756 |
aProcess == activeProcess ifTrue:[ |
|
2534 | 1757 |
" |
1758 |
hard case - its the currently running process |
|
1759 |
we must have the next active process destroy this one |
|
1760 |
(we cannot destroy the chair we are sitting on ... :-) |
|
1761 |
" |
|
1762 |
zombie := id. |
|
1763 |
self unRemember:aProcess. |
|
1764 |
self threadSwitch:scheduler. |
|
1765 |
"not reached" |
|
1766 |
^ self |
|
699 | 1767 |
]. |
1768 |
self class threadDestroy:id. |
|
1769 |
self unRemember:aProcess. |
|
1770 |
^ self |
|
1618 | 1771 |
|
1679
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
1772 |
"Modified: 23.9.1996 / 13:50:24 / stefan" |
2468 | 1773 |
"Modified: 20.3.1997 / 16:03:39 / cg" |
699 | 1774 |
! |
1775 |
||
1776 |
yield |
|
1777 |
"move the currently running process to the end of the currentList |
|
1778 |
and reschedule to the first in the list, thus switching to the |
|
1779 |
next same-prio-process." |
|
1780 |
||
1618 | 1781 |
|l sz wasBlocked| |
699 | 1782 |
|
1783 |
wasBlocked := OperatingSystem blockInterrupts. |
|
1784 |
||
1785 |
" |
|
1786 |
debugging consistency check - will be removed later |
|
1787 |
" |
|
1788 |
activeProcess priority ~~ currentPriority ifTrue:[ |
|
2534 | 1789 |
'Processor [warning]: process changed its priority' errorPrintCR. |
1790 |
currentPriority := activeProcess priority. |
|
699 | 1791 |
]. |
1792 |
||
1793 |
l := quiescentProcessLists at:currentPriority. |
|
1618 | 1794 |
sz := l size. |
699 | 1795 |
|
1796 |
" |
|
1797 |
debugging consistency checks - will be removed later |
|
1798 |
" |
|
1618 | 1799 |
sz == 0 ifTrue:[ |
2534 | 1800 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
1801 |
'Processor [warning]: empty runnable list' errorPrintCR. |
|
1802 |
^ self |
|
699 | 1803 |
]. |
1804 |
||
1805 |
" |
|
1806 |
check if the running process is not the only one |
|
1807 |
" |
|
1618 | 1808 |
sz ~~ 1 ifTrue:[ |
2534 | 1809 |
" |
1810 |
bring running process to the end |
|
1811 |
" |
|
1812 |
l removeFirst. |
|
1813 |
l addLast:activeProcess. |
|
1814 |
||
1815 |
" |
|
1816 |
and switch to first in the list |
|
1817 |
" |
|
1818 |
self threadSwitch:(l first). |
|
699 | 1819 |
]. |
1820 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
1086 | 1821 |
|
2129
e03cd7bc3475
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
2123
diff
changeset
|
1822 |
"Modified: 10.1.1997 / 18:04:35 / cg" |
699 | 1823 |
! ! |
1824 |
||
2188 | 1825 |
!ProcessorScheduler methodsFor:'scheduling - preemptive'! |
1826 |
||
1827 |
slice |
|
1828 |
"Give other Processes at the current priority a chance to run." |
|
1829 |
||
1830 |
|i "{ Class: SmallInteger }" |
|
1831 |
list| |
|
1832 |
||
2190 | 1833 |
i := TimeSlicingPriorityLimit. |
2333 | 1834 |
[(i > 0) and:[(list := quiescentProcessLists at:i) size <= 1]] whileTrue: [i := i - 1]. |
2188 | 1835 |
i == 0 ifTrue: [^ self]. |
1836 |
||
1837 |
"/ shuffle that list |
|
1838 |
list addLast:(list removeFirst). |
|
1839 |
||
2333 | 1840 |
"Modified: 30.1.1997 / 18:40:39 / cg" |
2188 | 1841 |
! |
1842 |
||
1843 |
startTimeSlicing |
|
2190 | 1844 |
"start preemptive scheduling (timeSlicing)" |
1845 |
||
1846 |
timeSliceProcess notNil ifTrue: [^ self]. |
|
1847 |
||
2188 | 1848 |
timeSliceProcess := [ |
2831
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
1849 |
[ |
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
1850 |
|myDelay t| |
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
1851 |
|
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
1852 |
myDelay := Delay forMilliseconds:(t := TimeSliceInterval). |
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
1853 |
|
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
1854 |
[true] whileTrue: [ |
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
1855 |
t ~~ TimeSliceInterval ifTrue:[ |
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
1856 |
"/ interval changed -> need a new delay |
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
1857 |
myDelay delay:(t := TimeSliceInterval). |
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
1858 |
]. |
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
1859 |
myDelay wait. |
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
1860 |
self slice |
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
1861 |
] |
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
1862 |
] valueOnUnwindDo:[ |
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
1863 |
timeSliceProcess := nil |
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
1864 |
] |
2188 | 1865 |
] newProcess. |
2190 | 1866 |
timeSliceProcess priority:HighestPriority. |
2188 | 1867 |
timeSliceProcess name:'time slicer'. |
2831
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
1868 |
timeSliceProcess restartable:true. |
2198
0537156f1fd7
make the timeSlicer a systemProcess
Claus Gittinger <cg@exept.de>
parents:
2193
diff
changeset
|
1869 |
timeSliceProcess beSystemProcess. |
2188 | 1870 |
timeSliceProcess resume. |
1871 |
||
1872 |
" |
|
2258 | 1873 |
Processor stopTimeSlicing. |
1874 |
Processor startTimeSlicing. |
|
2188 | 1875 |
" |
1876 |
||
1877 |
"Created: 17.1.1997 / 16:42:02 / cg" |
|
2831
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
1878 |
"Modified: 4.8.1997 / 15:10:44 / cg" |
2188 | 1879 |
! |
1880 |
||
1881 |
stopTimeSlicing |
|
2190 | 1882 |
"stop preemptive scheduling (timeSlicing)" |
2188 | 1883 |
|
1884 |
timeSliceProcess notNil ifTrue: [ |
|
2831
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
1885 |
timeSliceProcess terminate. |
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
1886 |
timeSliceProcess := nil. |
2188 | 1887 |
] |
1888 |
||
1889 |
" |
|
1890 |
Processor stopTimeSlicing |
|
1891 |
" |
|
1892 |
||
1893 |
"Created: 17.1.1997 / 16:43:03 / cg" |
|
2831
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
1894 |
"Modified: 4.8.1997 / 14:27:45 / cg" |
2188 | 1895 |
! ! |
1896 |
||
699 | 1897 |
!ProcessorScheduler methodsFor:'semaphore signalling'! |
1898 |
||
1899 |
disableSemaphore:aSemaphore |
|
1900 |
"disable triggering of a semaphore" |
|
1901 |
||
1902 |
|idx "{ Class: SmallInteger }" |
|
2831
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
1903 |
wasBlocked fd| |
699 | 1904 |
|
1905 |
wasBlocked := OperatingSystem blockInterrupts. |
|
1906 |
idx := readSemaphoreArray identityIndexOf:aSemaphore startingAt:1. |
|
1907 |
[idx ~~ 0] whileTrue:[ |
|
2831
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
1908 |
useIOInterrupts ifTrue:[ |
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
1909 |
fd := readFdArray at:idx. |
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
1910 |
fd notNil ifTrue:[ |
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
1911 |
OperatingSystem disableIOInterruptsOn:fd |
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
1912 |
]. |
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
1913 |
]. |
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
1914 |
readFdArray at:idx put:nil. |
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
1915 |
readSemaphoreArray at:idx put:nil. |
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
1916 |
readCheckArray at:idx put:nil. |
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
1917 |
idx := readSemaphoreArray identityIndexOf:aSemaphore startingAt:idx. |
699 | 1918 |
]. |
1919 |
idx := writeSemaphoreArray identityIndexOf:aSemaphore startingAt:1. |
|
1920 |
[idx ~~ 0] whileTrue:[ |
|
2831
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
1921 |
useIOInterrupts ifTrue:[ |
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
1922 |
fd := writeFdArray at:idx. |
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
1923 |
fd notNil ifTrue:[ |
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
1924 |
OperatingSystem disableIOInterruptsOn:fd |
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
1925 |
]. |
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
1926 |
]. |
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
1927 |
writeFdArray at:idx put:nil. |
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
1928 |
writeSemaphoreArray at:idx put:nil. |
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
1929 |
idx := writeSemaphoreArray identityIndexOf:aSemaphore startingAt:idx. |
699 | 1930 |
]. |
1931 |
idx := timeoutSemaphoreArray identityIndexOf:aSemaphore startingAt:1. |
|
1932 |
[idx ~~ 0] whileTrue:[ |
|
2831
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
1933 |
timeoutArray at:idx put:nil. |
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
1934 |
timeoutSemaphoreArray at:idx put:nil. |
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
1935 |
timeoutActionArray at:idx put:nil. |
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
1936 |
timeoutProcessArray at:idx put:nil. |
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
1937 |
idx := timeoutSemaphoreArray identityIndexOf:aSemaphore startingAt:idx. |
699 | 1938 |
]. |
1939 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
2831
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
1940 |
|
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
1941 |
"Modified: 4.8.1997 / 15:19:33 / cg" |
699 | 1942 |
! |
1943 |
||
1683 | 1944 |
signal:aSemaphore |
1945 |
"arrange for a semaphore to be triggered as soon as possible. |
|
1946 |
The actual signalling is performed slightly delayed, when the dispatcher |
|
2618 | 1947 |
looks for a process to resume the next time. I.e. here, the current |
1948 |
process continues to execute, even if the semaphore signalling would |
|
1949 |
make a higher prio process runnable. |
|
1950 |
This is provided as entry for primitive-code (external functions) |
|
1951 |
which want to signal a semaphore AND make certain that they do not get |
|
1952 |
suspended (i.e. it is called by __STX_SignalSemaphore()). |
|
1953 |
Normal smalltalk code should always send an appropriate message directly |
|
1954 |
to the semaphore (i.e. aSemaphore signal)." |
|
1683 | 1955 |
|
1956 |
|now wasBlocked| |
|
1957 |
||
1958 |
wasBlocked := OperatingSystem blockInterrupts. |
|
1959 |
now := OperatingSystem getMillisecondTime. |
|
1960 |
self signal:aSemaphore atMilliseconds:now. |
|
1961 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
1962 |
||
1963 |
"Created: 24.9.1996 / 10:18:45 / cg" |
|
1964 |
! |
|
1965 |
||
699 | 1966 |
signal:aSemaphore afterMilliseconds:millis |
1967 |
"arrange for a semaphore to be triggered after some milliseconds" |
|
1968 |
||
1969 |
|now then wasBlocked| |
|
1970 |
||
1971 |
wasBlocked := OperatingSystem blockInterrupts. |
|
1972 |
now := OperatingSystem getMillisecondTime. |
|
1973 |
then := OperatingSystem millisecondTimeAdd:now and:millis rounded. |
|
1974 |
self signal:aSemaphore atMilliseconds:then. |
|
1975 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
1976 |
! |
|
1977 |
||
1978 |
signal:aSemaphore afterSeconds:seconds |
|
1979 |
"arrange for a semaphore to be triggered after some seconds" |
|
1980 |
||
1981 |
self signal:aSemaphore afterMilliseconds:(seconds * 1000) |
|
1982 |
! |
|
1983 |
||
1984 |
signal:aSemaphore atMilliseconds:aMillisecondTime |
|
1985 |
"arrange for a semaphore to be triggered at a specific millisecond time. |
|
2618 | 1986 |
If there is already a pending trigger time installed for that semaphore, |
1987 |
the time of the pending trigger is changed." |
|
699 | 1988 |
|
1989 |
|index "{ Class: SmallInteger }" |
|
1990 |
wasBlocked| |
|
1991 |
||
1992 |
wasBlocked := OperatingSystem blockInterrupts. |
|
1993 |
index := timeoutSemaphoreArray identityIndexOf:aSemaphore startingAt:1. |
|
1994 |
index ~~ 0 ifTrue:[ |
|
1995 |
timeoutArray at:index put:aMillisecondTime |
|
1996 |
] ifFalse:[ |
|
1997 |
index := timeoutArray identityIndexOf:nil startingAt:1. |
|
1998 |
index ~~ 0 ifTrue:[ |
|
1999 |
timeoutSemaphoreArray at:index put:aSemaphore. |
|
2000 |
timeoutArray at:index put:aMillisecondTime. |
|
2001 |
timeoutActionArray at:index put:nil. |
|
2002 |
timeoutProcessArray at:index put:nil |
|
2003 |
] ifFalse:[ |
|
2004 |
timeoutSemaphoreArray := timeoutSemaphoreArray copyWith:aSemaphore. |
|
2005 |
timeoutArray := timeoutArray copyWith:aMillisecondTime. |
|
2006 |
timeoutActionArray := timeoutActionArray copyWith:nil. |
|
2007 |
timeoutProcessArray := timeoutProcessArray copyWith:nil |
|
2008 |
]. |
|
2009 |
]. |
|
2010 |
||
2011 |
anyTimeouts := true. |
|
2012 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
2013 |
! |
|
2014 |
||
2015 |
signal:aSemaphore onInput:aFileDescriptor |
|
2016 |
"arrange for a semaphore to be triggered when input on aFileDescriptor |
|
2622 | 2017 |
arrives. This will only happen, if the OS supports selecting on fileDescriptors." |
699 | 2018 |
|
2019 |
self signal:aSemaphore onInput:aFileDescriptor orCheck:nil |
|
2020 |
! |
|
2021 |
||
2022 |
signal:aSemaphore onInput:aFileDescriptor orCheck:aBlock |
|
2023 |
"arrange for a semaphore to be triggered when input on aFileDescriptor |
|
2618 | 2024 |
arrives OR checkblock evaluates to true. The checkBlock will be evaluated |
2025 |
by the scheduler from time to time (i.e. every few milliseconds). |
|
2026 |
(This is req'd for buffered input, where a select may not detect |
|
2027 |
data which has already been read into a buffer - as in Xlib. |
|
2028 |
Or on systems, where we cannot select on a displays eventQ, such as windows)" |
|
699 | 2029 |
|
2030 |
|idx "{ Class: SmallInteger }" |
|
3116 | 2031 |
fd wasBlocked| |
2032 |
||
2033 |
fd := aFileDescriptor. |
|
2034 |
fd < 0 ifTrue:[ |
|
2035 |
'Processor [warning]: invalid fd for IO signal' errorPrintCR. |
|
2036 |
fd := nil. |
|
1627
f95285226059
infoPrint for NT (no select)
Claus Gittinger <cg@exept.de>
parents:
1618
diff
changeset
|
2037 |
]. |
f95285226059
infoPrint for NT (no select)
Claus Gittinger <cg@exept.de>
parents:
1618
diff
changeset
|
2038 |
|
699 | 2039 |
wasBlocked := OperatingSystem blockInterrupts. |
3116 | 2040 |
|
2041 |
fd isNil ifTrue:[ |
|
2042 |
'Processor [info]: no fd to select on - polling with checkBlock' infoPrintCR. |
|
2043 |
(readCheckArray identityIndexOf:aBlock startingAt:1) == 0 ifTrue:[ |
|
2044 |
readFdArray := readFdArray copyWith:nil. |
|
2045 |
readSemaphoreArray := readSemaphoreArray copyWith:aSemaphore. |
|
2046 |
readCheckArray := readCheckArray copyWith:aBlock. |
|
2047 |
] |
|
2048 |
] ifFalse:[ |
|
2049 |
(readFdArray identityIndexOf:aFileDescriptor startingAt:1) == 0 ifTrue:[ |
|
2050 |
idx := readFdArray identityIndexOf:nil startingAt:1. |
|
2051 |
idx ~~ 0 ifTrue:[ |
|
2052 |
readFdArray at:idx put:aFileDescriptor. |
|
2053 |
readSemaphoreArray at:idx put:aSemaphore. |
|
2054 |
readCheckArray at:idx put:aBlock |
|
2055 |
] ifFalse:[ |
|
2056 |
readFdArray := readFdArray copyWith:aFileDescriptor. |
|
2057 |
readSemaphoreArray := readSemaphoreArray copyWith:aSemaphore. |
|
2058 |
readCheckArray := readCheckArray copyWith:aBlock. |
|
2059 |
]. |
|
2060 |
useIOInterrupts ifTrue:[ |
|
2061 |
OperatingSystem enableIOInterruptsOn:aFileDescriptor |
|
2062 |
]. |
|
2063 |
] |
|
699 | 2064 |
]. |
2065 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
2123 | 2066 |
|
2831
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
2067 |
"Modified: 4.8.1997 / 15:20:45 / cg" |
699 | 2068 |
! |
2069 |
||
2070 |
signal:aSemaphore onOutput:aFileDescriptor |
|
2071 |
"arrange for a semaphore to be triggered when output on aFileDescriptor |
|
2622 | 2072 |
is possible. (i.e. can be written without blocking). |
2073 |
This will only happen, if the OS supports selecting on fileDescriptors." |
|
699 | 2074 |
|
2075 |
|idx "{ Class: SmallInteger }" |
|
2076 |
wasBlocked| |
|
2077 |
||
2078 |
wasBlocked := OperatingSystem blockInterrupts. |
|
2079 |
(writeFdArray identityIndexOf:aFileDescriptor startingAt:1) == 0 ifTrue:[ |
|
2831
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
2080 |
idx := writeFdArray identityIndexOf:nil startingAt:1. |
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
2081 |
idx ~~ 0 ifTrue:[ |
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
2082 |
writeFdArray at:idx put:aFileDescriptor. |
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
2083 |
writeSemaphoreArray at:idx put:aSemaphore. |
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
2084 |
] ifFalse:[ |
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
2085 |
writeFdArray := writeFdArray copyWith:aFileDescriptor. |
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
2086 |
writeSemaphoreArray := writeSemaphoreArray copyWith:aSemaphore. |
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
2087 |
]. |
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
2088 |
useIOInterrupts ifTrue:[ |
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
2089 |
OperatingSystem enableIOInterruptsOn:aFileDescriptor |
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
2090 |
]. |
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
2091 |
|
699 | 2092 |
]. |
2093 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
2831
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
2094 |
|
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
2095 |
"Modified: 4.8.1997 / 15:21:49 / cg" |
699 | 2096 |
! ! |
2097 |
||
2098 |
!ProcessorScheduler methodsFor:'timeout handling'! |
|
2099 |
||
2100 |
addTimedBlock:aBlock afterMilliseconds:delta |
|
2101 |
"add the argument, aBlock to the list of time-scheduled-blocks; to be |
|
2102 |
evaluated after delta milliseconds. The process which installs this timed |
|
2103 |
block will be interrupted for execution of the block. |
|
2104 |
(if it is running, the interrupt will occur in whatever method it is |
|
2105 |
executing; if it is suspended, it will be resumed). |
|
2106 |
The block will be removed from the timed-block list after evaluation |
|
1676
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2107 |
(i.e. it will trigger only once). |
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2108 |
Returns an ID, which can be used in #removeTimeoutWidthID:" |
699 | 2109 |
|
2110 |
^ self addTimedBlock:aBlock for:activeProcess afterMilliseconds:delta |
|
1676
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2111 |
|
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2112 |
"Modified: 23.9.1996 / 14:33:59 / cg" |
699 | 2113 |
! |
2114 |
||
2115 |
addTimedBlock:aBlock afterSeconds:delta |
|
2116 |
"add the argument, aBlock to the list of time-scheduled-blocks. |
|
2117 |
to be evaluated after delta seconds. The process which installs this timed |
|
2118 |
block will be interrupted for execution of the block. |
|
2119 |
(if it is running, the interrupt will occur in whatever method it is |
|
2120 |
executing; if it is suspended, it will be resumed). |
|
2121 |
The block will be removed from the timed-block list after evaluation |
|
1676
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2122 |
(i.e. it will trigger only once). |
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2123 |
Returns an ID, which can be used in #removeTimeoutWidthID:" |
699 | 2124 |
|
1676
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2125 |
^ self addTimedBlock:aBlock for:activeProcess afterMilliseconds:(delta * 1000) rounded |
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2126 |
|
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2127 |
"Modified: 23.9.1996 / 14:34:04 / cg" |
699 | 2128 |
! |
2129 |
||
2130 |
addTimedBlock:aBlock atMilliseconds:aMillisecondTime |
|
2131 |
"add the argument, aBlock to the list of time-scheduled-blocks; to be |
|
2132 |
evaluated when the millisecondClock value passes aMillisecondTime. |
|
2133 |
The process which installs this timed block will be interrupted for |
|
2134 |
execution of the block. |
|
2135 |
(if it is running, the interrupt will occur in whatever method it is |
|
2136 |
executing; if it is suspended, it will be resumed). |
|
2137 |
The block will be removed from the timed-block list after evaluation |
|
1676
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2138 |
(i.e. it will trigger only once). |
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2139 |
Returns an ID, which can be used in #removeTimeoutWidthID:" |
699 | 2140 |
|
1676
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2141 |
^ self addTimedBlock:aBlock for:activeProcess atMilliseconds:aMillisecondTime |
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2142 |
|
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2143 |
"Modified: 23.9.1996 / 14:34:09 / cg" |
699 | 2144 |
! |
2145 |
||
2146 |
addTimedBlock:aBlock for:aProcess afterMilliseconds:delta |
|
2147 |
"add the argument, aBlock to the list of time-scheduled-blocks; to be |
|
2148 |
evaluated after delta milliseconds. The process specified by the argument, |
|
2149 |
aProcess will be interrupted for execution of the block. |
|
2150 |
(if it is running, the interrupt will occur in whatever method it is |
|
2151 |
executing; if it is suspended, it will be resumed). |
|
2152 |
If aProcess is nil, the block will be evaluated by the scheduler itself |
|
2153 |
(which is dangerous - the block should not raise any error conditions). |
|
2154 |
The block will be removed from the timed-block list after evaluation |
|
1676
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2155 |
(i.e. it will trigger only once). |
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2156 |
Returns an ID, which can be used in #removeTimeoutWidthID:" |
699 | 2157 |
|
1676
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2158 |
|now then wasBlocked id| |
699 | 2159 |
|
2160 |
wasBlocked := OperatingSystem blockInterrupts. |
|
2161 |
now := OperatingSystem getMillisecondTime. |
|
2162 |
then := OperatingSystem millisecondTimeAdd:now and:delta. |
|
1676
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2163 |
id := self addTimedBlock:aBlock for:aProcess atMilliseconds:then. |
699 | 2164 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
1676
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2165 |
^ id |
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2166 |
|
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2167 |
"Modified: 23.9.1996 / 14:34:13 / cg" |
699 | 2168 |
! |
2169 |
||
2170 |
addTimedBlock:aBlock for:aProcess afterSeconds:delta |
|
2171 |
"add the argument, aBlock to the list of time-scheduled-blocks. |
|
2172 |
to be evaluated after delta seconds. aProcess will be interrupted for |
|
2173 |
execution of the block. |
|
2174 |
(if it is running, the interrupt will occur in whatever method it is |
|
2175 |
executing; if it is suspended, it will be resumed). |
|
2176 |
If aProcess is nil, the block will be evaluated by the scheduler itself |
|
2177 |
(which is dangerous - the block should not raise any error conditions). |
|
2178 |
The block will be removed from the timed-block list after evaluation |
|
1676
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2179 |
(i.e. it will trigger only once). |
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2180 |
Returns an ID, which can be used in #removeTimeoutWidthID:" |
699 | 2181 |
|
1676
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2182 |
^ self addTimedBlock:aBlock for:aProcess afterMilliseconds:(delta * 1000) rounded |
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2183 |
|
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2184 |
"Modified: 23.9.1996 / 14:34:18 / cg" |
699 | 2185 |
! |
2186 |
||
2187 |
addTimedBlock:aBlock for:aProcess atMilliseconds:aMillisecondTime |
|
2188 |
"add the argument, aBlock to the list of time-scheduled-blocks; to be |
|
2189 |
evaluated by aProcess when the millisecondClock value passes |
|
2190 |
aMillisecondTime. |
|
2191 |
If that block is already in the timeout list, |
|
2192 |
its trigger-time is changed. |
|
2193 |
The process specified by the argument, aProcess will be interrupted |
|
2194 |
for execution of the block. |
|
2195 |
If aProcess is nil, the block will be evaluated by the scheduler itself |
|
2196 |
(which is dangerous - the block should not raise any error conditions). |
|
2197 |
If the process is active at trigger time, the interrupt will occur in |
|
2198 |
whatever method it is executing; if suspended at trigger time, it will be |
|
2199 |
resumed. |
|
2200 |
The block will be removed from the timed-block list after evaluation |
|
1676
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2201 |
(i.e. it will trigger only once). |
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2202 |
Returns an ID, which can be used in #removeTimeoutWidthID:" |
699 | 2203 |
|
2204 |
|index "{ Class: SmallInteger }" |
|
2205 |
wasBlocked| |
|
2206 |
||
2207 |
wasBlocked := OperatingSystem blockInterrupts. |
|
2208 |
index := timeoutActionArray identityIndexOf:aBlock startingAt:1. |
|
2209 |
index ~~ 0 ifTrue:[ |
|
2534 | 2210 |
timeoutArray at:index put:aMillisecondTime |
699 | 2211 |
] ifFalse:[ |
2534 | 2212 |
index := timeoutArray indexOf:nil. |
2213 |
index ~~ 0 ifTrue:[ |
|
2214 |
timeoutArray at:index put:aMillisecondTime. |
|
2215 |
timeoutActionArray at:index put:aBlock. |
|
2216 |
timeoutSemaphoreArray at:index put:nil. |
|
2217 |
timeoutProcessArray at:index put:aProcess |
|
2218 |
] ifFalse:[ |
|
2219 |
timeoutArray := timeoutArray copyWith:aMillisecondTime. |
|
2220 |
timeoutActionArray := timeoutActionArray copyWith:aBlock. |
|
2221 |
timeoutSemaphoreArray := timeoutSemaphoreArray copyWith:nil. |
|
2222 |
timeoutProcessArray := timeoutProcessArray copyWith:aProcess. |
|
2223 |
index := timeoutArray size. |
|
2224 |
]. |
|
699 | 2225 |
]. |
2226 |
||
2227 |
anyTimeouts := true. |
|
2228 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
1676
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2229 |
^ index |
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2230 |
|
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2231 |
"Modified: 23.9.1996 / 14:34:23 / cg" |
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2232 |
! |
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2233 |
|
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2234 |
addTimeoutFunctionCall:anExternalFunction for:aProcess afterMilliseconds:delta with:argument |
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2235 |
"prepare for an external function to be called with a single argument |
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2236 |
after some millisecond-Delay. |
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2237 |
If aProcess is nil, the block will be evaluated by the scheduler itself, |
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2238 |
otherwise, that process will be interrupted and the function is performed |
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2239 |
in this processes context. |
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2240 |
The callBack will be removed from the timed-block list after evaluation |
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2241 |
(i.e. it will trigger only once). |
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2242 |
Returns an ID, which can be used in #removeTimeoutWidthID:" |
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2243 |
|
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2244 |
|now then wasBlocked id| |
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2245 |
|
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2246 |
wasBlocked := OperatingSystem blockInterrupts. |
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2247 |
now := OperatingSystem getMillisecondTime. |
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2248 |
then := OperatingSystem millisecondTimeAdd:now and:delta. |
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2249 |
|
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2250 |
id := self |
2534 | 2251 |
addTimeoutFunctionCall:anExternalFunction |
2252 |
for:aProcess |
|
2253 |
atMilliseconds:then |
|
2254 |
with:argument. |
|
1676
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2255 |
|
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2256 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2257 |
^ id |
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2258 |
|
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2259 |
"Created: 23.9.1996 / 14:28:27 / cg" |
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2260 |
"Modified: 23.9.1996 / 14:34:42 / cg" |
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2261 |
! |
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2262 |
|
1681 | 2263 |
addTimeoutFunctionCall:anExternalFunction for:aProcess atMilliseconds:milliTime with:argument |
1676
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2264 |
"prepare for an external function to be called with a single argument |
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2265 |
at some millisecond-time. |
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2266 |
If aProcess is nil, the block will be evaluated by the scheduler itself, |
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2267 |
otherwise, that process will be interrupted and the function is performed |
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2268 |
in this processes context. |
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2269 |
The callBack will be removed from the timed-block list after evaluation |
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2270 |
(i.e. it will trigger only once). |
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2271 |
Returns an ID, which can be used in #removeTimeoutWidthID:" |
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2272 |
|
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2273 |
|action| |
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2274 |
|
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2275 |
action := [anExternalFunction callWith:argument]. |
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2276 |
^ self |
2534 | 2277 |
addTimedBlock:action |
2278 |
for:aProcess |
|
2279 |
atMilliseconds:milliTime. |
|
1676
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2280 |
|
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2281 |
"Created: 23.9.1996 / 14:29:30 / cg" |
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2282 |
"Modified: 23.9.1996 / 14:34:57 / cg" |
699 | 2283 |
! |
2284 |
||
2285 |
evaluateTimeouts |
|
2286 |
"walk through timeouts and evaluate blocks or signal semas that need to be .." |
|
2287 |
||
2288 |
|sema now aTime block blocksToEvaluate |
|
2289 |
processes n "{ Class: SmallInteger }"| |
|
2290 |
||
2291 |
anyTimeouts ifFalse:[ ^ self]. |
|
2292 |
||
2293 |
"have to collect the blocks first, then evaluate them. This avoids |
|
2294 |
problems due to newly inserted blocks." |
|
2295 |
||
2296 |
now := OperatingSystem getMillisecondTime. |
|
2297 |
blocksToEvaluate := nil. |
|
2298 |
n := timeoutArray size. |
|
2299 |
anyTimeouts := false. |
|
2300 |
1 to:n do:[:index | |
|
3245
863c0a09f5a2
issue a warning if a timedBlock is to be evaluated for a dead thread
Claus Gittinger <cg@exept.de>
parents:
3116
diff
changeset
|
2301 |
aTime := timeoutArray at:index. |
863c0a09f5a2
issue a warning if a timedBlock is to be evaluated for a dead thread
Claus Gittinger <cg@exept.de>
parents:
3116
diff
changeset
|
2302 |
aTime notNil ifTrue:[ |
863c0a09f5a2
issue a warning if a timedBlock is to be evaluated for a dead thread
Claus Gittinger <cg@exept.de>
parents:
3116
diff
changeset
|
2303 |
(OperatingSystem millisecondTime:aTime isAfter:now) ifFalse:[ |
863c0a09f5a2
issue a warning if a timedBlock is to be evaluated for a dead thread
Claus Gittinger <cg@exept.de>
parents:
3116
diff
changeset
|
2304 |
"this one should be triggered" |
863c0a09f5a2
issue a warning if a timedBlock is to be evaluated for a dead thread
Claus Gittinger <cg@exept.de>
parents:
3116
diff
changeset
|
2305 |
|
863c0a09f5a2
issue a warning if a timedBlock is to be evaluated for a dead thread
Claus Gittinger <cg@exept.de>
parents:
3116
diff
changeset
|
2306 |
sema := timeoutSemaphoreArray at:index. |
863c0a09f5a2
issue a warning if a timedBlock is to be evaluated for a dead thread
Claus Gittinger <cg@exept.de>
parents:
3116
diff
changeset
|
2307 |
sema notNil ifTrue:[ |
863c0a09f5a2
issue a warning if a timedBlock is to be evaluated for a dead thread
Claus Gittinger <cg@exept.de>
parents:
3116
diff
changeset
|
2308 |
sema signalOnce. |
863c0a09f5a2
issue a warning if a timedBlock is to be evaluated for a dead thread
Claus Gittinger <cg@exept.de>
parents:
3116
diff
changeset
|
2309 |
timeoutSemaphoreArray at:index put:nil |
863c0a09f5a2
issue a warning if a timedBlock is to be evaluated for a dead thread
Claus Gittinger <cg@exept.de>
parents:
3116
diff
changeset
|
2310 |
] ifFalse:[ |
863c0a09f5a2
issue a warning if a timedBlock is to be evaluated for a dead thread
Claus Gittinger <cg@exept.de>
parents:
3116
diff
changeset
|
2311 |
"to support pure-events" |
863c0a09f5a2
issue a warning if a timedBlock is to be evaluated for a dead thread
Claus Gittinger <cg@exept.de>
parents:
3116
diff
changeset
|
2312 |
block := timeoutActionArray at:index. |
863c0a09f5a2
issue a warning if a timedBlock is to be evaluated for a dead thread
Claus Gittinger <cg@exept.de>
parents:
3116
diff
changeset
|
2313 |
block notNil ifTrue:[ |
863c0a09f5a2
issue a warning if a timedBlock is to be evaluated for a dead thread
Claus Gittinger <cg@exept.de>
parents:
3116
diff
changeset
|
2314 |
blocksToEvaluate isNil ifTrue:[ |
863c0a09f5a2
issue a warning if a timedBlock is to be evaluated for a dead thread
Claus Gittinger <cg@exept.de>
parents:
3116
diff
changeset
|
2315 |
blocksToEvaluate := OrderedCollection new:10. |
863c0a09f5a2
issue a warning if a timedBlock is to be evaluated for a dead thread
Claus Gittinger <cg@exept.de>
parents:
3116
diff
changeset
|
2316 |
processes := OrderedCollection new:10. |
863c0a09f5a2
issue a warning if a timedBlock is to be evaluated for a dead thread
Claus Gittinger <cg@exept.de>
parents:
3116
diff
changeset
|
2317 |
]. |
863c0a09f5a2
issue a warning if a timedBlock is to be evaluated for a dead thread
Claus Gittinger <cg@exept.de>
parents:
3116
diff
changeset
|
2318 |
blocksToEvaluate add:block. |
863c0a09f5a2
issue a warning if a timedBlock is to be evaluated for a dead thread
Claus Gittinger <cg@exept.de>
parents:
3116
diff
changeset
|
2319 |
processes add:(timeoutProcessArray at:index). |
863c0a09f5a2
issue a warning if a timedBlock is to be evaluated for a dead thread
Claus Gittinger <cg@exept.de>
parents:
3116
diff
changeset
|
2320 |
timeoutActionArray at:index put:nil. |
863c0a09f5a2
issue a warning if a timedBlock is to be evaluated for a dead thread
Claus Gittinger <cg@exept.de>
parents:
3116
diff
changeset
|
2321 |
timeoutProcessArray at:index put:nil. |
863c0a09f5a2
issue a warning if a timedBlock is to be evaluated for a dead thread
Claus Gittinger <cg@exept.de>
parents:
3116
diff
changeset
|
2322 |
] |
863c0a09f5a2
issue a warning if a timedBlock is to be evaluated for a dead thread
Claus Gittinger <cg@exept.de>
parents:
3116
diff
changeset
|
2323 |
]. |
863c0a09f5a2
issue a warning if a timedBlock is to be evaluated for a dead thread
Claus Gittinger <cg@exept.de>
parents:
3116
diff
changeset
|
2324 |
timeoutArray at:index put:nil. |
863c0a09f5a2
issue a warning if a timedBlock is to be evaluated for a dead thread
Claus Gittinger <cg@exept.de>
parents:
3116
diff
changeset
|
2325 |
] ifTrue:[ |
863c0a09f5a2
issue a warning if a timedBlock is to be evaluated for a dead thread
Claus Gittinger <cg@exept.de>
parents:
3116
diff
changeset
|
2326 |
anyTimeouts := true |
863c0a09f5a2
issue a warning if a timedBlock is to be evaluated for a dead thread
Claus Gittinger <cg@exept.de>
parents:
3116
diff
changeset
|
2327 |
] |
863c0a09f5a2
issue a warning if a timedBlock is to be evaluated for a dead thread
Claus Gittinger <cg@exept.de>
parents:
3116
diff
changeset
|
2328 |
] |
699 | 2329 |
]. |
2330 |
||
2331 |
blocksToEvaluate notNil ifTrue:[ |
|
3245
863c0a09f5a2
issue a warning if a timedBlock is to be evaluated for a dead thread
Claus Gittinger <cg@exept.de>
parents:
3116
diff
changeset
|
2332 |
blocksToEvaluate keysAndValuesDo:[:index :block | |
863c0a09f5a2
issue a warning if a timedBlock is to be evaluated for a dead thread
Claus Gittinger <cg@exept.de>
parents:
3116
diff
changeset
|
2333 |
|p| |
863c0a09f5a2
issue a warning if a timedBlock is to be evaluated for a dead thread
Claus Gittinger <cg@exept.de>
parents:
3116
diff
changeset
|
2334 |
|
863c0a09f5a2
issue a warning if a timedBlock is to be evaluated for a dead thread
Claus Gittinger <cg@exept.de>
parents:
3116
diff
changeset
|
2335 |
p := processes at:index. |
863c0a09f5a2
issue a warning if a timedBlock is to be evaluated for a dead thread
Claus Gittinger <cg@exept.de>
parents:
3116
diff
changeset
|
2336 |
(p isNil or:[p == scheduler or:[PureEventDriven]]) ifTrue:[ |
863c0a09f5a2
issue a warning if a timedBlock is to be evaluated for a dead thread
Claus Gittinger <cg@exept.de>
parents:
3116
diff
changeset
|
2337 |
block value |
863c0a09f5a2
issue a warning if a timedBlock is to be evaluated for a dead thread
Claus Gittinger <cg@exept.de>
parents:
3116
diff
changeset
|
2338 |
] ifFalse:[ |
863c0a09f5a2
issue a warning if a timedBlock is to be evaluated for a dead thread
Claus Gittinger <cg@exept.de>
parents:
3116
diff
changeset
|
2339 |
p isDead ifTrue:[ |
3246 | 2340 |
|
2341 |
"/ a timedBlock for a process which has already terminated |
|
2342 |
"/ issue a warning and do not execute it. |
|
2343 |
"/ (exeuting here may be dangerous, since it would run at scheduler priority here, |
|
2344 |
"/ and thereby could block the whole smalltalk system. |
|
2345 |
"/ For this reason is it IGNORED here.) |
|
2346 |
||
3245
863c0a09f5a2
issue a warning if a timedBlock is to be evaluated for a dead thread
Claus Gittinger <cg@exept.de>
parents:
3116
diff
changeset
|
2347 |
('ProcessorScheduler [warning]: cannot evaluate timedBlock for dead process: ''' , p name , '''') infoPrintCR. |
863c0a09f5a2
issue a warning if a timedBlock is to be evaluated for a dead thread
Claus Gittinger <cg@exept.de>
parents:
3116
diff
changeset
|
2348 |
('ProcessorScheduler [warning]: the timedBlock is: ' , block displayString) infoPrintCR. |
863c0a09f5a2
issue a warning if a timedBlock is to be evaluated for a dead thread
Claus Gittinger <cg@exept.de>
parents:
3116
diff
changeset
|
2349 |
] ifFalse:[ |
863c0a09f5a2
issue a warning if a timedBlock is to be evaluated for a dead thread
Claus Gittinger <cg@exept.de>
parents:
3116
diff
changeset
|
2350 |
p interruptWith:block |
863c0a09f5a2
issue a warning if a timedBlock is to be evaluated for a dead thread
Claus Gittinger <cg@exept.de>
parents:
3116
diff
changeset
|
2351 |
] |
863c0a09f5a2
issue a warning if a timedBlock is to be evaluated for a dead thread
Claus Gittinger <cg@exept.de>
parents:
3116
diff
changeset
|
2352 |
] |
863c0a09f5a2
issue a warning if a timedBlock is to be evaluated for a dead thread
Claus Gittinger <cg@exept.de>
parents:
3116
diff
changeset
|
2353 |
] |
699 | 2354 |
] |
3245
863c0a09f5a2
issue a warning if a timedBlock is to be evaluated for a dead thread
Claus Gittinger <cg@exept.de>
parents:
3116
diff
changeset
|
2355 |
|
3246 | 2356 |
"Modified: / 29.1.1998 / 17:05:03 / cg" |
699 | 2357 |
! |
2358 |
||
2359 |
removeTimedBlock:aBlock |
|
2360 |
"remove the argument, aBlock from the list of time-sceduled-blocks." |
|
2361 |
||
2362 |
|index "{ Class: SmallInteger }" |
|
2363 |
wasBlocked| |
|
2364 |
||
2365 |
wasBlocked := OperatingSystem blockInterrupts. |
|
2366 |
index := timeoutActionArray identityIndexOf:aBlock startingAt:1. |
|
2367 |
(index ~~ 0) ifTrue:[ |
|
2368 |
timeoutArray at:index put:nil. |
|
2369 |
timeoutActionArray at:index put:nil. |
|
2370 |
timeoutSemaphoreArray at:index put:nil. |
|
2371 |
timeoutProcessArray at:index put:nil. |
|
2372 |
]. |
|
2373 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
1676
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2374 |
! |
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2375 |
|
1680 | 2376 |
removeTimeoutWithID:anID |
1676
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2377 |
"remove the timeOut with anID (as returned by #addTimedBlock) |
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2378 |
from the list of time-sceduled-blocks." |
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2379 |
|
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2380 |
|index "{ Class: SmallInteger }" |
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2381 |
wasBlocked| |
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2382 |
|
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2383 |
index := anID. |
1680 | 2384 |
(index > 0) ifTrue:[ |
2534 | 2385 |
wasBlocked := OperatingSystem blockInterrupts. |
2386 |
||
2387 |
timeoutArray at:index put:nil. |
|
2388 |
timeoutActionArray at:index put:nil. |
|
2389 |
timeoutSemaphoreArray at:index put:nil. |
|
2390 |
timeoutProcessArray at:index put:nil. |
|
2391 |
||
2392 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
1680 | 2393 |
] |
1676
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2394 |
|
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2395 |
"Created: 23.9.1996 / 14:32:33 / cg" |
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2396 |
"Modified: 23.9.1996 / 14:35:09 / cg" |
10 | 2397 |
! ! |
1 | 2398 |
|
10 | 2399 |
!ProcessorScheduler methodsFor:'waiting'! |
2400 |
||
699 | 2401 |
checkForInputWithTimeout:millis |
2402 |
"this is called, when there is absolutely nothing to do; |
|
2403 |
hard wait for either input to arrive or a timeout to occur." |
|
2404 |
||
2830 | 2405 |
|fd index sema action wasBlocked err| |
2116
1bcb6ee86fca
fixed pending sigChild problem;
Claus Gittinger <cg@exept.de>
parents:
2111
diff
changeset
|
2406 |
|
1bcb6ee86fca
fixed pending sigChild problem;
Claus Gittinger <cg@exept.de>
parents:
2111
diff
changeset
|
2407 |
"/ must enable interrupts, to be able to get out of a |
1bcb6ee86fca
fixed pending sigChild problem;
Claus Gittinger <cg@exept.de>
parents:
2111
diff
changeset
|
2408 |
"/ long wait (especially, to handle sigChild in the meantime) |
1bcb6ee86fca
fixed pending sigChild problem;
Claus Gittinger <cg@exept.de>
parents:
2111
diff
changeset
|
2409 |
|
1bcb6ee86fca
fixed pending sigChild problem;
Claus Gittinger <cg@exept.de>
parents:
2111
diff
changeset
|
2410 |
(wasBlocked := OperatingSystem interruptsBlocked) ifTrue:[ |
1bcb6ee86fca
fixed pending sigChild problem;
Claus Gittinger <cg@exept.de>
parents:
2111
diff
changeset
|
2411 |
OperatingSystem unblockInterrupts. |
1bcb6ee86fca
fixed pending sigChild problem;
Claus Gittinger <cg@exept.de>
parents:
2111
diff
changeset
|
2412 |
]. |
699 | 2413 |
|
2414 |
fd := OperatingSystem |
|
1679
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
2415 |
selectOnAnyReadable:readFdArray |
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
2416 |
writable:writeFdArray |
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
2417 |
exception:nil |
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
2418 |
withTimeOut:millis. |
1061
61012b7bed9c
protect myself against invalid fd's in readFdArray/writeFdArray
Claus Gittinger <cg@exept.de>
parents:
1042
diff
changeset
|
2419 |
|
2116
1bcb6ee86fca
fixed pending sigChild problem;
Claus Gittinger <cg@exept.de>
parents:
2111
diff
changeset
|
2420 |
wasBlocked ifTrue:[ |
1bcb6ee86fca
fixed pending sigChild problem;
Claus Gittinger <cg@exept.de>
parents:
2111
diff
changeset
|
2421 |
OperatingSystem blockInterrupts. |
1bcb6ee86fca
fixed pending sigChild problem;
Claus Gittinger <cg@exept.de>
parents:
2111
diff
changeset
|
2422 |
]. |
1bcb6ee86fca
fixed pending sigChild problem;
Claus Gittinger <cg@exept.de>
parents:
2111
diff
changeset
|
2423 |
|
1061
61012b7bed9c
protect myself against invalid fd's in readFdArray/writeFdArray
Claus Gittinger <cg@exept.de>
parents:
1042
diff
changeset
|
2424 |
fd isNil ifTrue:[ |
3116 | 2425 |
"/ either still nothing to do, |
2426 |
"/ or error (which should not happen) |
|
2427 |
||
2830 | 2428 |
(err := OperatingSystem lastErrorSymbol) notNil ifTrue:[ |
2429 |
err == #EBADF ifTrue:[ |
|
2430 |
||
2431 |
"/ mhmh - one of the fd's given to me is corrupt. |
|
2432 |
"/ find out which one .... and remove it |
|
2433 |
||
3116 | 2434 |
'Processor [warning]: bad FD in select - clearing' infoPrintCR. |
2830 | 2435 |
OperatingSystem clearLastErrorNumber. |
2436 |
self removeCorruptedFds |
|
2437 |
] ifFalse:[ |
|
3116 | 2438 |
err == #ENOENT ifTrue:[ |
2439 |
'Processor ENOENT in select; rd=' infoPrint. |
|
2440 |
readFdArray infoPrint. |
|
2441 |
' wr=' infoPrint. |
|
2442 |
writeFdArray infoPrintCR. |
|
2443 |
] ifFalse:[ |
|
2444 |
'Processor [warning]: error in select: ' infoPrint. err infoPrintCR. |
|
2445 |
] |
|
2830 | 2446 |
]. |
2447 |
] |
|
1061
61012b7bed9c
protect myself against invalid fd's in readFdArray/writeFdArray
Claus Gittinger <cg@exept.de>
parents:
1042
diff
changeset
|
2448 |
] ifFalse:[ |
1679
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
2449 |
index := readFdArray indexOf:fd. |
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
2450 |
index ~~ 0 ifTrue:[ |
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
2451 |
sema := readSemaphoreArray at:index. |
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
2452 |
sema notNil ifTrue:[ |
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
2453 |
sema signalOnce. |
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
2454 |
^ true |
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
2455 |
] ifFalse:[ |
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
2456 |
action := readCheckArray at:index. |
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
2457 |
action notNil ifTrue:[ |
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
2458 |
action value. |
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
2459 |
^ true |
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
2460 |
] |
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
2461 |
] |
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
2462 |
] |
699 | 2463 |
]. |
2464 |
^ false |
|
1154
96bb8fce61cf
Fix removeCorruptedFds to clear LastErrorNumber. Handle ChildSignalInterrupts in Scheduler's context, to avoid errno corruption.
Stefan Vogel <sv@exept.de>
parents:
1133
diff
changeset
|
2465 |
|
96bb8fce61cf
Fix removeCorruptedFds to clear LastErrorNumber. Handle ChildSignalInterrupts in Scheduler's context, to avoid errno corruption.
Stefan Vogel <sv@exept.de>
parents:
1133
diff
changeset
|
2466 |
"Modified: 12.4.1996 / 09:31:22 / stefan" |
699 | 2467 |
! |
2468 |
||
10 | 2469 |
ioInterrupt |
1787
32632b6f969d
remember threadSwitch:from: idea for later implementation;
Claus Gittinger <cg@exept.de>
parents:
1783
diff
changeset
|
2470 |
"{ Pragma: +returnable }" |
32632b6f969d
remember threadSwitch:from: idea for later implementation;
Claus Gittinger <cg@exept.de>
parents:
1783
diff
changeset
|
2471 |
|
159 | 2472 |
"data arrived while waiting - switch to scheduler process which will decide |
1783
be7402f74d94
hide timerInterrupt & ioInterrupt contexts when switching
Claus Gittinger <cg@exept.de>
parents:
1780
diff
changeset
|
2473 |
what to do now. |
be7402f74d94
hide timerInterrupt & ioInterrupt contexts when switching
Claus Gittinger <cg@exept.de>
parents:
1780
diff
changeset
|
2474 |
This method is called by the VM' interrupt handling mechanism. |
be7402f74d94
hide timerInterrupt & ioInterrupt contexts when switching
Claus Gittinger <cg@exept.de>
parents:
1780
diff
changeset
|
2475 |
Notice, that at the time of the message, we are still in the context |
be7402f74d94
hide timerInterrupt & ioInterrupt contexts when switching
Claus Gittinger <cg@exept.de>
parents:
1780
diff
changeset
|
2476 |
of whichever process is currently running." |
10 | 2477 |
|
804
264d440a67a0
Fixes when useIOInterrupts == true.
Stefan Vogel <sv@exept.de>
parents:
786
diff
changeset
|
2478 |
gotIOInterrupt := true. |
2966 | 2479 |
activeProcess ~~ scheduler ifTrue:[ |
2480 |
interruptedProcess := activeProcess. |
|
2481 |
self threadSwitch:scheduler |
|
2482 |
] |
|
804
264d440a67a0
Fixes when useIOInterrupts == true.
Stefan Vogel <sv@exept.de>
parents:
786
diff
changeset
|
2483 |
|
264d440a67a0
Fixes when useIOInterrupts == true.
Stefan Vogel <sv@exept.de>
parents:
786
diff
changeset
|
2484 |
"Modified: 21.12.1995 / 16:17:40 / stefan" |
2831
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
2485 |
"Modified: 4.8.1997 / 14:23:08 / cg" |
10 | 2486 |
! |
2487 |
||
1086 | 2488 |
removeCorruptedFds |
2489 |
"this is sent when select returns an error due to some invalid |
|
1606 | 2490 |
fileDescriptor. May happen, if someone does a readWait/writeWait on a |
2491 |
socket connection, which somehow got corrupted |
|
2280 | 2492 |
(shutdown by partner, or closed by another thread, while being in a read/write-wait). |
1086 | 2493 |
Without special care, all following selects would immediately return with |
2494 |
an #EBADF error, leading to high-frequency polling and a locked up system. |
|
2495 |
(you could still fix things by interrupting on the console and fixing the |
|
2496 |
readFdArray/writeFdArray in the debugger)" |
|
2497 |
||
2498 |
readFdArray keysAndValuesDo:[:idx :fd | |
|
2534 | 2499 |
|rslt sema| |
2500 |
||
2625
b15e9a29764c
allow readCheckFd to be given as -1; ignore those.
Claus Gittinger <cg@exept.de>
parents:
2622
diff
changeset
|
2501 |
(fd notNil and:[fd >= 0]) ifTrue:[ |
b15e9a29764c
allow readCheckFd to be given as -1; ignore those.
Claus Gittinger <cg@exept.de>
parents:
2622
diff
changeset
|
2502 |
rslt := OperatingSystem |
b15e9a29764c
allow readCheckFd to be given as -1; ignore those.
Claus Gittinger <cg@exept.de>
parents:
2622
diff
changeset
|
2503 |
selectOnAnyReadable:(Array with:fd) |
b15e9a29764c
allow readCheckFd to be given as -1; ignore those.
Claus Gittinger <cg@exept.de>
parents:
2622
diff
changeset
|
2504 |
writable:nil |
b15e9a29764c
allow readCheckFd to be given as -1; ignore those.
Claus Gittinger <cg@exept.de>
parents:
2622
diff
changeset
|
2505 |
exception:nil |
b15e9a29764c
allow readCheckFd to be given as -1; ignore those.
Claus Gittinger <cg@exept.de>
parents:
2622
diff
changeset
|
2506 |
withTimeOut:0. |
b15e9a29764c
allow readCheckFd to be given as -1; ignore those.
Claus Gittinger <cg@exept.de>
parents:
2622
diff
changeset
|
2507 |
|
b15e9a29764c
allow readCheckFd to be given as -1; ignore those.
Claus Gittinger <cg@exept.de>
parents:
2622
diff
changeset
|
2508 |
(rslt isNil and:[OperatingSystem lastErrorSymbol == #EBADF]) ifTrue:[ |
b15e9a29764c
allow readCheckFd to be given as -1; ignore those.
Claus Gittinger <cg@exept.de>
parents:
2622
diff
changeset
|
2509 |
('Processor [info]: removing invalid read-select fileDescriptor: ' , fd printString) errorPrintCR. |
b15e9a29764c
allow readCheckFd to be given as -1; ignore those.
Claus Gittinger <cg@exept.de>
parents:
2622
diff
changeset
|
2510 |
readFdArray at:idx put:nil. |
b15e9a29764c
allow readCheckFd to be given as -1; ignore those.
Claus Gittinger <cg@exept.de>
parents:
2622
diff
changeset
|
2511 |
OperatingSystem clearLastErrorNumber. |
b15e9a29764c
allow readCheckFd to be given as -1; ignore those.
Claus Gittinger <cg@exept.de>
parents:
2622
diff
changeset
|
2512 |
(sema := readSemaphoreArray at:idx) notNil ifTrue:[ |
b15e9a29764c
allow readCheckFd to be given as -1; ignore those.
Claus Gittinger <cg@exept.de>
parents:
2622
diff
changeset
|
2513 |
readSemaphoreArray at:idx put:nil. |
b15e9a29764c
allow readCheckFd to be given as -1; ignore those.
Claus Gittinger <cg@exept.de>
parents:
2622
diff
changeset
|
2514 |
sema signal. |
b15e9a29764c
allow readCheckFd to be given as -1; ignore those.
Claus Gittinger <cg@exept.de>
parents:
2622
diff
changeset
|
2515 |
]. |
b15e9a29764c
allow readCheckFd to be given as -1; ignore those.
Claus Gittinger <cg@exept.de>
parents:
2622
diff
changeset
|
2516 |
] |
b15e9a29764c
allow readCheckFd to be given as -1; ignore those.
Claus Gittinger <cg@exept.de>
parents:
2622
diff
changeset
|
2517 |
]. |
1086 | 2518 |
]. |
2519 |
||
2520 |
writeFdArray keysAndValuesDo:[:idx :fd | |
|
2534 | 2521 |
|rslt sema| |
2522 |
||
2523 |
rslt := OperatingSystem |
|
2524 |
selectOnAnyReadable:nil |
|
2525 |
writable:(Array with:fd) |
|
2526 |
exception:nil |
|
2527 |
withTimeOut:0. |
|
2528 |
||
2529 |
(rslt isNil and:[OperatingSystem lastErrorSymbol == #EBADF]) ifTrue:[ |
|
2530 |
('Processor [info]: removing invalid write-select fileDescriptor: ' , fd printString) errorPrintCR. |
|
2531 |
writeFdArray at:idx put:nil. |
|
2532 |
OperatingSystem clearLastErrorNumber. |
|
2533 |
(sema := writeSemaphoreArray at:idx) notNil ifTrue:[ |
|
2534 |
writeSemaphoreArray at:idx put:nil. |
|
2535 |
sema signal. |
|
2536 |
]. |
|
2537 |
] |
|
1086 | 2538 |
]. |
1154
96bb8fce61cf
Fix removeCorruptedFds to clear LastErrorNumber. Handle ChildSignalInterrupts in Scheduler's context, to avoid errno corruption.
Stefan Vogel <sv@exept.de>
parents:
1133
diff
changeset
|
2539 |
|
96bb8fce61cf
Fix removeCorruptedFds to clear LastErrorNumber. Handle ChildSignalInterrupts in Scheduler's context, to avoid errno corruption.
Stefan Vogel <sv@exept.de>
parents:
1133
diff
changeset
|
2540 |
"Modified: 12.4.1996 / 09:32:58 / stefan" |
2280 | 2541 |
"Modified: 27.1.1997 / 20:09:27 / cg" |
1086 | 2542 |
! |
2543 |
||
750
f4ed622893ce
added schedulerInterrupt - for soon to come semaSignal primitive function
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
2544 |
schedulerInterrupt |
f4ed622893ce
added schedulerInterrupt - for soon to come semaSignal primitive function
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
2545 |
"forced reschedule - switch to scheduler process which will decide |
f4ed622893ce
added schedulerInterrupt - for soon to come semaSignal primitive function
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
2546 |
what to do now." |
f4ed622893ce
added schedulerInterrupt - for soon to come semaSignal primitive function
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
2547 |
|
2966 | 2548 |
activeProcess ~~ scheduler ifTrue:[ |
2549 |
interruptedProcess := activeProcess. |
|
2550 |
self threadSwitch:scheduler |
|
2551 |
] |
|
750
f4ed622893ce
added schedulerInterrupt - for soon to come semaSignal primitive function
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
2552 |
! |
f4ed622893ce
added schedulerInterrupt - for soon to come semaSignal primitive function
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
2553 |
|
10 | 2554 |
timeToNextTimeout |
2555 |
"return the delta-T (in millis) to next timeout, or nil if |
|
2556 |
there is none" |
|
2557 |
||
231 | 2558 |
|aTime now delta minDelta n "{ Class: SmallInteger }"| |
10 | 2559 |
|
2560 |
"find next timeout. since there are usually not many, just search. |
|
302 | 2561 |
If there were many, the list should be kept sorted ... keeping deltas |
10 | 2562 |
to next (as in Unix kernel)" |
2563 |
||
231 | 2564 |
n := timeoutArray size. |
10 | 2565 |
1 to:n do:[:index | |
231 | 2566 |
aTime := timeoutArray at:index. |
159 | 2567 |
aTime notNil ifTrue:[ |
231 | 2568 |
now isNil ifTrue:[ |
159 | 2569 |
now := OperatingSystem getMillisecondTime. |
231 | 2570 |
]. |
2571 |
(OperatingSystem millisecondTime:aTime isAfter:now) ifFalse:[^ 0]. |
|
2572 |
delta := OperatingSystem millisecondTimeDeltaBetween:aTime and:now. |
|
2573 |
minDelta isNil ifTrue:[ |
|
2574 |
minDelta := delta |
|
159 | 2575 |
] ifFalse:[ |
231 | 2576 |
minDelta := minDelta min:delta |
159 | 2577 |
] |
2578 |
] |
|
10 | 2579 |
]. |
2580 |
||
2581 |
^ minDelta |
|
2582 |
! |
|
2583 |
||
699 | 2584 |
timerInterrupt |
1787
32632b6f969d
remember threadSwitch:from: idea for later implementation;
Claus Gittinger <cg@exept.de>
parents:
1783
diff
changeset
|
2585 |
"{ Pragma: +returnable }" |
32632b6f969d
remember threadSwitch:from: idea for later implementation;
Claus Gittinger <cg@exept.de>
parents:
1783
diff
changeset
|
2586 |
|
699 | 2587 |
"timer expired while waiting - switch to scheduler process which will decide |
1783
be7402f74d94
hide timerInterrupt & ioInterrupt contexts when switching
Claus Gittinger <cg@exept.de>
parents:
1780
diff
changeset
|
2588 |
what to do now. |
be7402f74d94
hide timerInterrupt & ioInterrupt contexts when switching
Claus Gittinger <cg@exept.de>
parents:
1780
diff
changeset
|
2589 |
This method is called by the VM' interrupt handling mechanism. |
be7402f74d94
hide timerInterrupt & ioInterrupt contexts when switching
Claus Gittinger <cg@exept.de>
parents:
1780
diff
changeset
|
2590 |
Notice, that at the time of the message, we are still in the context |
be7402f74d94
hide timerInterrupt & ioInterrupt contexts when switching
Claus Gittinger <cg@exept.de>
parents:
1780
diff
changeset
|
2591 |
of whichever process is currently running." |
699 | 2592 |
|
2966 | 2593 |
activeProcess ~~ scheduler ifTrue:[ |
2594 |
interruptedProcess := activeProcess. |
|
2595 |
self threadSwitch:scheduler |
|
2596 |
] |
|
1783
be7402f74d94
hide timerInterrupt & ioInterrupt contexts when switching
Claus Gittinger <cg@exept.de>
parents:
1780
diff
changeset
|
2597 |
|
be7402f74d94
hide timerInterrupt & ioInterrupt contexts when switching
Claus Gittinger <cg@exept.de>
parents:
1780
diff
changeset
|
2598 |
"Modified: 18.10.1996 / 20:35:54 / cg" |
699 | 2599 |
! |
2600 |
||
10 | 2601 |
waitForEventOrTimeout |
44 | 2602 |
"entered when no process is runnable - wait for either input on |
2603 |
any file descriptors to arrive or a timeout to happen. |
|
2604 |
If it makes sense, do some background garbage collection. |
|
2605 |
The idle actions are a leftover from previous ST/X releases and will |
|
93 | 2606 |
vanish (installing a low-prio process has the same effect)." |
44 | 2607 |
|
1575 | 2608 |
|millis doingGC anySema| |
10 | 2609 |
|
2610 |
doingGC := true. |
|
2611 |
[doingGC] whileTrue:[ |
|
1679
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
2612 |
anyTimeouts ifTrue:[ |
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
2613 |
millis := self timeToNextTimeout. |
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
2614 |
(millis notNil and:[millis <= 0]) ifTrue:[ |
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
2615 |
^ self "oops - hurry up checking" |
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
2616 |
]. |
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
2617 |
]. |
10 | 2618 |
|
1679
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
2619 |
" |
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
2620 |
if its worth doing, collect a bit of garbage; |
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
2621 |
but not, if a backgroundCollector is active |
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
2622 |
" |
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
2623 |
ObjectMemory backgroundCollectorRunning ifTrue:[ |
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
2624 |
doingGC := false |
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
2625 |
] ifFalse:[ |
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
2626 |
doingGC := ObjectMemory gcStepIfUseful. |
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
2627 |
]. |
10 | 2628 |
|
1679
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
2629 |
"then do idle actions" |
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
2630 |
(idleActions notNil and:[idleActions size ~~ 0]) ifTrue:[ |
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
2631 |
idleActions do:[:aBlock | |
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
2632 |
aBlock value. |
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
2633 |
]. |
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
2634 |
^ self "go back checking" |
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
2635 |
]. |
10 | 2636 |
|
1679
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
2637 |
doingGC ifTrue:[ |
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
2638 |
(self checkForInputWithTimeout:0) ifTrue:[ |
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
2639 |
^ self "go back checking" |
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
2640 |
] |
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
2641 |
] |
10 | 2642 |
]. |
2643 |
||
964
6d87e84d86ac
in standAloneMode: exit dispatch if last process dies and no more sema/timer waits are pending
Claus Gittinger <cg@exept.de>
parents:
840
diff
changeset
|
2644 |
exitWhenNoMoreUserProcesses ifTrue:[ |
1679
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
2645 |
"/ check if there are any processes at all |
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
2646 |
"/ stop dispatching if there is none |
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
2647 |
"/ (and millis is nil, which means that no timeout blocks are present) |
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
2648 |
"/ and no readSemaphores are present (which means that noone is waiting for input) |
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
2649 |
"/ and no writeSemaphores are present |
964
6d87e84d86ac
in standAloneMode: exit dispatch if last process dies and no more sema/timer waits are pending
Claus Gittinger <cg@exept.de>
parents:
840
diff
changeset
|
2650 |
|
1679
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
2651 |
anySema := false. |
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
2652 |
anySema := (readSemaphoreArray findFirst:[:sema | sema notNil]) ~~ 0. |
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
2653 |
anySema ifFalse:[ |
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
2654 |
anySema := (writeSemaphoreArray findFirst:[:sema | sema notNil]) ~~ 0. |
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
2655 |
]. |
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
2656 |
anySema ifFalse:[ |
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
2657 |
self anyUserProcessAtAll ifFalse:[ |
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
2658 |
dispatching := false. |
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
2659 |
^ self |
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
2660 |
] |
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
2661 |
]. |
964
6d87e84d86ac
in standAloneMode: exit dispatch if last process dies and no more sema/timer waits are pending
Claus Gittinger <cg@exept.de>
parents:
840
diff
changeset
|
2662 |
]. |
10 | 2663 |
|
1627
f95285226059
infoPrint for NT (no select)
Claus Gittinger <cg@exept.de>
parents:
1618
diff
changeset
|
2664 |
"/ |
f95285226059
infoPrint for NT (no select)
Claus Gittinger <cg@exept.de>
parents:
1618
diff
changeset
|
2665 |
"/ absolutely nothing to do - simply wait |
f95285226059
infoPrint for NT (no select)
Claus Gittinger <cg@exept.de>
parents:
1618
diff
changeset
|
2666 |
"/ |
49 | 2667 |
OperatingSystem supportsSelect ifFalse:[ |
1679
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
2668 |
"SCO instant ShitStation has a bug here, |
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
2669 |
waiting always 1 sec in the select - therefore we delay a bit and |
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
2670 |
return - effectively polling in 50ms cycles |
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
2671 |
" |
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
2672 |
(self checkForInputWithTimeout:0) ifTrue:[ |
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
2673 |
^ self "go back checking" |
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
2674 |
]. |
2626
4194d370d46f
made event polling interval a variable
Claus Gittinger <cg@exept.de>
parents:
2625
diff
changeset
|
2675 |
OperatingSystem millisecondDelay:EventPollingInterval. |
1679
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
2676 |
^ self |
10 | 2677 |
]. |
2678 |
||
2679 |
millis isNil ifTrue:[ |
|
2292
e1c0e8ada72f
can wait forEver, if there is nothing to do
Claus Gittinger <cg@exept.de>
parents:
2280
diff
changeset
|
2680 |
millis := 999999. |
1 | 2681 |
] ifFalse:[ |
1679
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
2682 |
millis := millis rounded |
10 | 2683 |
]. |
2684 |
self checkForInputWithTimeout:millis |
|
768
20434b8239f3
stefans modalBox changes (no more polling)
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
2685 |
|
20434b8239f3
stefans modalBox changes (no more polling)
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
2686 |
"Modified: 14.12.1995 / 13:37:46 / stefan" |
1576 | 2687 |
"Modified: 18.7.1996 / 20:42:17 / cg" |
10 | 2688 |
! ! |
2689 |
||
1783
be7402f74d94
hide timerInterrupt & ioInterrupt contexts when switching
Claus Gittinger <cg@exept.de>
parents:
1780
diff
changeset
|
2690 |
!ProcessorScheduler class methodsFor:'documentation'! |
10 | 2691 |
|
699 | 2692 |
version |
3522
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
2693 |
^ '$Header: /cvs/stx/stx/libbasic/ProcessorScheduler.st,v 1.148 1998-06-07 00:08:56 cg Exp $' |
1 | 2694 |
! ! |
699 | 2695 |
ProcessorScheduler initialize! |