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