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