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