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