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