author | Jan Vrany <jan.vrany@labware.com> |
Wed, 22 Mar 2023 13:57:18 +0000 | |
branch | jv |
changeset 25445 | 1623217d2268 |
parent 25429 | 14ed0c85e7ab |
permissions | -rw-r--r-- |
1 | 1 |
" |
2 |
COPYRIGHT (c) 1993 by Claus Gittinger |
|
23107 | 3 |
COPYRIGHT (c) 2016-2017 Jan Vrany |
18295 | 4 |
All Rights Reserved |
1 | 5 |
|
6 |
This software is furnished under a license and may be used |
|
7 |
only in accordance with the terms of that license and with the |
|
8 |
inclusion of the above copyright notice. This software may not |
|
9 |
be provided or otherwise made available to, or used by, any |
|
10 |
other person. No title to or ownership of the software is |
|
11 |
hereby transferred. |
|
12 |
" |
|
5396 | 13 |
"{ Package: 'stx:libbasic' }" |
14 |
||
17271 | 15 |
"{ NameSpace: Smalltalk }" |
16 |
||
1 | 17 |
Object subclass:#ProcessorScheduler |
15687 | 18 |
instanceVariableNames:'quiescentProcessLists scheduler zombie activeProcess |
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
19 |
activeProcessId currentPriority readFdArray readSemaphoreArray |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
20 |
readCheckArray writeFdArray writeSemaphoreArray writeCheckArray |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
21 |
timeoutArray timeoutActionArray timeoutProcessArray |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
22 |
timeoutSemaphoreArray idleActions anyTimeouts dispatching |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
23 |
interruptedProcess useIOInterrupts gotIOInterrupt |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
24 |
osChildExitActions gotChildSignalInterrupt |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
25 |
exitWhenNoMoreUserProcesses suspendScheduler timeSliceProcess |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
26 |
supportDynamicPriorities timeSliceNeededSemaphore |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
27 |
scheduledProcesses preWaitActions timeoutHandlerProcess |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
28 |
readableResultFdArray writableResultFdArray exceptFdArray |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
29 |
exceptResultFdArray exceptSemaphoreArray interruptCounter |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
30 |
timedActionCounter' |
15687 | 31 |
classVariableNames:'KnownProcesses KnownProcessIds PureEventDriven |
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
32 |
UserSchedulingPriority UserInterruptPriority TimingPriority |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
33 |
HighestPriority SchedulingPriority MaxNumberOfProcesses |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
34 |
InvalidProcessSignal TimeSlicingPriorityLimit TimeSliceInterval |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
35 |
EventPollingInterval MinProcessId MaxProcessId SysProcessId' |
15687 | 36 |
poolDictionaries:'' |
37 |
category:'Kernel-Processes' |
|
1 | 38 |
! |
39 |
||
25422
3b02b0f1f647
Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
23107
diff
changeset
|
40 |
!ProcessorScheduler primitiveDefinitions! |
3b02b0f1f647
Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
23107
diff
changeset
|
41 |
%{ |
3b02b0f1f647
Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
23107
diff
changeset
|
42 |
# ifndef _STDIO_H_INCLUDED_ |
3b02b0f1f647
Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
23107
diff
changeset
|
43 |
# include <stdio.h> |
3b02b0f1f647
Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
23107
diff
changeset
|
44 |
# define _STDIO_H_INCLUDED_ |
3b02b0f1f647
Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
23107
diff
changeset
|
45 |
# endif |
3b02b0f1f647
Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
23107
diff
changeset
|
46 |
%} |
3b02b0f1f647
Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
23107
diff
changeset
|
47 |
! ! |
3b02b0f1f647
Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
23107
diff
changeset
|
48 |
|
1783
be7402f74d94
hide timerInterrupt & ioInterrupt contexts when switching
Claus Gittinger <cg@exept.de>
parents:
1780
diff
changeset
|
49 |
!ProcessorScheduler class methodsFor:'documentation'! |
88 | 50 |
|
51 |
copyright |
|
52 |
" |
|
53 |
COPYRIGHT (c) 1993 by Claus Gittinger |
|
23107 | 54 |
COPYRIGHT (c) 2016-2017 Jan Vrany |
18295 | 55 |
All Rights Reserved |
88 | 56 |
|
57 |
This software is furnished under a license and may be used |
|
58 |
only in accordance with the terms of that license and with the |
|
59 |
inclusion of the above copyright notice. This software may not |
|
60 |
be provided or otherwise made available to, or used by, any |
|
61 |
other person. No title to or ownership of the software is |
|
62 |
hereby transferred. |
|
63 |
" |
|
64 |
! |
|
65 |
||
66 |
documentation |
|
67 |
" |
|
68 |
This class has only one instance, which is bound to the global |
|
2193 | 69 |
'Processor' (well, on future multiprocessor systems, things may look |
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
70 |
different ... ;-). It is responsible for scheduling among the smalltalk |
88 | 71 |
processes (threads; not to confuse with heavy weight unix processes). |
93 | 72 |
|
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
73 |
Scheduling is fully done in smalltalk (the always runnable scheduler- |
93 | 74 |
process, running at highest priority does this). |
2193 | 75 |
See the 'scheduling' documentation. |
76 |
||
231 | 77 |
The main VM primitive to support this is found in threadSwitch, which passes |
93 | 78 |
control to another process (usually selected by the scheduler). |
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
79 |
Thus it is possible to modify the schedulers policy and implementation |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
80 |
at the smalltalk level. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
81 |
|
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
82 |
Notice: Smalltalk/X can (still) be compiled & configured without |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
83 |
process support. This non-process mode is called 'pureEventDriven' mode |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
84 |
and is useful to quickly port ST/X to systems, where these facilities |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
85 |
are either not needed (server applications), or are difficult to |
10747 | 86 |
implement (threads require some assembler support functions). |
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
87 |
To allow pureEvent mode, kludges are built into some places in the |
10747 | 88 |
system, where either a process is forked, or a timeout is used instead |
93 | 89 |
(for examples, see ProcessMonitor or MemoryMonitor). |
90 |
||
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
91 |
This pure-event mode may not be supported in the future |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
92 |
(actually, it is no longer maintained, so don't run the system without Processes). |
93 | 93 |
|
6619 | 94 |
[instance variables:] |
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
95 |
quiescentProcessLists - list of waiting processes |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
96 |
scheduler - the scheduler process itself |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
97 |
zombie - internal temporary (recently died process) |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
98 |
activeProcess - the current process |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
99 |
activeProcessId - the current processes id |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
100 |
currentPriority - the current processes priority |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
101 |
readFdArray - fd-sema-checkBlock triple-association |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
102 |
readSemaphoreArray (stupid historic 3-separate arrays for hi-speed-optimization reasons) |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
103 |
readCheckArray |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
104 |
writeFdArray - fd-sema-checkBlock triple-association |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
105 |
writeSemaphoreArray (stupid historic 3-separate arrays for hi-speed-optimization reasons) |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
106 |
writeCheckArray |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
107 |
timeoutArray - time-action-process-sema quadruple-association |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
108 |
timeoutActionArray (stupid historic 3-separate arrays for hi-speed-optimization reasons) |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
109 |
timeoutProcessArray |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
110 |
timeoutSemaphoreArray |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
111 |
idleActions - actions to be executed when idle |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
112 |
preWaitActions - actions to be executed BEFORE going into an OS-wait |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
113 |
anyTimeouts - flag if any timeouts are pending |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
114 |
dispatching - flag if dispatch process is running (i.e. NOT initializing) |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
115 |
interruptedProcess - the currently interrupted process. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
116 |
useIOInterrupts - flag if the OS supports I/O interrupts and if they are used (to get me out of an OS wait) |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
117 |
gotIOInterrupt - flag if I came out of a wait due to an I/O interrupt |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
118 |
osChildExitActions - OS chid process actions |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
119 |
gotChildSignalInterrupt - flag if I came out of a wait due to an OS child interrupt |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
120 |
exitWhenNoMoreUserProcesses - flag which controls if ST/X should exit when the last process dies (for standalone apps) |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
121 |
suspendScheduler - internal use |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
122 |
timeSliceProcess - the timeSlicer process |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
123 |
supportDynamicPriorities - flag if dynamic priorities should be supported by the timeSlicer |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
124 |
scheduledProcesses - list of scheduled processes for the timeSlicers dynamic prio handling |
369 | 125 |
|
1273 | 126 |
[class variables:] |
93 | 127 |
|
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
128 |
KnownProcesses <WeakArray> all known processes |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
129 |
KnownProcessIds <Collection> and their IDs |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
130 |
|
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
131 |
PureEventDriven <Boolean> true, if no process support |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
132 |
is available |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
133 |
|
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
134 |
UserSchedulingPriority <Integer> the priority at which normal |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
135 |
user interfaces run |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
136 |
|
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
137 |
UserInterruptPriority the priority at which user- |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
138 |
interrupts (Cntl-C) processing |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
139 |
takes place. Processes with |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
140 |
a greater or equal priority are |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
141 |
not interruptable. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
142 |
|
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
143 |
TimingPriority the priority used for timing. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
144 |
Processes with a greater or |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
145 |
equal priority are not interrupted |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
146 |
by timers. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
147 |
|
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
148 |
HighestPriority The highest allowed prio for processes |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
149 |
|
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
150 |
SchedulingPriority The priority of the scheduler (must |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
151 |
me higher than any other). |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
152 |
|
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
153 |
MaxNumberOfProcesses if non-nil, no more than this |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
154 |
number of processes are allowed |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
155 |
(for debugging) |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
156 |
|
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
157 |
TimeSliceInterval for preemptive priority scheduling only: |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
158 |
the time interval in millis, at which processes |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
159 |
are timesliced |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
160 |
|
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
161 |
TimeSlicingPriorityLimit for preemptive priority scheduling only: |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
162 |
processes are only timesliced, if running |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
163 |
at or below this priority. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
164 |
|
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
165 |
EventPollingInterval for systems which do not support select on |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
166 |
a fileDescriptor: the polling interval in millis. |
2626
4194d370d46f
made event polling interval a variable
Claus Gittinger <cg@exept.de>
parents:
2625
diff
changeset
|
167 |
|
759
908363ce8a32
interest is written with one 'r' (shame on me)
Claus Gittinger <cg@exept.de>
parents:
752
diff
changeset
|
168 |
most interesting methods: |
93 | 169 |
|
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
170 |
Processor>>suspend: (see also Process>>suspend) |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
171 |
Processor>>resume: (see also Process>>resume) |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
172 |
Processor>>terminate: (see also Process>>terminate) |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
173 |
Processor>>yield |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
174 |
Processor>>changePriority:for: (see also Process>>priority: |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
175 |
|
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
176 |
Processor>>signal:afterSeconds: (see also Delay>>forSeconds:) |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
177 |
Processor>>signal:afterMilliseconds: (see also Delay>>forMilliseconds:) |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
178 |
Processor>>signal:onInput: (see also ExternalStream>>readWait) |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
179 |
Processor>>signal:onOutput: (see also ExternalStream>>writeWait) |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
180 |
Processor>>disableSemaphore: |
1273 | 181 |
|
182 |
||
183 |
[see also:] |
|
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
184 |
Process |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
185 |
Delay Semaphore SemaphoreSet SharedQueue |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
186 |
WindowGroup |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
187 |
(``Working with processes'': programming/processes.html) |
1294 | 188 |
|
189 |
[author:] |
|
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
190 |
Claus Gittinger |
88 | 191 |
" |
2193 | 192 |
! |
193 |
||
194 |
scheduling |
|
195 |
" |
|
10747 | 196 |
By default, the scheduler does 'non preemptive priority scheduling'; |
197 |
||
198 |
this means, that the highest priority runnable process |
|
2193 | 199 |
is choosen and allowed to run, until it either gives back the CPU (via #yield), |
200 |
or suspends (i.e. waiting for I/O, the time or a semaphore), |
|
201 |
or a higher priority process becomes runnable.. |
|
3650
523781600982
added #useIOInterrupts: to allow disabling this feature
Claus Gittinger <cg@exept.de>
parents:
3644
diff
changeset
|
202 |
A higher prio process may become runnable either by a programmatic action |
523781600982
added #useIOInterrupts: to allow disabling this feature
Claus Gittinger <cg@exept.de>
parents:
3644
diff
changeset
|
203 |
(i.e. signalling a semaphore), by a timer or by IO availability. |
2193 | 204 |
|
205 |
If another process is runnable at the same priority, it will not |
|
206 |
be given CPU-time, unless one of the above happens. |
|
207 |
||
208 |
The consequence is, that a user process running at (say) priority 8, |
|
209 |
may block other user processes at the same priority, if it does heavy |
|
210 |
processing, or loops. |
|
10747 | 211 |
(the event handling which is responsible to care for userInterrupts, |
212 |
is running at a much higher priority, |
|
3650
523781600982
added #useIOInterrupts: to allow disabling this feature
Claus Gittinger <cg@exept.de>
parents:
3644
diff
changeset
|
213 |
so that interrupting the process should always be possible). |
2193 | 214 |
|
215 |
||
216 |
The scheduler also supports 'timesliced priority scheduling', which is enabled |
|
217 |
via the #startTimeSlicing message (and disabled by #stopTimeSlicing). |
|
218 |
In this mode, the highest priority running process is suspended in regular intervals |
|
219 |
(the TimeSliceInterval) IFF there is another runnable process with the same priority. |
|
220 |
I.e. the top highest priority processes are timeshared. |
|
221 |
In this mode, the other processes will also get a chance to make some progress - however, |
|
222 |
lower priority process will only run, IFF all higher prio processes are waiting for an |
|
223 |
event. |
|
224 |
Timeslicing will not be done for processes running above TimeSlicingPriorityLimit, which |
|
225 |
allows for critical processes to run unaffected to completion. |
|
226 |
||
227 |
WARNING: |
|
18295 | 228 |
timesliced priority scheduling is an experimental feature. There is no warranty, |
229 |
(at the moment), that the system runs reliable in this mode. |
|
230 |
The problem is, that shared collections may now be easily modified by other |
|
231 |
processes, running at the same time. |
|
232 |
The class library has being investigated for such possible trouble spots |
|
233 |
(we have eliminated many weak spots, and added critical regions at many places, |
|
234 |
but cannot guarantee that all of them have been found so far ...) |
|
235 |
We found that many existing public domain programs are not prepared for |
|
236 |
being interrupted by a same-prio process and therefore may corrupt their |
|
237 |
data. If in doubt, disable this fefature. |
|
2193 | 238 |
|
239 |
We think, that the timeSlicer is a useful add-on and that the system is fit enough |
|
10747 | 240 |
for it to be evaluated, therefore, its included. |
2193 | 241 |
However, use it at your own risk. |
3650
523781600982
added #useIOInterrupts: to allow disabling this feature
Claus Gittinger <cg@exept.de>
parents:
3644
diff
changeset
|
242 |
|
523781600982
added #useIOInterrupts: to allow disabling this feature
Claus Gittinger <cg@exept.de>
parents:
3644
diff
changeset
|
243 |
To demonstrate the effect of timeSlicing, do the following: |
523781600982
added #useIOInterrupts: to allow disabling this feature
Claus Gittinger <cg@exept.de>
parents:
3644
diff
changeset
|
244 |
|
18295 | 245 |
- disable timeSlicing (in the launchers misc-settings menu) |
246 |
- open a workSpace |
|
247 |
- in the workspace, evaluate: |
|
248 |
[true] whileTrue:[1000 factorial] |
|
3650
523781600982
added #useIOInterrupts: to allow disabling this feature
Claus Gittinger <cg@exept.de>
parents:
3644
diff
changeset
|
249 |
|
523781600982
added #useIOInterrupts: to allow disabling this feature
Claus Gittinger <cg@exept.de>
parents:
3644
diff
changeset
|
250 |
now, (since the workSpace runs at the same prio as other window-processes), |
523781600982
added #useIOInterrupts: to allow disabling this feature
Claus Gittinger <cg@exept.de>
parents:
3644
diff
changeset
|
251 |
other views do no longer react - all CPU is used up by the workSpace. |
523781600982
added #useIOInterrupts: to allow disabling this feature
Claus Gittinger <cg@exept.de>
parents:
3644
diff
changeset
|
252 |
However, CTRL-C in the workspace is still possible to stop the endless loop, |
523781600982
added #useIOInterrupts: to allow disabling this feature
Claus Gittinger <cg@exept.de>
parents:
3644
diff
changeset
|
253 |
since that is handled by the (higher prio) event dispatcher process. |
523781600982
added #useIOInterrupts: to allow disabling this feature
Claus Gittinger <cg@exept.de>
parents:
3644
diff
changeset
|
254 |
|
523781600982
added #useIOInterrupts: to allow disabling this feature
Claus Gittinger <cg@exept.de>
parents:
3644
diff
changeset
|
255 |
Now, stop the factorial-loop, enable timeSlicing, and try again. |
10747 | 256 |
You will notice, that other windows react - although possibly a bit slower, |
3650
523781600982
added #useIOInterrupts: to allow disabling this feature
Claus Gittinger <cg@exept.de>
parents:
3644
diff
changeset
|
257 |
since the CPU is now divided equally among the runnable processes (timeSliced). |
2193 | 258 |
" |
88 | 259 |
! ! |
260 |
||
1783
be7402f74d94
hide timerInterrupt & ioInterrupt contexts when switching
Claus Gittinger <cg@exept.de>
parents:
1780
diff
changeset
|
261 |
!ProcessorScheduler class methodsFor:'initialization'! |
1 | 262 |
|
263 |
initialize |
|
44 | 264 |
"class setup: create the one-and-only instance of myself and |
265 |
setup some priority values." |
|
266 |
||
2193 | 267 |
TimeSliceInterval := 50. |
2626
4194d370d46f
made event polling interval a variable
Claus Gittinger <cg@exept.de>
parents:
2625
diff
changeset
|
268 |
EventPollingInterval := 20. |
2193 | 269 |
|
93 | 270 |
UserSchedulingPriority := 8. |
271 |
UserInterruptPriority := 24. |
|
272 |
TimingPriority := 16. |
|
2190 | 273 |
TimeSlicingPriorityLimit := 26. |
274 |
HighestPriority := 30. |
|
93 | 275 |
SchedulingPriority := 31. |
276 |
||
23071
77ad9497363c
Issue #94 [3/x]: Respect `SYS_PROCESS_ID` when creating an initial system process
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
20080
diff
changeset
|
277 |
self initializeVMProcessIdConstants. |
77ad9497363c
Issue #94 [3/x]: Respect `SYS_PROCESS_ID` when creating an initial system process
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
20080
diff
changeset
|
278 |
|
1679
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
279 |
InvalidProcessSignal isNil ifTrue:[ |
20706
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20643
diff
changeset
|
280 |
InvalidProcessSignal := Error newSignalMayProceed:true. |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20643
diff
changeset
|
281 |
InvalidProcessSignal nameClass:self message:#invalidProcessSignal. |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20643
diff
changeset
|
282 |
InvalidProcessSignal notifierString:'invalid process'. |
1679
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
283 |
]. |
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
284 |
|
159 | 285 |
Processor isNil ifTrue:[ |
20706
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20643
diff
changeset
|
286 |
"create the one and only processor" |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20643
diff
changeset
|
287 |
|
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20643
diff
changeset
|
288 |
Smalltalk at:#Processor put:(self basicNew initialize). |
10 | 289 |
]. |
77 | 290 |
|
291 |
" |
|
292 |
allow configurations without processes |
|
2129
e03cd7bc3475
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
2123
diff
changeset
|
293 |
(but such configurations are no longer distributed) |
77 | 294 |
" |
13 | 295 |
PureEventDriven := self threadsAvailable not. |
296 |
PureEventDriven ifTrue:[ |
|
25422
3b02b0f1f647
Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
23107
diff
changeset
|
297 |
Logger error:'Processor: no process support - running event driven'. |
13 | 298 |
]. |
23071
77ad9497363c
Issue #94 [3/x]: Respect `SYS_PROCESS_ID` when creating an initial system process
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
20080
diff
changeset
|
299 |
|
16841
9e5808800de0
Added MaxProcessId variable & accessor.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16624
diff
changeset
|
300 |
|
9e5808800de0
Added MaxProcessId variable & accessor.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16624
diff
changeset
|
301 |
"Modified: / 23-09-1996 / 14:24:50 / stefan" |
9e5808800de0
Added MaxProcessId variable & accessor.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16624
diff
changeset
|
302 |
"Modified: / 10-01-1997 / 18:03:03 / cg" |
9e5808800de0
Added MaxProcessId variable & accessor.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16624
diff
changeset
|
303 |
"Modified: / 19-09-2014 / 12:47:51 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
18295 | 304 |
! |
305 |
||
23071
77ad9497363c
Issue #94 [3/x]: Respect `SYS_PROCESS_ID` when creating an initial system process
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
20080
diff
changeset
|
306 |
initializeVMProcessIdConstants |
18295 | 307 |
|
308 |
"/ for java locks, the VM may reserve some bits |
|
309 |
"/ and reduce the maximum processID to be able to |
|
310 |
"/ encode the id in an object's header field. |
|
311 |
%{ |
|
312 |
#ifndef __SCHTEAM__ |
|
23071
77ad9497363c
Issue #94 [3/x]: Respect `SYS_PROCESS_ID` when creating an initial system process
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
20080
diff
changeset
|
313 |
@global(ProcessorScheduler:MinProcessId) = __MKSMALLINT(MIN_PROCESS_ID); |
18295 | 314 |
@global(ProcessorScheduler:MaxProcessId) = __MKSMALLINT(MAX_PROCESS_ID); |
23071
77ad9497363c
Issue #94 [3/x]: Respect `SYS_PROCESS_ID` when creating an initial system process
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
20080
diff
changeset
|
315 |
@global(ProcessorScheduler:SysProcessId) = __MKSMALLINT(SYS_PROCESS_ID); |
18295 | 316 |
RETURN (self); |
317 |
#endif /* not SCHTEAM */ |
|
318 |
%}. |
|
23071
77ad9497363c
Issue #94 [3/x]: Respect `SYS_PROCESS_ID` when creating an initial system process
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
20080
diff
changeset
|
319 |
self primitiveFailed |
1 | 320 |
! ! |
321 |
||
1783
be7402f74d94
hide timerInterrupt & ioInterrupt contexts when switching
Claus Gittinger <cg@exept.de>
parents:
1780
diff
changeset
|
322 |
!ProcessorScheduler class methodsFor:'instance creation'! |
10 | 323 |
|
324 |
new |
|
325 |
"there is (currently) only one processor ..." |
|
326 |
||
159 | 327 |
self error:'only one processor is allowed in the system' |
10 | 328 |
! ! |
329 |
||
1783
be7402f74d94
hide timerInterrupt & ioInterrupt contexts when switching
Claus Gittinger <cg@exept.de>
parents:
1780
diff
changeset
|
330 |
!ProcessorScheduler class methodsFor:'Signal constants'! |
1679
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
331 |
|
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
332 |
invalidProcessSignal |
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
333 |
^ InvalidProcessSignal |
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
334 |
|
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
335 |
"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
|
336 |
! ! |
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
337 |
|
1783
be7402f74d94
hide timerInterrupt & ioInterrupt contexts when switching
Claus Gittinger <cg@exept.de>
parents:
1780
diff
changeset
|
338 |
!ProcessorScheduler class methodsFor:'instance release'! |
10 | 339 |
|
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
340 |
update:something with:aParameter from:changedObject |
10747 | 341 |
"some Process has been garbage collected |
342 |
- terminate the underlying thread. |
|
343 |
Usually this does not happen; instead, the process terminates itself |
|
335 | 344 |
by sending #terminate." |
10 | 345 |
|
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
346 |
|id sz "{ Class: SmallInteger }"| |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
347 |
|
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
348 |
something == #ElementExpired ifTrue:[ |
18295 | 349 |
sz := KnownProcessIds size. |
350 |
1 to:sz do:[:index | |
|
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
351 |
"/ (KnownProcesses at:index) isNil ifTrue:[ |
18620
b4e9f25d6ce6
preparations for lined index list in WeakArray
Claus Gittinger <cg@exept.de>
parents:
18295
diff
changeset
|
352 |
(KnownProcesses at:index) class == SmallInteger ifTrue:[ |
18295 | 353 |
id := KnownProcessIds at:index. |
354 |
id notNil ifTrue:[ |
|
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
355 |
'Processor [warning]: terminating thread ' errorPrint. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
356 |
id errorPrint. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
357 |
' (no longer refd)' errorPrintCR. |
18295 | 358 |
|
359 |
self threadDestroy:id. |
|
360 |
KnownProcessIds at:index put:nil. |
|
361 |
]. |
|
362 |
KnownProcesses at:index put:nil. |
|
363 |
] |
|
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
364 |
] |
10 | 365 |
] |
2091
c11bb3e29a1b
Use dependent mechamism of WeakArray instead of #watcher.
Stefan Vogel <sv@exept.de>
parents:
1981
diff
changeset
|
366 |
|
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
367 |
"Created: 7.1.1997 / 16:45:42 / stefan" |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
368 |
"Modified: 10.1.1997 / 19:10:48 / cg" |
10 | 369 |
! ! |
370 |
||
1783
be7402f74d94
hide timerInterrupt & ioInterrupt contexts when switching
Claus Gittinger <cg@exept.de>
parents:
1780
diff
changeset
|
371 |
!ProcessorScheduler class methodsFor:'primitive process primitives'! |
10 | 372 |
|
339 | 373 |
threadCreate:aProcess withId:id |
159 | 374 |
"physical creation of a process. |
10 | 375 |
(warning: low level entry, no administration done). |
339 | 376 |
This may raise an exception, if a VM process could not be created." |
13 | 377 |
|
369 | 378 |
MaxNumberOfProcesses notNil ifTrue:[ |
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
379 |
KnownProcessIds size >= MaxNumberOfProcesses ifTrue:[ |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
380 |
(KnownProcessIds count:[:el | el notNil]) >= MaxNumberOfProcesses ifTrue:[ |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
381 |
" |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
382 |
the number of processes has reached the (soft) limit. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
383 |
This limit prevents runaway programs from creating too many |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
384 |
processes. If you continue in the debugger, the process will be |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
385 |
created as usual. If you don't want this, abort or terminate. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
386 |
" |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
387 |
self error:'too many processes'. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
388 |
] |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
389 |
] |
369 | 390 |
]. |
391 |
||
392 |
%{ |
|
1 | 393 |
int tid; |
394 |
extern int __threadCreate(); |
|
395 |
||
10747 | 396 |
tid = __threadCreate(aProcess, |
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
397 |
0 /* stackSize: no longer needed */, |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
398 |
__isSmallInteger(id) ? __intVal(id) /* assign id */ |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
399 |
: -1 /* let VM assign one */ ); |
339 | 400 |
if (tid) { |
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
401 |
RETURN ( __mkSmallInteger(tid)); |
1 | 402 |
} |
403 |
%} |
|
13 | 404 |
. |
69 | 405 |
" |
406 |
arrive here, if creation of process in VM failed. |
|
159 | 407 |
This may happen, if the VM does not support more processes, |
408 |
or if it ran out of memory, when allocating internal data |
|
409 |
structures. |
|
69 | 410 |
" |
20706
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20643
diff
changeset
|
411 |
^ AllocationFailure raise. |
1 | 412 |
! |
413 |
||
414 |
threadDestroy:id |
|
415 |
"physical destroy other process ... |
|
416 |
(warning: low level entry, no administration done)" |
|
417 |
||
13 | 418 |
%{ /* NOCONTEXT */ |
419 |
||
253 | 420 |
if (__isSmallInteger(id)) { |
18295 | 421 |
__threadDestroy(__intVal(id)); |
1 | 422 |
} |
423 |
%} |
|
699 | 424 |
! |
425 |
||
426 |
threadInterrupt:id |
|
427 |
"make the process evaluate an interrupt. This sets a flag in the VMs |
|
428 |
threadSwitcher, to let the process perform a #interrupt when its set to |
|
10747 | 429 |
run the next time. The process itself can decide how to react on this |
699 | 430 |
interrupt (currently, it looks for interruptBlocks to evaluate)." |
431 |
||
432 |
%{ /* NOCONTEXT */ |
|
433 |
||
434 |
if (__isSmallInteger(id)) { |
|
18295 | 435 |
__threadInterrupt(__intVal(id)); |
699 | 436 |
} |
437 |
%} |
|
438 |
! |
|
439 |
||
440 |
threadsAvailable |
|
441 |
"return true, if the runtime system supports threads (i.e. processes); |
|
442 |
false otherwise." |
|
443 |
||
444 |
%{ /* NOCONTEXT */ |
|
445 |
RETURN (__threadsAvailable()); |
|
5406 | 446 |
%}. |
447 |
^ true |
|
1 | 448 |
! ! |
449 |
||
1783
be7402f74d94
hide timerInterrupt & ioInterrupt contexts when switching
Claus Gittinger <cg@exept.de>
parents:
1780
diff
changeset
|
450 |
!ProcessorScheduler class methodsFor:'queries'! |
699 | 451 |
|
452 |
isPureEventDriven |
|
453 |
"this is temporary - (maybe not :-). |
|
454 |
you can run ST/X either with or without processes. |
|
455 |
Without, there is conceptionally a single process handling all |
|
456 |
outside events and timeouts. This has some negative implications |
|
457 |
(Debugger is ugly), but allows a fully portable ST/X without any |
|
458 |
assembler support - i.e. quick portability. |
|
459 |
The PureEvent flag will automatically be set if the runtime system |
|
460 |
does not support threads - otherwise, it can be set manually |
|
461 |
(from rc-file). |
|
462 |
" |
|
463 |
||
464 |
^ PureEventDriven |
|
465 |
! |
|
466 |
||
467 |
knownProcesses |
|
468 |
"return a collection of all (living) processes in the system" |
|
469 |
||
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
470 |
^ KnownProcesses select:[:p | p notNil and:[p class ~~ SmallInteger]] |
699 | 471 |
! |
472 |
||
14442 | 473 |
knownProcessesDo:aBlock |
25422
3b02b0f1f647
Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
23107
diff
changeset
|
474 |
<resource: #obsolete> |
14442 | 475 |
"evaluate aBlock for each (living) processes in the system" |
476 |
||
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
477 |
KnownProcesses do:[:p | |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
478 |
(p notNil and:[p class ~~ SmallInteger]) ifTrue:[aBlock value:p] |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
479 |
] |
14442 | 480 |
|
481 |
"Created: / 26-10-2012 / 13:02:33 / cg" |
|
482 |
! |
|
483 |
||
699 | 484 |
maxNumberOfProcesses |
485 |
"return the limit on the number of processes; |
|
486 |
the default is nil (i.e. unlimited)." |
|
487 |
||
488 |
^ MaxNumberOfProcesses |
|
489 |
! |
|
10 | 490 |
|
699 | 491 |
maxNumberOfProcesses:aNumber |
492 |
"set the limit on the number of processes. |
|
493 |
This helps if you have a program which (by error) creates countless |
|
494 |
subprocesses. Without this limit, you may have a hard time to find |
|
495 |
this error (and repairing it). If nil (the default), the number of |
|
496 |
processes is unlimited." |
|
497 |
||
498 |
MaxNumberOfProcesses := aNumber |
|
499 |
! |
|
500 |
||
16841
9e5808800de0
Added MaxProcessId variable & accessor.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16624
diff
changeset
|
501 |
maxProcessId |
9e5808800de0
Added MaxProcessId variable & accessor.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16624
diff
changeset
|
502 |
"Return a maximum allowed value of a Process id. " |
9e5808800de0
Added MaxProcessId variable & accessor.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16624
diff
changeset
|
503 |
|
9e5808800de0
Added MaxProcessId variable & accessor.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16624
diff
changeset
|
504 |
^ MaxProcessId |
9e5808800de0
Added MaxProcessId variable & accessor.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16624
diff
changeset
|
505 |
|
9e5808800de0
Added MaxProcessId variable & accessor.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16624
diff
changeset
|
506 |
"Created: / 19-09-2014 / 12:47:16 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
9e5808800de0
Added MaxProcessId variable & accessor.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16624
diff
changeset
|
507 |
! |
9e5808800de0
Added MaxProcessId variable & accessor.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16624
diff
changeset
|
508 |
|
699 | 509 |
processDriven |
510 |
"turn on process driven mode" |
|
10 | 511 |
|
699 | 512 |
PureEventDriven := false |
513 |
! |
|
514 |
||
25422
3b02b0f1f647
Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
23107
diff
changeset
|
515 |
processWithID:id |
3b02b0f1f647
Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
23107
diff
changeset
|
516 |
|wasBlocked| |
3b02b0f1f647
Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
23107
diff
changeset
|
517 |
|
3b02b0f1f647
Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
23107
diff
changeset
|
518 |
wasBlocked := OperatingSystem blockInterrupts. |
3b02b0f1f647
Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
23107
diff
changeset
|
519 |
KnownProcesses nonNilElementsDo:[:p| |
3b02b0f1f647
Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
23107
diff
changeset
|
520 |
p id = id ifTrue:[ |
3b02b0f1f647
Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
23107
diff
changeset
|
521 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
3b02b0f1f647
Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
23107
diff
changeset
|
522 |
^ p |
3b02b0f1f647
Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
23107
diff
changeset
|
523 |
]. |
3b02b0f1f647
Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
23107
diff
changeset
|
524 |
]. |
3b02b0f1f647
Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
23107
diff
changeset
|
525 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
3b02b0f1f647
Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
23107
diff
changeset
|
526 |
^ nil. |
3b02b0f1f647
Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
23107
diff
changeset
|
527 |
|
3b02b0f1f647
Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
23107
diff
changeset
|
528 |
"Created: / 01-06-2020 / 14:03:54 / cg" |
3b02b0f1f647
Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
23107
diff
changeset
|
529 |
! |
3b02b0f1f647
Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
23107
diff
changeset
|
530 |
|
699 | 531 |
pureEventDriven |
532 |
"turn on pure-event driven mode - no processes, single dispatch loop" |
|
533 |
||
534 |
PureEventDriven := true |
|
535 |
! ! |
|
1 | 536 |
|
699 | 537 |
!ProcessorScheduler methodsFor:'I/O event actions'! |
538 |
||
539 |
enableIOAction:aBlock onInput:aFileDescriptor |
|
5101 | 540 |
"obsolete event support: arrange for aBlock to be |
10747 | 541 |
evaluated when input on aFileDescriptor arrives. |
699 | 542 |
This is a leftover support for pure-event systems and may vanish." |
1 | 543 |
|
699 | 544 |
|idx "{Class: SmallInteger }" |
545 |
wasBlocked| |
|
10 | 546 |
|
3116 | 547 |
aFileDescriptor < 0 ifTrue:[ |
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
548 |
'Processor [warning]: ignored invalid fd for IO action.' errorPrintCR. |
18295 | 549 |
thisContext fullPrintAll. |
550 |
^ self |
|
3116 | 551 |
]. |
552 |
||
93 | 553 |
wasBlocked := OperatingSystem blockInterrupts. |
699 | 554 |
(readFdArray identityIndexOf:aFileDescriptor startingAt:1) == 0 ifTrue:[ |
18295 | 555 |
idx := readFdArray identityIndexOf:nil startingAt:1. |
556 |
idx ~~ 0 ifTrue:[ |
|
557 |
readFdArray at:idx put:aFileDescriptor. |
|
558 |
readCheckArray at:idx put:aBlock. |
|
559 |
readSemaphoreArray at:idx put:nil |
|
560 |
] ifFalse:[ |
|
561 |
readFdArray := readFdArray copyWith:aFileDescriptor. |
|
562 |
readCheckArray := readCheckArray copyWith:aBlock. |
|
563 |
readSemaphoreArray := readSemaphoreArray copyWith:nil. |
|
564 |
]. |
|
565 |
useIOInterrupts ifTrue:[ |
|
566 |
OperatingSystem enableIOInterruptsOn:aFileDescriptor |
|
567 |
]. |
|
2831
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
568 |
|
93 | 569 |
]. |
570 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
2831
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
571 |
|
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
572 |
"Modified: 4.8.1997 / 15:17:28 / cg" |
1 | 573 |
! ! |
574 |
||
575 |
!ProcessorScheduler methodsFor:'accessing'! |
|
576 |
||
69 | 577 |
activePriority |
578 |
"return the priority of the currently running process. |
|
159 | 579 |
GNU-ST & ST-80 compatibility; this is the same as currentPriority" |
69 | 580 |
|
581 |
^ currentPriority |
|
582 |
! |
|
583 |
||
25 | 584 |
activeProcess |
10 | 585 |
"return the currently running process" |
586 |
||
25 | 587 |
^ activeProcess |
1 | 588 |
|
25 | 589 |
"Processor activeProcess" |
181 | 590 |
! |
591 |
||
2262 | 592 |
activeProcessId |
593 |
"return the currently running process's ID. |
|
594 |
The same as returned by 'Processor activeProcess id'; |
|
595 |
added for to avoid another send in semaphores debugging support." |
|
596 |
||
597 |
^ activeProcessId |
|
598 |
! |
|
599 |
||
699 | 600 |
currentPriority |
601 |
"return the priority of the currently running process" |
|
602 |
||
603 |
^ currentPriority |
|
604 |
||
605 |
"Processor currentPriority" |
|
606 |
! |
|
607 |
||
21114 | 608 |
exitWhenNoMoreUserProcesses:aBoolean |
609 |
"set/clear the flag, which controls if the scheduler should exit and return |
|
610 |
when the last user process finishes (and therefore exit the smalltalk system). |
|
611 |
A userProcess is defined as a process with a non-zero processGroup. |
|
612 |
This flag is typically set for standAlone operation, to terminate the (Unix-) |
|
613 |
process, when the last thread terminates." |
|
614 |
||
615 |
exitWhenNoMoreUserProcesses := aBoolean |
|
616 |
! |
|
617 |
||
19850 | 618 |
interruptCounter |
619 |
"for statistics: counts the overall number of interrupts" |
|
20706
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20643
diff
changeset
|
620 |
|
19850 | 621 |
^ interruptCounter |
622 |
||
623 |
" |
|
624 |
Processor interruptCounter |
|
625 |
" |
|
626 |
! |
|
627 |
||
181 | 628 |
interruptedProcess |
629 |
"returns the process which was interrupted by the active one" |
|
630 |
||
631 |
^ interruptedProcess |
|
7046 | 632 |
! |
633 |
||
16842
01a2d5d91c96
Oops, added #maxProcessId also to instance side.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16841
diff
changeset
|
634 |
maxProcessId |
01a2d5d91c96
Oops, added #maxProcessId also to instance side.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16841
diff
changeset
|
635 |
^ self class maxProcessId |
01a2d5d91c96
Oops, added #maxProcessId also to instance side.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16841
diff
changeset
|
636 |
|
01a2d5d91c96
Oops, added #maxProcessId also to instance side.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16841
diff
changeset
|
637 |
"Created: / 19-09-2014 / 12:53:45 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
01a2d5d91c96
Oops, added #maxProcessId also to instance side.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16841
diff
changeset
|
638 |
! |
01a2d5d91c96
Oops, added #maxProcessId also to instance side.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16841
diff
changeset
|
639 |
|
7046 | 640 |
scheduler |
641 |
"return the scheduling process" |
|
642 |
||
643 |
^ scheduler |
|
19850 | 644 |
! |
645 |
||
646 |
timedActionCounter |
|
647 |
"for statistics: counts the overall number of timer actions" |
|
20706
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20643
diff
changeset
|
648 |
|
19850 | 649 |
^ timedActionCounter |
650 |
||
651 |
" |
|
652 |
Processor timedActionCounter |
|
653 |
" |
|
10 | 654 |
! ! |
655 |
||
699 | 656 |
!ProcessorScheduler methodsFor:'background processing'! |
1 | 657 |
|
699 | 658 |
addIdleBlock:aBlock |
659 |
"add the argument, aBlock to the list of idle-actions. |
|
660 |
Idle blocks are evaluated whenever no other process is runnable, |
|
661 |
and no events are pending. |
|
10747 | 662 |
Use of idle blocks is not recommended, use a low priority processes |
14780 | 663 |
instead, which has the same effect. Idle blocks are still included |
10747 | 664 |
to support background actions in pure-event systems, where no processes |
699 | 665 |
are available. |
6619 | 666 |
ATTENTION: Support for idle-blocks may vanish." |
10 | 667 |
|
699 | 668 |
|wasBlocked| |
669 |
||
670 |
wasBlocked := OperatingSystem blockInterrupts. |
|
671 |
idleActions isNil ifTrue:[ |
|
18295 | 672 |
idleActions := OrderedCollection new |
699 | 673 |
]. |
674 |
idleActions add:aBlock. |
|
675 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
676 |
! |
|
1 | 677 |
|
699 | 678 |
removeIdleBlock:aBlock |
679 |
"remove the argument, aBlock from the list of idle-blocks. |
|
6619 | 680 |
ATTENTION: Support for idle-blocks may vanish - use low prio processes instead." |
699 | 681 |
|
682 |
|wasBlocked| |
|
683 |
||
684 |
wasBlocked := OperatingSystem blockInterrupts. |
|
685 |
idleActions notNil ifTrue:[ |
|
3969 | 686 |
idleActions removeIdentical:aBlock ifAbsent:nil |
10 | 687 |
]. |
699 | 688 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
2353 | 689 |
|
690 |
"Modified: 1.2.1997 / 12:09:46 / cg" |
|
699 | 691 |
! ! |
692 |
||
10 | 693 |
!ProcessorScheduler methodsFor:'dispatching'! |
694 |
||
695 |
dispatch |
|
93 | 696 |
"It handles timeouts and switches to the highest prio runnable process" |
44 | 697 |
|
19083 | 698 |
|millis pri p nActions "{ Class: SmallInteger }" |
3745 | 699 |
checkBlock sema wasBlocked| |
700 |
||
701 |
wasBlocked := OperatingSystem blockInterrupts. |
|
10 | 702 |
|
93 | 703 |
" |
704 |
handle all timeout actions |
|
705 |
" |
|
27 | 706 |
anyTimeouts ifTrue:[ |
20810 | 707 |
self evaluateTimeouts |
10 | 708 |
]. |
709 |
||
231 | 710 |
"first do a quick check for semaphores using checkActions - this is needed for |
302 | 711 |
devices like the X-connection, where some events might be in the event |
10747 | 712 |
queue but the sockets input queue is empty. |
5101 | 713 |
Without these checks, a select might block even though there is work to do. |
714 |
Also, this is needed for poor MSDOS, where WaitForObject does not work with |
|
715 |
sockets and pipes (sigh) |
|
93 | 716 |
" |
231 | 717 |
nActions := readCheckArray size. |
10 | 718 |
1 to:nActions do:[:index | |
20810 | 719 |
checkBlock := readCheckArray at:index. |
720 |
(checkBlock notNil and:[checkBlock value]) ifTrue:[ |
|
721 |
sema := readSemaphoreArray at:index. |
|
722 |
sema notNil ifTrue:[ |
|
723 |
sema signalOnce. |
|
724 |
]. |
|
725 |
] |
|
5101 | 726 |
]. |
727 |
nActions := writeCheckArray size. |
|
728 |
1 to:nActions do:[:index | |
|
20810 | 729 |
checkBlock := writeCheckArray at:index. |
730 |
(checkBlock notNil and:[checkBlock value]) ifTrue:[ |
|
731 |
sema := writeSemaphoreArray at:index. |
|
732 |
sema notNil ifTrue:[ |
|
733 |
sema signalOnce. |
|
734 |
]. |
|
735 |
] |
|
10 | 736 |
]. |
737 |
||
231 | 738 |
"now, someone might be runnable ..." |
10 | 739 |
|
13 | 740 |
p := self highestPriorityRunnableProcess. |
10 | 741 |
p isNil ifTrue:[ |
20810 | 742 |
"/ no one runnable, hard wait for event or timeout |
743 |
"/ Trace ifTrue:['w' printCR.]. |
|
744 |
self waitForEventOrTimeout. |
|
745 |
||
746 |
"/ check for OS process termination |
|
747 |
gotChildSignalInterrupt ifTrue:[ |
|
748 |
gotChildSignalInterrupt := false. |
|
749 |
self handleChildSignalInterrupt |
|
750 |
]. |
|
751 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
752 |
^ self |
|
10 | 753 |
]. |
754 |
||
13 | 755 |
pri := p priority. |
756 |
||
302 | 757 |
" |
758 |
want to give control to the process p. |
|
10 | 759 |
If the switched-to processes priority is lower than the |
10747 | 760 |
userSchedulingPriority, we have to make certain, that the |
10 | 761 |
next input or timer will bring us back for a reschedule. |
762 |
This is done by enabling ioInterrupts for all file descriptors. |
|
10747 | 763 |
If ioInterrupts are not available (OS does not support them), |
302 | 764 |
we schedule a timer interrupt to interrupt us after 1/20s of a second |
765 |
- effectively polling the filedescriptors 20 times a second. |
|
766 |
(which is bad, since low prio processes will be hurt in performance) |
|
20810 | 767 |
Therefore, don't let benchmarks run with low prio ... |
302 | 768 |
|
10747 | 769 |
Higher prio processes must be suspended, |
302 | 770 |
same prio ones must yield or suspend to get back control |
771 |
" |
|
10 | 772 |
|
93 | 773 |
" |
774 |
uncommenting this will make timeouts interrupt the current process |
|
10747 | 775 |
(i.e. as if the interrupt runs at TimingPrio); |
93 | 776 |
if left commented, they are handled at UserSchedulingPrio. |
13 | 777 |
this will all change, when timeouts are removed and all is process driven |
231 | 778 |
(a future version will have a process running to handle a timeout queue) |
13 | 779 |
" |
780 |
||
781 |
" |
|
782 |
pri < TimingPriority ifTrue:[ |
|
20810 | 783 |
anyTimeouts ifTrue:[ |
784 |
millis := self timeToNextTimeout. |
|
785 |
millis == 0 ifTrue:[ |
|
786 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
787 |
^ self |
|
788 |
] |
|
789 |
] |
|
13 | 790 |
]. |
791 |
" |
|
792 |
||
93 | 793 |
" |
794 |
if the process to run has a lower than UserInterruptPriority, |
|
302 | 795 |
arrange for an interrupt to occur on I/O. |
231 | 796 |
This is done by enabling IO-signals (if the OS supports them) |
93 | 797 |
or by installing a poll-interrupt after 50ms (if the OS does not). |
798 |
" |
|
799 |
pri < UserInterruptPriority ifTrue:[ |
|
10747 | 800 |
|
93 | 801 |
"comment out this if above is uncommented" |
20810 | 802 |
anyTimeouts ifTrue:[ |
803 |
millis := self timeToNextTimeout. |
|
804 |
millis == 0 ifTrue:[ |
|
805 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
806 |
^ self |
|
807 |
]. |
|
808 |
]. |
|
93 | 809 |
"---" |
10 | 810 |
|
20810 | 811 |
useIOInterrupts ifTrue:[ |
2831
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
812 |
"/ readFdArray do:[:fd | |
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
813 |
"/ (fd notNil and:[fd >= 0]) ifTrue:[ |
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
814 |
"/ OperatingSystem enableIOInterruptsOn:fd |
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
815 |
"/ ]. |
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
816 |
"/ ]. |
20810 | 817 |
] ifFalse:[ |
818 |
millis notNil ifTrue:[ |
|
819 |
millis := millis min:EventPollingInterval |
|
820 |
] ifFalse:[ |
|
821 |
millis := EventPollingInterval |
|
822 |
] |
|
823 |
] |
|
13 | 824 |
]. |
10 | 825 |
|
13 | 826 |
millis notNil ifTrue:[ |
20810 | 827 |
"/ Trace ifTrue:['C' print. millis printCR.]. |
828 |
"schedule a clock interrupt after millis milliseconds" |
|
829 |
OperatingSystem enableTimer:millis rounded. |
|
10 | 830 |
]. |
831 |
||
3722
1114c2014bea
added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents:
3718
diff
changeset
|
832 |
scheduledProcesses notNil ifTrue:[ |
20810 | 833 |
scheduledProcesses add:p |
3722
1114c2014bea
added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents:
3718
diff
changeset
|
834 |
]. |
1114c2014bea
added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents:
3718
diff
changeset
|
835 |
|
231 | 836 |
" |
837 |
now let the process run - will come back here by reschedule |
|
15438 | 838 |
from ioInterrupt, scheduler or timerInterrupt ... (running at max+1) |
231 | 839 |
" |
10747 | 840 |
"/ Trace ifTrue:['->' print. p printCR.]. |
10 | 841 |
self threadSwitch:p. |
10747 | 842 |
"/ Trace ifTrue:['<-' printCR.]. |
10 | 843 |
|
804
264d440a67a0
Fixes when useIOInterrupts == true.
Stefan Vogel <sv@exept.de>
parents:
786
diff
changeset
|
844 |
"... when we arrive here, we are back on stage. |
20810 | 845 |
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
|
846 |
" |
10 | 847 |
|
848 |
millis notNil ifTrue:[ |
|
20810 | 849 |
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
|
850 |
]. |
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
|
851 |
|
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
|
852 |
"/ 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
|
853 |
gotChildSignalInterrupt ifTrue:[ |
20810 | 854 |
gotChildSignalInterrupt := false. |
855 |
self handleChildSignalInterrupt |
|
804
264d440a67a0
Fixes when useIOInterrupts == true.
Stefan Vogel <sv@exept.de>
parents:
786
diff
changeset
|
856 |
]. |
264d440a67a0
Fixes when useIOInterrupts == true.
Stefan Vogel <sv@exept.de>
parents:
786
diff
changeset
|
857 |
|
264d440a67a0
Fixes when useIOInterrupts == true.
Stefan Vogel <sv@exept.de>
parents:
786
diff
changeset
|
858 |
"/ check for new input |
264d440a67a0
Fixes when useIOInterrupts == true.
Stefan Vogel <sv@exept.de>
parents:
786
diff
changeset
|
859 |
|
3745 | 860 |
OperatingSystem unblockInterrupts. |
861 |
||
804
264d440a67a0
Fixes when useIOInterrupts == true.
Stefan Vogel <sv@exept.de>
parents:
786
diff
changeset
|
862 |
(gotIOInterrupt or:[useIOInterrupts not]) ifTrue:[ |
20810 | 863 |
gotIOInterrupt := false. |
864 |
self checkForIOWithTimeout:0. |
|
3745 | 865 |
]. |
866 |
||
867 |
wasBlocked ifTrue:[OperatingSystem blockInterrupts]. |
|
768
20434b8239f3
stefans modalBox changes (no more polling)
Claus Gittinger <cg@exept.de>
parents:
759
diff
changeset
|
868 |
|
3722
1114c2014bea
added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents:
3718
diff
changeset
|
869 |
"Modified: / 12.4.1996 / 10:14:18 / stefan" |
1114c2014bea
added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents:
3718
diff
changeset
|
870 |
"Modified: / 3.8.1998 / 21:54:01 / cg" |
699 | 871 |
! |
872 |
||
873 |
dispatchLoop |
|
874 |
"central dispatch loop; the scheduler process is always staying in |
|
875 |
this method, looping forever." |
|
876 |
||
806
409a8c189e01
also handle termination of the scheduler process
Claus Gittinger <cg@exept.de>
parents:
804
diff
changeset
|
877 |
|dispatchAction handlerAction ignoredSignals| |
786 | 878 |
|
699 | 879 |
"avoid confusion if entered twice" |
880 |
||
14230 | 881 |
dispatching == true ifTrue:[ |
25422
3b02b0f1f647
Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
23107
diff
changeset
|
882 |
Logger info:'Processor: already in dispatch'. |
3b02b0f1f647
Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
23107
diff
changeset
|
883 |
^ self |
14230 | 884 |
]. |
699 | 885 |
dispatching := true. |
886 |
||
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
|
887 |
"/ 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
|
888 |
"/ 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
|
889 |
"/ (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
|
890 |
"/ 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
|
891 |
|
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
892 |
dispatchAction := |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
893 |
[ |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
894 |
[dispatching] whileTrue:[ |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
895 |
self dispatch |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
896 |
] |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
897 |
]. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
898 |
|
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
899 |
handlerAction := |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
900 |
[:ex | |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
901 |
(HaltInterrupt accepts:ex creator) ifTrue:[ |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
902 |
"/ in a standalone application, we do not want those |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
903 |
(Smalltalk isStandAloneApp and:[Smalltalk isStandAloneDebug not]) ifTrue:[ |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
904 |
('Processor [info]: ignored (', ex creator printString, ')') infoPrintCR. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
905 |
ex proceed. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
906 |
]. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
907 |
"/ MiniDebugger enter. -- should this be done when some --debug/--verbose was given? |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
908 |
ex proceed. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
909 |
]. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
910 |
|
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
911 |
('Processor [info]: caught (and ignored) signal (', ex creator printString, ')') infoPrintCR. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
912 |
ex return |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
913 |
]. |
10747 | 914 |
|
915 |
ignoredSignals := SignalSet |
|
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
916 |
with:HaltInterrupt |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
917 |
with:TerminateProcessRequest |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
918 |
with:RecursionError |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
919 |
with:AbortAllOperationRequest. |
786 | 920 |
|
921 |
"/ |
|
922 |
"/ I made this an extra call to dispatch; this allows recompilation |
|
923 |
"/ of the dispatch-handling code in the running system. |
|
924 |
"/ |
|
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
|
925 |
[dispatching] whileTrue:[ |
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
926 |
ignoredSignals |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
927 |
handle:handlerAction |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
928 |
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
|
929 |
]. |
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
|
930 |
|
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
|
931 |
"/ 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
|
932 |
"/ 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
|
933 |
"/ 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
|
934 |
|
25422
3b02b0f1f647
Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
23107
diff
changeset
|
935 |
Logger info:'Processor: finish dispatch (no more processes)'. |
3b02b0f1f647
Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
23107
diff
changeset
|
936 |
|
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
937 |
"Modified: / 23-09-1996 / 14:19:56 / stefan" |
14230 | 938 |
"Modified: / 20-07-2012 / 18:34:48 / cg" |
827
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
807
diff
changeset
|
939 |
! ! |
806
409a8c189e01
also handle termination of the scheduler process
Claus Gittinger <cg@exept.de>
parents:
804
diff
changeset
|
940 |
|
6434 | 941 |
!ProcessorScheduler methodsFor:'initialization'! |
3522
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
942 |
|
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
943 |
initialize |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
944 |
"initialize the one-and-only ProcessorScheduler" |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
945 |
|
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
946 |
|nPrios "{ Class: SmallInteger }" |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
947 |
p l| |
3522
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
948 |
|
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
949 |
KnownProcesses isNil ifTrue:[ |
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
950 |
KnownProcesses := WeakArray new:30. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
951 |
KnownProcesses addDependent:self class. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
952 |
KnownProcessIds := OrderedCollection new:30. |
3522
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
953 |
]. |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
954 |
|
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
955 |
" |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
956 |
create a collection with process lists; accessed using the priority as key |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
957 |
" |
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
958 |
nPrios := SchedulingPriority. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
959 |
quiescentProcessLists := Array new:nPrios. |
3967 | 960 |
|
961 |
readFdArray := Array new:5. |
|
962 |
readCheckArray := Array new:5. |
|
963 |
readSemaphoreArray := Array new:5. |
|
964 |
writeFdArray := Array new:3. |
|
5101 | 965 |
writeCheckArray := Array new:3. |
3967 | 966 |
writeSemaphoreArray := Array new:3. |
18957 | 967 |
exceptFdArray := Array new:3. |
968 |
exceptSemaphoreArray := Array new:3. |
|
969 |
||
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
970 |
timeoutArray := Array new:5. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
971 |
timeoutSemaphoreArray := Array new:5. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
972 |
timeoutActionArray := Array new:5. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
973 |
timeoutProcessArray := Array new:5. |
3967 | 974 |
|
3522
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
975 |
anyTimeouts := false. |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
976 |
dispatching := false. |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
977 |
useIOInterrupts := OperatingSystem supportsIOInterrupts. |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
978 |
gotIOInterrupt := false. |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
979 |
osChildExitActions := Dictionary new. |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
980 |
gotChildSignalInterrupt := false. |
19850 | 981 |
interruptCounter := timedActionCounter := 0. |
3522
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
982 |
|
17412 | 983 |
supportDynamicPriorities := false. |
984 |
exitWhenNoMoreUserProcesses isNil ifTrue:[ |
|
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
985 |
exitWhenNoMoreUserProcesses := false. "/ mhmh - how about true ? |
17412 | 986 |
]. |
987 |
||
3522
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
988 |
" |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
989 |
handcraft the first (dispatcher-) process - this one will never |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
990 |
block, but go into a select if there is nothing to do. |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
991 |
Also, it has a prio of max+1 - thus, it comes first when looking |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
992 |
for a runnable process. |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
993 |
" |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
994 |
currentPriority := SchedulingPriority. |
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
995 |
p := Process basicNew. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
996 |
p |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
997 |
setId:SysProcessId state:#run; |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
998 |
setPriority:currentPriority; |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
999 |
name:'scheduler'; |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1000 |
beSystemProcess. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1001 |
|
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1002 |
scheduler := activeProcess := p. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1003 |
activeProcessId := SysProcessId. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1004 |
|
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1005 |
quiescentProcessLists at:currentPriority put:(l := LinkedList new). |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1006 |
l add:p. |
3522
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
1007 |
|
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
1008 |
" |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
1009 |
let me handle IO and timer interrupts |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
1010 |
" |
5406 | 1011 |
useIOInterrupts ifTrue:[ObjectMemory ioInterruptHandler:self]. |
18295 | 1012 |
ObjectMemory |
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1013 |
timerInterruptHandler:self; |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1014 |
childSignalInterruptHandler:self. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1015 |
|
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1016 |
"Modified: / 7.1.1997 / 16:48:26 / stefan" |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1017 |
"Modified: / 4.2.1999 / 13:08:39 / cg" |
3522
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
1018 |
! |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
1019 |
|
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
1020 |
reinitialize |
10747 | 1021 |
"all previous processes (except those marked as restartable) are made dead |
3522
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
1022 |
- each object should reinstall its process(s) upon restart; |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
1023 |
especially, windowgroups have to. |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
1024 |
In contrast to ST-80, restartable processes are restarted at the beginning |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
1025 |
NOT continued where left. This is a consequence of the portable implementation |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
1026 |
of ST/X, since in order to continue a process, we needed to know the |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
1027 |
internals of the machines (and C-compilers) stack layout. |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
1028 |
This was not done, favouring portability for process continuation. |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
1029 |
In praxis, this is not much of a problem, since in almost every case, |
10747 | 1030 |
the computation state can be saved in some object, and processing be |
3522
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
1031 |
restarted from scratch, reinitializing things from this saved state." |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
1032 |
|
3525
26fe903e0250
oops - no need for last change
Claus Gittinger <cg@exept.de>
parents:
3522
diff
changeset
|
1033 |
|processesToRestart| |
26fe903e0250
oops - no need for last change
Claus Gittinger <cg@exept.de>
parents:
3522
diff
changeset
|
1034 |
|
3522
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
1035 |
" |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
1036 |
lay all processes to rest, collect restartable ones |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
1037 |
" |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
1038 |
processesToRestart := OrderedCollection new. |
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1039 |
KnownProcesses do:[:p | |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1040 |
(p notNil and:[p class ~~ SmallInteger]) ifTrue:[ |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1041 |
"how, exactly should this be done ?" |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1042 |
|
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1043 |
p isRestartable == true ifTrue:[ |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1044 |
p nextLink:nil. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1045 |
processesToRestart add:p |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1046 |
] ifFalse:[ |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1047 |
p setId:nil state:#dead |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1048 |
] |
18295 | 1049 |
]. |
3522
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
1050 |
]. |
10747 | 1051 |
scheduler setId:nil state:#dead. |
3522
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
1052 |
|
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
1053 |
" |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
1054 |
now, start from scratch |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
1055 |
" |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
1056 |
KnownProcesses := nil. |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
1057 |
self initialize. |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
1058 |
|
3525
26fe903e0250
oops - no need for last change
Claus Gittinger <cg@exept.de>
parents:
3522
diff
changeset
|
1059 |
processesToRestart do:[:p | |
18295 | 1060 |
p imageRestart |
3522
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
1061 |
] |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
1062 |
|
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1063 |
"Modified: / 7.6.1998 / 02:23:56 / cg" |
3522
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
1064 |
! ! |
291ec553ac33
restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents:
3312
diff
changeset
|
1065 |
|
3777
f351744c575f
fix terminate/interrupt/reschedule while in osWait (win32)
Claus Gittinger <cg@exept.de>
parents:
3745
diff
changeset
|
1066 |
!ProcessorScheduler methodsFor:'native thread support'! |
f351744c575f
fix terminate/interrupt/reschedule while in osWait (win32)
Claus Gittinger <cg@exept.de>
parents:
3745
diff
changeset
|
1067 |
|
7842
c6ce40656157
preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents:
7761
diff
changeset
|
1068 |
vmResumeInterrupt:id |
10747 | 1069 |
"signal from VM to resume a thread after finish of an osWait or wrapCall-wait. |
7842
c6ce40656157
preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents:
7761
diff
changeset
|
1070 |
MUST be invoked with interrupts blocked. |
c6ce40656157
preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents:
7761
diff
changeset
|
1071 |
This is only used with native threads." |
c6ce40656157
preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents:
7761
diff
changeset
|
1072 |
|
8504
93b46834c68f
#unblockInterrupts returns the prvious blocking state
Stefan Vogel <sv@exept.de>
parents:
8494
diff
changeset
|
1073 |
<context: #return> |
93b46834c68f
#unblockInterrupts returns the prvious blocking state
Stefan Vogel <sv@exept.de>
parents:
8494
diff
changeset
|
1074 |
|
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1075 |
|index pri aProcess l| |
7842
c6ce40656157
preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents:
7761
diff
changeset
|
1076 |
|
c6ce40656157
preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents:
7761
diff
changeset
|
1077 |
OperatingSystem interruptsBlocked ifFalse:[ |
19850 | 1078 |
MiniDebugger |
1079 |
enterWithMessage:'vmResumeInterrupt with no interruptsBlocked' |
|
1080 |
mayProceed:true. |
|
7842
c6ce40656157
preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents:
7761
diff
changeset
|
1081 |
]. |
c6ce40656157
preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents:
7761
diff
changeset
|
1082 |
|
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1083 |
index := KnownProcessIds identityIndexOf:id. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1084 |
index ~~ 0 ifTrue:[ |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1085 |
aProcess := KnownProcesses at:index. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1086 |
pri := aProcess priority. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1087 |
l := quiescentProcessLists at:pri. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1088 |
l notNil ifTrue:[ |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1089 |
(l includesIdentical:aProcess) ifTrue:[ |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1090 |
"/ aProcess is on a run queue. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1091 |
"/ CG: this situation may happen, if the wrapCall |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1092 |
"/ finishes before the process was layed to sleep |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1093 |
"/ (i.e. schedulerIRQ arrives before the threadSwitch was finished). |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1094 |
"/ In that case, simply resume it and everything is OK. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1095 |
"/ If the process is state running, ignore. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1096 |
|
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1097 |
|state| |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1098 |
|
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1099 |
state := aProcess state. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1100 |
(state == #wrapWait or:[(state == #osWait) or:[state == #stopped]]) ifTrue:[ |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1101 |
aProcess state:#run. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1102 |
]. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1103 |
'ProcSched [info]: resumeIRQ ignored for process: ' infoPrint. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1104 |
aProcess id infoPrint. ' in state: ' infoPrint. state infoPrintCR. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1105 |
^ self |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1106 |
] |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1107 |
] ifFalse:[ |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1108 |
l := LinkedList new. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1109 |
quiescentProcessLists at:pri put:l. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1110 |
]. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1111 |
l addLast:aProcess. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1112 |
aProcess state:#run. |
7842
c6ce40656157
preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents:
7761
diff
changeset
|
1113 |
] ifFalse:[ |
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1114 |
'ProcSched [info]: resumeIRQ for unknown process: ' infoPrint. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1115 |
id infoPrintCR. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1116 |
] |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1117 |
|
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1118 |
"Modified: / 28.9.1998 / 11:36:53 / cg" |
7842
c6ce40656157
preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents:
7761
diff
changeset
|
1119 |
! |
c6ce40656157
preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents:
7761
diff
changeset
|
1120 |
|
7844
906062102891
preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents:
7843
diff
changeset
|
1121 |
vmSuspendInterrupt:whyCode |
7842
c6ce40656157
preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents:
7761
diff
changeset
|
1122 |
"signal from VM to suspend a thread into a certain state. |
10747 | 1123 |
Invoked before the VM switches to the scheduler process. |
7842
c6ce40656157
preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents:
7761
diff
changeset
|
1124 |
MUST be invoked with interrupts blocked. |
c6ce40656157
preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents:
7761
diff
changeset
|
1125 |
This is only used with native threads." |
c6ce40656157
preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents:
7761
diff
changeset
|
1126 |
|
8504
93b46834c68f
#unblockInterrupts returns the prvious blocking state
Stefan Vogel <sv@exept.de>
parents:
8494
diff
changeset
|
1127 |
<context: #return> |
93b46834c68f
#unblockInterrupts returns the prvious blocking state
Stefan Vogel <sv@exept.de>
parents:
8494
diff
changeset
|
1128 |
|
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1129 |
|pri l newState| |
7842
c6ce40656157
preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents:
7761
diff
changeset
|
1130 |
|
c6ce40656157
preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents:
7761
diff
changeset
|
1131 |
OperatingSystem interruptsBlocked ifFalse:[ |
18295 | 1132 |
MiniDebugger |
1133 |
enterWithMessage:'immediateInterrupt with no interruptsBlocked' |
|
1134 |
mayProceed:true. |
|
7842
c6ce40656157
preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents:
7761
diff
changeset
|
1135 |
]. |
c6ce40656157
preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents:
7761
diff
changeset
|
1136 |
|
7844
906062102891
preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents:
7843
diff
changeset
|
1137 |
(whyCode == 2) ifTrue:[ |
18295 | 1138 |
newState := #wrapWait. |
7843
922a4285375a
preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents:
7842
diff
changeset
|
1139 |
] ifFalse:[ |
18295 | 1140 |
(whyCode == 3) ifTrue:[ |
1141 |
newState := #osWait. |
|
1142 |
] ifFalse:[ |
|
1143 |
newState := #stopped. |
|
1144 |
]. |
|
7843
922a4285375a
preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents:
7842
diff
changeset
|
1145 |
]. |
7842
c6ce40656157
preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents:
7761
diff
changeset
|
1146 |
activeProcess setStateTo:newState if:#active. |
c6ce40656157
preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents:
7761
diff
changeset
|
1147 |
|
c6ce40656157
preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents:
7761
diff
changeset
|
1148 |
pri := activeProcess priority. |
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1149 |
l := quiescentProcessLists at:pri. |
7842
c6ce40656157
preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents:
7761
diff
changeset
|
1150 |
|
c6ce40656157
preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents:
7761
diff
changeset
|
1151 |
"notice: this is slightly faster than putting the if-code into |
c6ce40656157
preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents:
7761
diff
changeset
|
1152 |
the ifAbsent block, because [] is a shared cheap block, created at compile time |
c6ce40656157
preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents:
7761
diff
changeset
|
1153 |
" |
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1154 |
(l isNil or:[(l removeIdentical:activeProcess ifAbsent:nil) isNil]) ifTrue:[ |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1155 |
"/ 'Processor [warning]: bad vmSuspendInterrupt: not on run list' errorPrintCR. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1156 |
MiniDebugger enterWithMessage:'bad vmSuspendInterrupt: not on run list' mayProceed:true. |
18295 | 1157 |
^ self |
7842
c6ce40656157
preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents:
7761
diff
changeset
|
1158 |
]. |
3777
f351744c575f
fix terminate/interrupt/reschedule while in osWait (win32)
Claus Gittinger <cg@exept.de>
parents:
3745
diff
changeset
|
1159 |
! ! |
f351744c575f
fix terminate/interrupt/reschedule while in osWait (win32)
Claus Gittinger <cg@exept.de>
parents:
3745
diff
changeset
|
1160 |
|
827
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
807
diff
changeset
|
1161 |
!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
|
1162 |
|
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
807
diff
changeset
|
1163 |
childSignalInterrupt |
2116
1bcb6ee86fca
fixed pending sigChild problem;
Claus Gittinger <cg@exept.de>
parents:
2111
diff
changeset
|
1164 |
"{ Pragma: +returnable }" |
1bcb6ee86fca
fixed pending sigChild problem;
Claus Gittinger <cg@exept.de>
parents:
2111
diff
changeset
|
1165 |
|
10747 | 1166 |
"child changed state - switch to scheduler process which will decide |
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
|
1167 |
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
|
1168 |
|
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
|
1169 |
gotChildSignalInterrupt := true. |
20052 | 1170 |
interruptCounter := interruptCounter + 1 bitAnd:SmallInteger maxVal. |
2966 | 1171 |
activeProcess ~~ scheduler ifTrue:[ |
20706
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20643
diff
changeset
|
1172 |
interruptCounter := interruptCounter + 1 bitAnd:SmallInteger maxVal. |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20643
diff
changeset
|
1173 |
interruptedProcess := activeProcess. |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20643
diff
changeset
|
1174 |
self threadSwitch:scheduler |
2966 | 1175 |
] |
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
|
1176 |
|
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
|
1177 |
"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
|
1178 |
! |
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
|
1179 |
|
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
|
1180 |
handleChildSignalInterrupt |
827
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
807
diff
changeset
|
1181 |
"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
|
1182 |
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
|
1183 |
|
523533898acd
Reset sigCHLD interrupt handler, when no more processes are being waited for.
Stefan Vogel <sv@exept.de>
parents:
829
diff
changeset
|
1184 |
|osProcessStatus blocking wasBlocked| |
827
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
807
diff
changeset
|
1185 |
|
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1186 |
blocking := OperatingSystem isChildProcessWaitBlocking. |
827
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
807
diff
changeset
|
1187 |
|
840
523533898acd
Reset sigCHLD interrupt handler, when no more processes are being waited for.
Stefan Vogel <sv@exept.de>
parents:
829
diff
changeset
|
1188 |
"/ 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
|
1189 |
wasBlocked := OperatingSystem blockInterrupts. |
827
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
807
diff
changeset
|
1190 |
[ |
18295 | 1191 |
[ |
1192 |
osProcessStatus := OperatingSystem childProcessWait:blocking pid:nil. |
|
1193 |
osProcessStatus notNil ifTrue:[ |
|
1194 |
|pid action| |
|
1195 |
||
1196 |
pid := osProcessStatus pid. |
|
1197 |
osProcessStatus stillAlive ifTrue:[ |
|
1198 |
action := osChildExitActions at:pid ifAbsent:nil. |
|
1199 |
] ifFalse:[ |
|
1200 |
action := osChildExitActions removeKey:pid ifAbsent:nil. |
|
1201 |
]. |
|
1202 |
action notNil ifTrue:[ |
|
1203 |
action value:osProcessStatus |
|
1204 |
]. |
|
1205 |
]. |
|
1206 |
||
1207 |
"/ if pollChildProcesses does block, poll only one status change. |
|
1208 |
"/ we will get another SIGCHLD for other status changes. |
|
1209 |
||
1210 |
osProcessStatus notNil and:[blocking not] |
|
1211 |
] whileTrue. |
|
1212 |
||
1213 |
"/ if there are no more waiters, disable SIGCHILD handler. |
|
1214 |
"/ this helps us with synchronous waiters (e.g. pclose), |
|
1215 |
"/ But they should block SIGCHLD anyway. |
|
1216 |
||
1217 |
osChildExitActions isEmpty ifTrue:[ |
|
1218 |
OperatingSystem disableChildSignalInterrupts. |
|
1219 |
]. |
|
6421
58dca33cf0fc
#valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents:
6376
diff
changeset
|
1220 |
] ensure:[ |
18295 | 1221 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
1032 | 1222 |
] |
827
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
807
diff
changeset
|
1223 |
|
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1224 |
"Modified: 5.1.1996 / 16:56:11 / stefan" |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1225 |
"Modified: 28.2.1996 / 21:36:31 / cg" |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1226 |
"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
|
1227 |
! |
3eb3911cb63e
Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents:
807
diff
changeset
|
1228 |
|
2499
95392696facc
Fix race condition when waiting for SIGCHLD.
Stefan Vogel <sv@exept.de>
parents:
2468
diff
changeset
|
1229 |
monitor:aBlockReturningPid action:actionBlock |
2611
9a575397bf9a
fixed davids monitorPid (dont wait a second; dont do busy poll ...)
Claus Gittinger <cg@exept.de>
parents:
2534
diff
changeset
|
1230 |
"Helper for executing and waiting for OS processes. |
2499
95392696facc
Fix race condition when waiting for SIGCHLD.
Stefan Vogel <sv@exept.de>
parents:
2468
diff
changeset
|
1231 |
aBlockReturningPid is evaluated and supposed to return |
95392696facc
Fix race condition when waiting for SIGCHLD.
Stefan Vogel <sv@exept.de>
parents:
2468
diff
changeset
|
1232 |
the process-id of an OS-process or nil. |
10747 | 1233 |
To avoid race conditions, the OS-process must be started |
2499
95392696facc
Fix race condition when waiting for SIGCHLD.
Stefan Vogel <sv@exept.de>
parents:
2468
diff
changeset
|
1234 |
within the block. |
95392696facc
Fix race condition when waiting for SIGCHLD.
Stefan Vogel <sv@exept.de>
parents:
2468
diff
changeset
|
1235 |
ActionBlock will be called with an OSProcessStatus as arg if the |
95392696facc
Fix race condition when waiting for SIGCHLD.
Stefan Vogel <sv@exept.de>
parents:
2468
diff
changeset
|
1236 |
status of the OS process changes (e.g. the process terminates). |
20053 | 1237 |
The method returns the value from aBlockReturningPid (i.e. a pid or nil)." |
2611
9a575397bf9a
fixed davids monitorPid (dont wait a second; dont do busy poll ...)
Claus Gittinger <cg@exept.de>
parents:
2534
diff
changeset
|
1238 |
|
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1239 |
|pid wasBlocked| |
16338 | 1240 |
|
1241 |
"/ aBlock will be evaluated: |
|
1242 |
"/ on unix: as soon as a SIGCHLD interrupt for pid has been received. |
|
1243 |
"/ on win: as soon as a select for the pid handle returns |
|
1244 |
||
1245 |
OperatingSystem enableChildSignalInterrupts. "/ no-op in windows |
|
1246 |
wasBlocked := OperatingSystem blockInterrupts. |
|
1247 |
"/ start the OS-Process |
|
1248 |
pid := aBlockReturningPid value. |
|
1249 |
pid notNil ifTrue:[ |
|
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1250 |
osChildExitActions at:pid put:actionBlock. |
840
523533898acd
Reset sigCHLD interrupt handler, when no more processes are being waited for.
Stefan Vogel <sv@exept.de>
parents:
829
diff
changeset
|
1251 |
]. |
16338 | 1252 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
2499
95392696facc
Fix race condition when waiting for SIGCHLD.
Stefan Vogel <sv@exept.de>
parents:
2468
diff
changeset
|
1253 |
^ pid |
95392696facc
Fix race condition when waiting for SIGCHLD.
Stefan Vogel <sv@exept.de>
parents:
2468
diff
changeset
|
1254 |
|
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1255 |
"Created: / 25.3.1997 / 10:54:56 / stefan" |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1256 |
"Modified: / 25.3.1997 / 11:21:05 / stefan" |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1257 |
"Modified: / 15.4.1997 / 11:55:57 / David" |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1258 |
"Modified: / 27.4.1999 / 20:09:38 / cg" |
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
|
1259 |
! |
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
|
1260 |
|
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
|
1261 |
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
|
1262 |
"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
|
1263 |
|
2966 | 1264 |
osChildExitActions removeKey:pid ifAbsent:nil. |
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
|
1265 |
|
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
|
1266 |
"Created: 12.4.1996 / 19:01:59 / cg" |
699 | 1267 |
! ! |
1268 |
||
1269 |
!ProcessorScheduler methodsFor:'primitive process primitives'! |
|
1270 |
||
1271 |
scheduleForInterrupt:aProcess |
|
1272 |
"make aProcess evaluate its pushed interrupt block(s)" |
|
1273 |
||
1092
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
1274 |
self scheduleInterruptActionsOf:aProcess. |
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1275 |
aProcess state ~~ #stopped ifTrue:[ |
18295 | 1276 |
" |
1277 |
make the process runnable |
|
1278 |
" |
|
1279 |
self resume:aProcess |
|
699 | 1280 |
] |
1092
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
1281 |
|
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1282 |
"Modified: / 24.8.1998 / 18:31:32 / cg" |
1092
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
1283 |
! |
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
1284 |
|
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
1285 |
scheduleInterruptActionsOf:aProcess |
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
1286 |
"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
|
1287 |
when resumed." |
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
1288 |
|
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1289 |
|id| |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1290 |
|
1092
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
1291 |
aProcess isNil ifTrue:[^ self]. |
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
1292 |
aProcess == activeProcess ifTrue:[^ self]. |
2a8acc60f5b5
added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents:
1086
diff
changeset
|
1293 |
|
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1294 |
id := aProcess id. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1295 |
self class threadInterrupt:id. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1296 |
|
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1297 |
"Created: 5.3.1996 / 17:25:55 / cg" |
699 | 1298 |
! |
1299 |
||
1300 |
threadSwitch:aProcess |
|
1301 |
"continue execution in aProcess. |
|
1783
be7402f74d94
hide timerInterrupt & ioInterrupt contexts when switching
Claus Gittinger <cg@exept.de>
parents:
1780
diff
changeset
|
1302 |
WARNING: this is a low level entry, no process administration is done here" |
699 | 1303 |
|
3644 | 1304 |
|id pri ok oldProcess oldPri oldId p nm singleStep wasBlocked| |
699 | 1305 |
|
1306 |
(aProcess isNil or:[aProcess == activeProcess]) ifTrue:[^ self]. |
|
1307 |
||
1308 |
wasBlocked := OperatingSystem blockInterrupts. |
|
1309 |
||
1310 |
oldProcess := activeProcess. |
|
2262 | 1311 |
oldId := activeProcessId. |
699 | 1312 |
oldPri := currentPriority. |
1313 |
||
1314 |
id := aProcess id. |
|
25422
3b02b0f1f647
Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
23107
diff
changeset
|
1315 |
id class == SmallInteger ifFalse:[ |
3b02b0f1f647
Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
23107
diff
changeset
|
1316 |
Logger error: 'Bad id in process %1' with: aProcess. |
3b02b0f1f647
Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
23107
diff
changeset
|
1317 |
]. |
3b02b0f1f647
Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
23107
diff
changeset
|
1318 |
|
699 | 1319 |
pri := aProcess priority. |
1320 |
singleStep := aProcess isSingleStepping. |
|
1321 |
aProcess state:#active. |
|
1322 |
oldProcess setStateTo:#run if:#active. |
|
1323 |
||
5449 | 1324 |
currentPriority := pri. |
699 | 1325 |
activeProcess := aProcess. |
2262 | 1326 |
activeProcessId := id. |
12958 | 1327 |
|
1328 |
" |
|
1329 |
no interrupts now - activeProcess has already been changed |
|
20810 | 1330 |
(don't add any message sends here) |
12958 | 1331 |
" |
1332 |
"/ ok := self threadSwitchFrom:oldProcess to:aProcess id:id singleStep:singleStep. |
|
1333 |
%{ |
|
1334 |
extern OBJ ___threadSwitch(); |
|
1335 |
||
1336 |
if (__isSmallInteger(id)) { |
|
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1337 |
ok = ___threadSwitch(__context, __intVal(id), (singleStep == true) ? 1 : 0, 0); |
12958 | 1338 |
} else { |
20810 | 1339 |
ok = false; |
12958 | 1340 |
} |
1341 |
%}. |
|
5449 | 1342 |
|
699 | 1343 |
"time passes spent in some other process ... |
1344 |
... here again" |
|
1345 |
||
1346 |
p := activeProcess. |
|
1347 |
activeProcess := oldProcess. |
|
2262 | 1348 |
activeProcessId := oldId. |
699 | 1349 |
currentPriority := oldProcess priority. |
1350 |
||
21009 | 1351 |
ok ~~ true ifTrue:[ |
20810 | 1352 |
" |
1353 |
switch failed for some reason - |
|
1354 |
destroy (hard-terminate) the bad process. |
|
1355 |
This happens when: |
|
1356 |
- the stack went above the absolute limit |
|
1357 |
(VM switches back to scheduler) |
|
1358 |
- a halted process cannot execute its interrupt |
|
1359 |
actions (win32 only) |
|
1360 |
" |
|
21009 | 1361 |
id := p id. |
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1362 |
(id ~~ SysProcessId and:[id notNil]) ifTrue:[ |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1363 |
'Processor [warning]: problem with process ' errorPrint. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1364 |
id errorPrint. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1365 |
(nm := p name) notNil ifTrue:[ |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1366 |
' (' errorPrint. nm errorPrint. ')' errorPrint. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1367 |
]. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1368 |
|
21009 | 1369 |
ok == #halted ifTrue:[ |
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1370 |
"/ that process was halted (win32 only) |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1371 |
p state:#halted. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1372 |
'; stopped it.' errorPrintCR. |
21009 | 1373 |
self suspend:p. |
1374 |
] ifFalse:[ |
|
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1375 |
'; hard-terminate it.' errorPrintCR. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1376 |
'Processor [info]: cleanup may take a while if stack is huge' infoPrintCR. |
21009 | 1377 |
p state:#cleanup. |
1378 |
self terminateNoSignal:p. |
|
20810 | 1379 |
] |
1380 |
] |
|
699 | 1381 |
]. |
1382 |
zombie notNil ifTrue:[ |
|
21284 | 1383 |
"delayed processing of terminated process (see #terminateNoSignal)" |
20810 | 1384 |
self class threadDestroy:zombie. |
1385 |
zombie := nil |
|
1783
be7402f74d94
hide timerInterrupt & ioInterrupt contexts when switching
Claus Gittinger <cg@exept.de>
parents:
1780
diff
changeset
|
1386 |
]. |
be7402f74d94
hide timerInterrupt & ioInterrupt contexts when switching
Claus Gittinger <cg@exept.de>
parents:
1780
diff
changeset
|
1387 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
12958 | 1388 |
|
1389 |
"Modified: / 23-07-2010 / 10:32:11 / cg" |
|
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1390 |
"Modified (format): / 24-01-2017 / 17:50:12 / stefan" |
1787
32632b6f969d
remember threadSwitch:from: idea for later implementation;
Claus Gittinger <cg@exept.de>
parents:
1783
diff
changeset
|
1391 |
! ! |
32632b6f969d
remember threadSwitch:from: idea for later implementation;
Claus Gittinger <cg@exept.de>
parents:
1783
diff
changeset
|
1392 |
|
1981
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1393 |
!ProcessorScheduler methodsFor:'priority constants'! |
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1394 |
|
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1395 |
highIOPriority |
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1396 |
"not currently used - for ST80 compatibility only" |
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1397 |
|
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1398 |
^ 16 "claus: is this ok ?" |
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1399 |
|
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1400 |
"Created: 15.11.1996 / 11:42:39 / cg" |
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1401 |
! |
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1402 |
|
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1403 |
highestPriority |
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1404 |
"return the highest priority value (normal) processes can have." |
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1405 |
|
10747 | 1406 |
"must be below schedulingPriority - |
1981
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1407 |
otherwise scheduler could be blocked ... |
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1408 |
" |
10747 | 1409 |
^ HighestPriority |
1981
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1410 |
! |
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1411 |
|
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1412 |
lowIOPriority |
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1413 |
"not currently used - for ST80 compatibility only" |
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1414 |
|
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1415 |
^ 2 "claus: is this ok ?" |
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1416 |
! |
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1417 |
|
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1418 |
lowestPriority |
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1419 |
"return the lowest priority value" |
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1420 |
|
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1421 |
^ 1 "do not change this - its not variable" |
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1422 |
! |
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1423 |
|
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1424 |
schedulingPriority |
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1425 |
"return the priority at which the scheduler runs." |
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1426 |
|
10747 | 1427 |
"must be above highestPriority - |
1981
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1428 |
otherwise scheduler could be blocked ... |
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1429 |
" |
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1430 |
^ SchedulingPriority |
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1431 |
! |
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1432 |
|
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1433 |
systemBackgroundPriority |
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1434 |
"return the priority, at which background system processing |
7076 | 1435 |
should take place." |
1981
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1436 |
|
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1437 |
^ 4 |
7076 | 1438 |
|
1439 |
" |
|
1440 |
Processor systemBackgroundPriority |
|
1441 |
" |
|
1981
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1442 |
! |
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1443 |
|
2190 | 1444 |
timeSlicingPriorityLimit |
1445 |
"return the priority, above which no timeslicing takes place |
|
1446 |
(i.e. processes running at a higher priority are not preempted). |
|
1447 |
This is only effective, if preemption is enabled." |
|
1448 |
||
1449 |
^ TimeSlicingPriorityLimit |
|
1450 |
! |
|
1451 |
||
2191 | 1452 |
timingPriority |
1453 |
"return the priority, at which all timing takes place (messageTally, |
|
1454 |
delay etc.)" |
|
1455 |
||
1456 |
^ TimingPriority |
|
1457 |
! |
|
1458 |
||
1981
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1459 |
userBackgroundPriority |
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1460 |
"return the priority, at which background user (non-interactive) processing |
7076 | 1461 |
should take place." |
1981
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1462 |
|
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1463 |
^ 6 |
7076 | 1464 |
|
1465 |
" |
|
1466 |
Processor userBackgroundPriority |
|
1467 |
" |
|
1981
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1468 |
! |
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1469 |
|
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1470 |
userInterruptPriority |
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1471 |
"return the priority, at which the event scheduler runs - i.e. |
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1472 |
all processes running at a lower priority are interruptable by Cntl-C |
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1473 |
or the timer. Processes running at higher prio will not be interrupted." |
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1474 |
|
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1475 |
^ UserInterruptPriority |
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1476 |
! |
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1477 |
|
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1478 |
userSchedulingPriority |
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1479 |
"return the priority, at which all normal user (interactive) processing |
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1480 |
takes place" |
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1481 |
|
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1482 |
^ UserSchedulingPriority |
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1483 |
! ! |
de394714f50b
added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents:
1836
diff
changeset
|
1484 |
|
699 | 1485 |
!ProcessorScheduler methodsFor:'private'! |
1486 |
||
1487 |
remember:aProcess |
|
1488 |
"remember aProcess for later disposal (where the underlying |
|
1489 |
system resources have to be freed)." |
|
1490 |
||
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1491 |
|newShadow oldId wasBlocked |
699 | 1492 |
oldSize "{ Class: SmallInteger }" |
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1493 |
index "{ Class: SmallInteger }" |
1787
32632b6f969d
remember threadSwitch:from: idea for later implementation;
Claus Gittinger <cg@exept.de>
parents:
1783
diff
changeset
|
1494 |
sz "{ Class: SmallInteger }" | |
699 | 1495 |
|
1496 |
wasBlocked := OperatingSystem blockInterrupts. |
|
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1497 |
index := 1. |
699 | 1498 |
sz := KnownProcessIds size. |
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1499 |
[index <= sz] whileTrue:[ |
18295 | 1500 |
(KnownProcesses at:index) isNil ifTrue:[ |
1501 |
oldId := KnownProcessIds at:index. |
|
1502 |
oldId notNil ifTrue:[ |
|
1503 |
self class threadDestroy:oldId. |
|
1504 |
]. |
|
1505 |
KnownProcesses at:index put:aProcess. |
|
1506 |
KnownProcessIds at:index put:aProcess id. |
|
1507 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
1508 |
^ self |
|
1509 |
]. |
|
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1510 |
index := index + 1 |
699 | 1511 |
]. |
1512 |
||
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1513 |
KnownProcessIds grow:index. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1514 |
KnownProcessIds at:index put:aProcess id. |
699 | 1515 |
|
1516 |
oldSize := KnownProcesses size. |
|
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1517 |
(index > oldSize) ifTrue:[ |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1518 |
newShadow := WeakArray new:(oldSize * 2). |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1519 |
newShadow addDependent:self class. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1520 |
newShadow replaceFrom:1 with:KnownProcesses. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1521 |
KnownProcesses := newShadow |
699 | 1522 |
]. |
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1523 |
KnownProcesses at:index put:aProcess. |
699 | 1524 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
2091
c11bb3e29a1b
Use dependent mechamism of WeakArray instead of #watcher.
Stefan Vogel <sv@exept.de>
parents:
1981
diff
changeset
|
1525 |
|
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1526 |
"Modified: 7.1.1997 / 16:48:39 / stefan" |
699 | 1527 |
! |
1528 |
||
1529 |
unRemember:aProcess |
|
1530 |
"forget aProcess - dispose processing will not consider this one" |
|
1531 |
||
1532 |
|index wasBlocked| |
|
1533 |
||
1534 |
wasBlocked := OperatingSystem blockInterrupts. |
|
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1535 |
index := KnownProcesses identityIndexOf:aProcess. |
699 | 1536 |
index ~~ 0 ifTrue:[ |
18295 | 1537 |
KnownProcessIds at:index put:nil. |
1538 |
KnownProcesses at:index put:nil. |
|
699 | 1539 |
]. |
1540 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
1541 |
! ! |
|
1542 |
||
1543 |
!ProcessorScheduler methodsFor:'process creation'! |
|
1544 |
||
1545 |
newProcessFor:aProcess |
|
1546 |
"create a physical (VM-) process for aProcess. |
|
1547 |
Return true if ok, false if something went wrong. |
|
10747 | 1548 |
The process is not scheduled; to start it running, |
1549 |
it needs a Process>>resume. Once resumed, the process will later |
|
699 | 1550 |
get control in its #start method." |
1551 |
||
1552 |
|id| |
|
1553 |
||
1554 |
id := self class threadCreate:aProcess withId:nil. |
|
1555 |
aProcess setId:id state:#light. "meaning: has no stack yet" |
|
1556 |
self remember:aProcess. |
|
1557 |
! |
|
1558 |
||
1559 |
newProcessFor:aProcess withId:idWant |
|
1560 |
"private entry for Process restart - do not use in your program" |
|
1561 |
||
1836
08a200835cc8
process restart is different if done at image restart time.
Claus Gittinger <cg@exept.de>
parents:
1793
diff
changeset
|
1562 |
idWant isNil ifTrue:[ |
18295 | 1563 |
self newProcessFor:aProcess. |
1564 |
^ true. |
|
1836
08a200835cc8
process restart is different if done at image restart time.
Claus Gittinger <cg@exept.de>
parents:
1793
diff
changeset
|
1565 |
]. |
08a200835cc8
process restart is different if done at image restart time.
Claus Gittinger <cg@exept.de>
parents:
1793
diff
changeset
|
1566 |
|
699 | 1567 |
(self class threadCreate:aProcess withId:idWant) ~~ idWant ifTrue:[ |
18295 | 1568 |
^ false |
699 | 1569 |
]. |
1570 |
||
1571 |
aProcess state:#light. "meaning: has no stack yet" |
|
1572 |
self remember:aProcess. |
|
1573 |
^ true |
|
1836
08a200835cc8
process restart is different if done at image restart time.
Claus Gittinger <cg@exept.de>
parents:
1793
diff
changeset
|
1574 |
|
08a200835cc8
process restart is different if done at image restart time.
Claus Gittinger <cg@exept.de>
parents:
1793
diff
changeset
|
1575 |
"Modified: 28.10.1996 / 19:14:28 / cg" |
699 | 1576 |
! ! |
1577 |
||
1578 |
!ProcessorScheduler methodsFor:'queries'! |
|
1579 |
||
1580 |
activeProcessIsSystemProcess |
|
1581 |
"return true if the active process is a system process, |
|
1582 |
which should not be suspended." |
|
1583 |
||
2637
0d8508bedf06
Move #isSystemProcess from ProcessorScheduler to Process.
Stefan Vogel <sv@exept.de>
parents:
2626
diff
changeset
|
1584 |
^ activeProcess isSystemProcess |
699 | 1585 |
|
1586 |
" |
|
1587 |
Processor activeProcessIsSystemProcess |
|
1588 |
" |
|
2637
0d8508bedf06
Move #isSystemProcess from ProcessorScheduler to Process.
Stefan Vogel <sv@exept.de>
parents:
2626
diff
changeset
|
1589 |
|
0d8508bedf06
Move #isSystemProcess from ProcessorScheduler to Process.
Stefan Vogel <sv@exept.de>
parents:
2626
diff
changeset
|
1590 |
"Modified: 17.4.1997 / 12:59:33 / stefan" |
699 | 1591 |
! |
1592 |
||
20754 | 1593 |
anyScheduledWindowGroupAtAll |
1594 |
"return true, if there is any window group with active topviews. |
|
1595 |
This is used to determine if we should stop scheduling |
|
1596 |
in standAlone applications." |
|
1597 |
||
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1598 |
Screen notNil ifTrue:[ |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1599 |
Screen allScreens notEmptyOrNil ifTrue:[ |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1600 |
WindowGroup scheduledWindowGroups notEmptyOrNil ifTrue:[^ true]. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1601 |
]. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1602 |
]. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1603 |
^ false |
20754 | 1604 |
|
1605 |
" |
|
1606 |
Processor anyScheduledWindowGroupAtAll |
|
1607 |
" |
|
1608 |
! |
|
1609 |
||
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
|
1610 |
anyUserProcessAtAll |
18940 | 1611 |
"return true, if there is any user process still running, |
1612 |
or waiting on a semaphore. |
|
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
|
1613 |
This is used to determine if we should stop scheduling |
2193 | 1614 |
in standAlone applications. |
20736 | 1615 |
A user process has a non-zero processGroup. |
1616 |
Should be called with interrupts blocked." |
|
1617 |
||
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1618 |
|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
|
1619 |
|
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
|
1620 |
prio := HighestPriority. |
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1621 |
|
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
|
1622 |
listArray := quiescentProcessLists. |
1571
8d00e6b97ca7
changed #anyUserProcessAtAll,
Claus Gittinger <cg@exept.de>
parents:
1473
diff
changeset
|
1623 |
|
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1624 |
[prio >= 1] whileTrue:[ |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1625 |
l := listArray at:prio. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1626 |
l notNil ifTrue:[ |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1627 |
l linksDo:[:aProcess | |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1628 |
aProcess isUserProcess ifTrue:[ |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1629 |
"/ 'anyUserProcess: found quiescent ' _errorPrint. aProcess asString _errorPrintCR. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1630 |
^ true. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1631 |
] |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1632 |
] |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1633 |
]. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1634 |
prio := prio - 1 |
25422
3b02b0f1f647
Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
23107
diff
changeset
|
1635 |
]. |
3b02b0f1f647
Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
23107
diff
changeset
|
1636 |
|
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1637 |
(scheduledProcesses notNil |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1638 |
and:[scheduledProcesses contains:[:p | p notNil and:[p isUserProcess and:[p state ~~ #dead]] ]]) ifTrue:[ |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1639 |
"/ 'anyUserProcess: found scheduled ' _errorPrint. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1640 |
"/ (scheduledProcesses detect:[:p | p notNil and:[p isUserProcess and:[p state ~~ #dead]] ]) asString _errorPrintCR. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1641 |
^ true. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1642 |
]. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1643 |
|
18940 | 1644 |
"/ any user process waiting on a sema? |
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1645 |
(readSemaphoreArray contains:[:sema | |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1646 |
sema notNil and:[sema waitingProcesses contains:[:p | p notNil and:[p isUserProcess and:[p state ~~ #dead]] ]]] |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1647 |
) ifTrue:[ |
20883 | 1648 |
"/ 'anyUserProcess: found on read sema' _errorPrintCR. |
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1649 |
^ true. |
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
|
1650 |
]. |
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1651 |
(writeSemaphoreArray contains:[:sema | |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1652 |
sema notNil and:[sema waitingProcesses contains:[:p | p notNil and:[p isUserProcess and:[p state ~~ #dead]] ]]] |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1653 |
) ifTrue:[ |
20883 | 1654 |
"/ 'anyUserProcess: found on write sema' _errorPrintCR. |
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1655 |
^ true. |
18940 | 1656 |
]. |
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1657 |
(timeoutSemaphoreArray contains:[:sema | |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1658 |
sema notNil and:[sema waitingProcesses contains:[:p | p notNil and:[p isUserProcess and:[p state ~~ #dead]] ]]] |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1659 |
) ifTrue:[ |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1660 |
"/ 'anyUserProcess: found on timeout sema' _errorPrintCR. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1661 |
^ true. |
25422
3b02b0f1f647
Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
23107
diff
changeset
|
1662 |
]. |
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1663 |
(timeoutProcessArray contains:[:p | p notNil and:[p isUserProcess] ] |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1664 |
) ifTrue:[ |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1665 |
^ true. |
18940 | 1666 |
]. |
1667 |
||
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
|
1668 |
^ false |
1571
8d00e6b97ca7
changed #anyUserProcessAtAll,
Claus Gittinger <cg@exept.de>
parents:
1473
diff
changeset
|
1669 |
|
8d00e6b97ca7
changed #anyUserProcessAtAll,
Claus Gittinger <cg@exept.de>
parents:
1473
diff
changeset
|
1670 |
" |
10747 | 1671 |
Processor anyUserProcessAtAll |
1571
8d00e6b97ca7
changed #anyUserProcessAtAll,
Claus Gittinger <cg@exept.de>
parents:
1473
diff
changeset
|
1672 |
" |
8d00e6b97ca7
changed #anyUserProcessAtAll,
Claus Gittinger <cg@exept.de>
parents:
1473
diff
changeset
|
1673 |
|
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1674 |
"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
|
1675 |
! |
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
|
1676 |
|
699 | 1677 |
highestPriorityRunnableProcess |
1678 |
"return the highest prio runnable process" |
|
1679 |
||
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1680 |
|listArray l p prio "{ Class: SmallInteger }" |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1681 |
wasBlocked| |
699 | 1682 |
|
1683 |
prio := HighestPriority. |
|
3745 | 1684 |
wasBlocked := OperatingSystem blockInterrupts. |
1685 |
||
699 | 1686 |
listArray := quiescentProcessLists. |
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1687 |
[prio >= 1] whileTrue:[ |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1688 |
l := listArray at:prio. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1689 |
l notNil ifTrue:[ |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1690 |
l notEmpty ifTrue:[ |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1691 |
p := l firstLink. |
18295 | 1692 |
" |
1693 |
if it got corrupted somehow ... |
|
1694 |
" |
|
1695 |
p isDead ifTrue:[ |
|
25422
3b02b0f1f647
Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
23107
diff
changeset
|
1696 |
Logger warning:'Processor: dead process removed'. |
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1697 |
l removeFirst. |
18295 | 1698 |
p := nil. |
1699 |
]. |
|
1700 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
1701 |
^ p |
|
1702 |
] |
|
1703 |
]. |
|
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1704 |
prio := prio - 1 |
699 | 1705 |
]. |
3745 | 1706 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
699 | 1707 |
^ nil |
1086 | 1708 |
|
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1709 |
"Modified: 12.2.1997 / 12:41:49 / cg" |
699 | 1710 |
! |
1711 |
||
5389 | 1712 |
isDispatching |
1713 |
^ dispatching |
|
1714 |
! |
|
1715 |
||
1177 | 1716 |
isPureEventDriven |
1717 |
"this is temporary - (maybe not :-). |
|
1718 |
you can run ST/X either with or without processes. |
|
1719 |
Without, there is conceptionally a single process handling all |
|
1720 |
outside events and timeouts. This has some negative implications |
|
1721 |
(Debugger is ugly), but allows a fully portable ST/X without any |
|
1722 |
assembler support - i.e. quick portability. |
|
1723 |
The PureEvent flag will automatically be set if the runtime system |
|
1724 |
does not support threads - otherwise, it can be set manually |
|
1725 |
(from rc-file). |
|
1726 |
" |
|
1727 |
||
1728 |
^ PureEventDriven |
|
1729 |
||
1730 |
"Created: 13.4.1996 / 20:31:31 / cg" |
|
1731 |
! |
|
1732 |
||
2191 | 1733 |
isTimeSlicing |
1734 |
"return true, if in timeslicing mode" |
|
1735 |
||
1736 |
^ timeSliceProcess notNil |
|
1737 |
||
1738 |
" |
|
1739 |
Processor isTimeSlicing |
|
1740 |
" |
|
1741 |
||
1742 |
"Modified: 17.1.1997 / 17:48:41 / cg" |
|
16623 | 1743 |
! |
1744 |
||
1745 |
processWithId:anInteger |
|
1746 |
"answer the process with id anInteger, or nil if there is none" |
|
1747 |
||
16624 | 1748 |
|wasBlocked slot process| |
1749 |
||
1750 |
wasBlocked := OperatingSystem blockInterrupts. |
|
16623 | 1751 |
|
1752 |
slot := KnownProcessIds indexOf:anInteger. |
|
16624 | 1753 |
slot ~~ 0 ifTrue:[ |
18295 | 1754 |
process := KnownProcesses at:slot ifAbsent:[]. |
16624 | 1755 |
]. |
1756 |
||
25422
3b02b0f1f647
Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
23107
diff
changeset
|
1757 |
wasBlocked ifFalse:[ OperatingSystem unblockInterrupts ]. |
16624 | 1758 |
|
1759 |
"Take care, the process may already have been collected" |
|
1760 |
process == 0 ifTrue:[ |
|
18295 | 1761 |
^ nil. |
16623 | 1762 |
]. |
16624 | 1763 |
^ process. |
16623 | 1764 |
|
1765 |
" |
|
18295 | 1766 |
Processor processWithId:4 |
1767 |
Processor processWithId:4711 |
|
16623 | 1768 |
" |
21118 | 1769 |
! |
1770 |
||
1771 |
processesWithGroupId:anInteger |
|
1772 |
"answer a collection of processes with processGroupId, anInteger" |
|
1773 |
||
1774 |
|wasBlocked coll| |
|
1775 |
||
1776 |
coll := OrderedCollection new. |
|
1777 |
||
1778 |
wasBlocked := OperatingSystem blockInterrupts. |
|
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1779 |
KnownProcesses validElementsDo:[:eachProcess| |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1780 |
eachProcess processGroupId = anInteger ifTrue:[ |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1781 |
coll add:eachProcess. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1782 |
]. |
21118 | 1783 |
]. |
1784 |
||
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1785 |
wasBlocked ifFalse:[ |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1786 |
OperatingSystem unblockInterrupts. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1787 |
]. |
21118 | 1788 |
|
1789 |
^ coll. |
|
1790 |
||
1791 |
" |
|
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1792 |
Processor processesWithGroupId:0 |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1793 |
Processor processesWithGroupId:4711 |
21118 | 1794 |
" |
699 | 1795 |
! ! |
1796 |
||
1797 |
!ProcessorScheduler methodsFor:'scheduling'! |
|
1798 |
||
1799 |
changePriority:prio for:aProcess |
|
1800 |
"change the priority of aProcess" |
|
1801 |
||
1802 |
|oldList newList oldPrio newPrio wasBlocked| |
|
1803 |
||
1804 |
oldPrio := aProcess priority. |
|
1805 |
oldPrio == prio ifTrue:[^ self]. |
|
1042 | 1806 |
aProcess == scheduler ifTrue:[^ self]. |
699 | 1807 |
|
1808 |
" |
|
1809 |
check for valid argument |
|
1810 |
" |
|
1811 |
newPrio := prio. |
|
1812 |
newPrio < 1 ifTrue:[ |
|
18295 | 1813 |
newPrio := 1. |
699 | 1814 |
] ifFalse:[ |
18295 | 1815 |
newPrio > HighestPriority ifTrue:[ |
1816 |
newPrio := HighestPriority |
|
1817 |
] |
|
699 | 1818 |
]. |
1819 |
||
1042 | 1820 |
[ |
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1821 |
wasBlocked := OperatingSystem blockInterrupts. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1822 |
|
18295 | 1823 |
aProcess setPriority:newPrio. |
1824 |
||
1825 |
oldList := quiescentProcessLists at:oldPrio. |
|
1826 |
oldList notNil ifTrue:[ |
|
1827 |
(oldList removeIdentical:aProcess ifAbsent:nil) notNil ifTrue:[ |
|
1828 |
newList := quiescentProcessLists at:newPrio. |
|
1829 |
newList isNil ifTrue:[ |
|
1830 |
quiescentProcessLists at:newPrio put:(newList := LinkedList new). |
|
1831 |
]. |
|
1832 |
newList addLast:aProcess. |
|
1833 |
||
25422
3b02b0f1f647
Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
23107
diff
changeset
|
1834 |
"if it's the current process lowering its prio |
18295 | 1835 |
or another one raising, we have to reschedule" |
1836 |
||
1837 |
aProcess == activeProcess ifTrue:[ |
|
1838 |
currentPriority := newPrio. |
|
1839 |
newPrio < oldPrio ifTrue:[ |
|
1840 |
self threadSwitch:scheduler. |
|
1841 |
] |
|
1842 |
] ifFalse:[ |
|
1843 |
newPrio > currentPriority ifTrue:[ |
|
1844 |
self threadSwitch:aProcess. |
|
1845 |
] |
|
1846 |
]. |
|
1847 |
timeSliceNeededSemaphore notNil ifTrue:[ |
|
1848 |
"/ tell timeslicer, that some work might be needed... |
|
1849 |
timeSliceNeededSemaphore signalIf. |
|
1850 |
] |
|
1851 |
] |
|
1852 |
] |
|
6421
58dca33cf0fc
#valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents:
6376
diff
changeset
|
1853 |
] ensure:[ |
18295 | 1854 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
1042 | 1855 |
] |
1032 | 1856 |
|
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1857 |
"Modified: / 4.8.1998 / 00:08:54 / cg" |
699 | 1858 |
! |
1859 |
||
1860 |
interruptActive |
|
10747 | 1861 |
"interrupt the current process |
1783
be7402f74d94
hide timerInterrupt & ioInterrupt contexts when switching
Claus Gittinger <cg@exept.de>
parents:
1780
diff
changeset
|
1862 |
- this message is sent by the VM, when a process is about to be switched to, |
be7402f74d94
hide timerInterrupt & ioInterrupt contexts when switching
Claus Gittinger <cg@exept.de>
parents:
1780
diff
changeset
|
1863 |
and that process has the interrupted flag bit set. |
be7402f74d94
hide timerInterrupt & ioInterrupt contexts when switching
Claus Gittinger <cg@exept.de>
parents:
1780
diff
changeset
|
1864 |
Pass the interrupt to the process, which may do whatever it likes with it." |
be7402f74d94
hide timerInterrupt & ioInterrupt contexts when switching
Claus Gittinger <cg@exept.de>
parents:
1780
diff
changeset
|
1865 |
|
9991
a03847e11498
make #interruptActive returnable for better debugging
Stefan Vogel <sv@exept.de>
parents:
9452
diff
changeset
|
1866 |
<context: #return> |
25422
3b02b0f1f647
Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
23107
diff
changeset
|
1867 |
<resource: #skipInDebuggersWalkBack> |
9991
a03847e11498
make #interruptActive returnable for better debugging
Stefan Vogel <sv@exept.de>
parents:
9452
diff
changeset
|
1868 |
|
1791 | 1869 |
|s| |
1870 |
||
1871 |
"/ hide those intermediate scheduler contexts; |
|
10747 | 1872 |
"/ the interrupt block should think it was called right |
1791 | 1873 |
"/ from the originally interrupted context |
1874 |
||
1875 |
s := thisContext sender. |
|
9991
a03847e11498
make #interruptActive returnable for better debugging
Stefan Vogel <sv@exept.de>
parents:
9452
diff
changeset
|
1876 |
s selector == #threadSwitchFrom:to:id:singleStep: ifTrue:[ |
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1877 |
s := s sender. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1878 |
s selector == #threadSwitch: ifTrue:[ |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1879 |
s := s sender. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1880 |
s selector == #timerInterrupt ifTrue:[ |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1881 |
s := s sender |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1882 |
] |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1883 |
] |
1791 | 1884 |
]. |
1885 |
||
2727 | 1886 |
"/ the returned value here has a subtle effect: |
1887 |
"/ if false, the interrupt is assumed to be not taken, |
|
1888 |
"/ and will be redelivered. |
|
2724 | 1889 |
^ activeProcess interruptedIn:s |
1783
be7402f74d94
hide timerInterrupt & ioInterrupt contexts when switching
Claus Gittinger <cg@exept.de>
parents:
1780
diff
changeset
|
1890 |
|
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1891 |
"Modified: 20.10.1996 / 17:06:48 / cg" |
699 | 1892 |
! |
1893 |
||
3273
343ecdba9817
added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents:
3271
diff
changeset
|
1894 |
makeRunnable:aProcess |
14771 | 1895 |
"set aProcess runnable - but do not reschedule. |
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1896 |
Answer true, if a reschedule is required, false if not." |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1897 |
|
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1898 |
|l s pri wasBlocked| |
3273
343ecdba9817
added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents:
3271
diff
changeset
|
1899 |
|
343ecdba9817
added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents:
3271
diff
changeset
|
1900 |
"ignore, if process is already dead" |
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1901 |
(aProcess isNil or:[aProcess isDead]) ifTrue:[^ false]. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1902 |
|
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1903 |
s := aProcess state. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1904 |
s == #osWait ifTrue:[ |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1905 |
'Processor [warning]: bad resume: #osWait' errorPrintCR. |
18295 | 1906 |
"/ MiniDebugger enterWithMessage:'bad resume: state osWait'. |
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1907 |
^ false. |
14771 | 1908 |
]. |
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1909 |
s == #stopped ifTrue:[ |
18295 | 1910 |
"by definition, stopped processes cannot be resumed" |
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1911 |
^ false. |
14771 | 1912 |
]. |
3273
343ecdba9817
added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents:
3271
diff
changeset
|
1913 |
|
343ecdba9817
added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents:
3271
diff
changeset
|
1914 |
aProcess == activeProcess ifTrue:[ |
18295 | 1915 |
"special handling for waiting schedulers" |
1916 |
aProcess == scheduler ifTrue:[ |
|
1917 |
suspendScheduler := false. |
|
1918 |
]. |
|
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1919 |
^ false |
3273
343ecdba9817
added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents:
3271
diff
changeset
|
1920 |
]. |
343ecdba9817
added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents:
3271
diff
changeset
|
1921 |
|
343ecdba9817
added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents:
3271
diff
changeset
|
1922 |
wasBlocked := OperatingSystem blockInterrupts. |
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1923 |
|
3273
343ecdba9817
added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents:
3271
diff
changeset
|
1924 |
pri := aProcess priority. |
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1925 |
|
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1926 |
l := quiescentProcessLists at:pri. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1927 |
"if already running, ignore" |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1928 |
l notNil ifTrue:[ |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1929 |
(l identityIndexOf:aProcess) ~~ 0 ifTrue:[ |
18295 | 1930 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1931 |
^ false |
18295 | 1932 |
] |
3273
343ecdba9817
added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents:
3271
diff
changeset
|
1933 |
] ifFalse:[ |
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1934 |
l := LinkedList new. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1935 |
quiescentProcessLists at:pri put:l. |
3273
343ecdba9817
added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents:
3271
diff
changeset
|
1936 |
]. |
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1937 |
l addLast:aProcess. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1938 |
aProcess state:#run. |
3273
343ecdba9817
added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents:
3271
diff
changeset
|
1939 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
343ecdba9817
added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents:
3271
diff
changeset
|
1940 |
|
14771 | 1941 |
pri > currentPriority ifTrue:[ |
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1942 |
"must reschedule" |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1943 |
^ true. |
14771 | 1944 |
]. |
11590
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
1945 |
|
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1946 |
timeSliceNeededSemaphore notNil ifTrue:[ |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1947 |
"/ tell timeslicer, that some work might be needed... |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1948 |
timeSliceNeededSemaphore signalIf. |
14771 | 1949 |
]. |
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1950 |
^ false. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1951 |
|
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1952 |
"Modified: / 29.7.1996 / 12:07:37 / cg" |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1953 |
"Created: / 4.2.1998 / 20:58:28 / cg" |
3273
343ecdba9817
added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents:
3271
diff
changeset
|
1954 |
! |
343ecdba9817
added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents:
3271
diff
changeset
|
1955 |
|
699 | 1956 |
processTermination |
10747 | 1957 |
"sent by VM if the current process finished its startup block |
1958 |
without proper process termination. Lay him to rest now. |
|
1959 |
This can only happen, if something went wrong in Block>>newProcess, |
|
699 | 1960 |
since the block defined there always terminates itself." |
1961 |
||
1962 |
self terminateNoSignal:activeProcess. |
|
1963 |
self threadSwitch:scheduler |
|
1964 |
! |
|
1965 |
||
1966 |
reschedule |
|
1967 |
"switch to the highest prio runnable process. |
|
1968 |
The scheduler itself is always runnable, so we can do an unconditional switch |
|
2622 | 1969 |
to that one. This method is provided as a hook for primitive C code, |
1970 |
to allow giving up the CPU." |
|
699 | 1971 |
|
1972 |
^ self threadSwitch:scheduler |
|
1973 |
! |
|
1974 |
||
1975 |
resume:aProcess |
|
10747 | 1976 |
"set aProcess runnable - |
699 | 1977 |
if its prio is higher than the currently running prio, switch to it." |
1978 |
||
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1979 |
(self makeRunnable:aProcess) ifTrue:[ |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1980 |
"aProcess prio is higher; immediately transfer control to it" |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
1981 |
self threadSwitch:aProcess. |
1679
dbbfbd78b1e4
Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
1982 |
]. |
699 | 1983 |
! |
1984 |
||
1985 |
resumeForSingleSend:aProcess |
|
1986 |
"like resume, but let the process execute a single send only. |
|
3271 | 1987 |
This will be used by the debugger for single stepping." |
699 | 1988 |
|
1989 |
(aProcess isNil or:[aProcess == activeProcess]) ifTrue:[^ self]. |
|
1990 |
aProcess singleStep:true. |
|
1991 |
self resume:aProcess |
|
3271 | 1992 |
|
1993 |
"Modified: / 3.2.1998 / 01:08:08 / stefan" |
|
699 | 1994 |
! |
1995 |
||
1996 |
suspend:aProcess |
|
1997 |
"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
|
1998 |
If the process is the current one, reschedule. |
2155 | 1999 |
|
2000 |
Notice: |
|
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
2001 |
This method should only be called by Process>>suspend or |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
2002 |
Process>>suspendWithState:" |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
2003 |
|
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
2004 |
|pri l p wasBlocked| |
699 | 2005 |
|
2006 |
" |
|
2007 |
some debugging stuff |
|
2008 |
" |
|
2009 |
aProcess isNil ifTrue:[ |
|
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
2010 |
InvalidProcessSignal raiseRequestWith:aProcess errorString:'nil suspend'. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
2011 |
^ self |
699 | 2012 |
]. |
15658 | 2013 |
aProcess isDead ifTrue:[ |
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
2014 |
InvalidProcessSignal raiseRequestWith:aProcess errorString:'bad suspend: already dead'. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
2015 |
self threadSwitch:scheduler. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
2016 |
^ self |
699 | 2017 |
]. |
2018 |
aProcess == scheduler ifTrue:[ |
|
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
2019 |
"only the scheduler may suspend itself" |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
2020 |
activeProcess == scheduler ifTrue:[ |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
2021 |
suspendScheduler := true. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
2022 |
[suspendScheduler] whileTrue:[ |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
2023 |
self dispatch. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
2024 |
]. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
2025 |
^ self |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
2026 |
]. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
2027 |
|
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
2028 |
InvalidProcessSignal raiseRequestWith:aProcess errorString:'attempt to suspend scheduler'. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
2029 |
^ self |
699 | 2030 |
]. |
2031 |
||
21009 | 2032 |
(aProcess == activeProcess) ifTrue:[ |
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
2033 |
"this is a no-op if the process has no interrupt actions" |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
2034 |
aProcess interrupt. |
7863 | 2035 |
]. |
2036 |
||
699 | 2037 |
wasBlocked := OperatingSystem blockInterrupts. |
2038 |
||
2039 |
pri := aProcess priority. |
|
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
2040 |
l := quiescentProcessLists at:pri. |
699 | 2041 |
|
2042 |
"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
|
2043 |
the ifAbsent block, because [] is a shared cheap block, created at compile time |
699 | 2044 |
" |
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
2045 |
(l isNil or:[(l removeIdentical:aProcess ifAbsent:nil) isNil]) ifTrue:[ |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
2046 |
"/ 'Processor [warning]: bad suspend: process is not running' errorPrintCR. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
2047 |
"/ MiniDebugger enterWithMessage:'bad suspend: process is not running'. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
2048 |
aProcess == activeProcess ifTrue:[ |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
2049 |
self threadSwitch:scheduler. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
2050 |
]. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
2051 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
2052 |
^ self |
699 | 2053 |
]. |
2054 |
||
2055 |
(aProcess == activeProcess) ifTrue:[ |
|
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
2056 |
"we can immediately switch sometimes" |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
2057 |
l isEmpty ifTrue:[ |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
2058 |
p := scheduler |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
2059 |
] ifFalse:[ |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
2060 |
p := l firstLink |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
2061 |
]. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
2062 |
self threadSwitch:p |
699 | 2063 |
]. |
752
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
750
diff
changeset
|
2064 |
|
3745 | 2065 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
2066 |
||
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
2067 |
"Modified: / 23.9.1996 / 13:49:24 / stefan" |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
2068 |
"Modified: / 27.7.1998 / 23:34:59 / cg" |
699 | 2069 |
! |
2070 |
||
2071 |
terminate:aProcess |
|
20055 | 2072 |
"terminate aProcess. This is done by sending aProcess the terminateSignal, |
699 | 2073 |
which will evaluate any unwind blocks and finally do a hard terminate." |
2074 |
||
2075 |
aProcess terminate |
|
2076 |
! |
|
2077 |
||
2078 |
terminateActive |
|
2079 |
"terminate the current process (i.e. the running process kills itself). |
|
2080 |
The active process is sent the terminateSignal so it will evaluate any |
|
2081 |
unwind blocks and finally do a hard terminate. |
|
2082 |
This is sent for regular termination and by the VM, if the hard-stack limit |
|
2083 |
is reached. (i.e. a process did not repair things in a recursionInterrupt and |
|
2084 |
continued to grow its stack)" |
|
2085 |
||
2086 |
activeProcess terminate |
|
2087 |
! |
|
2088 |
||
2089 |
terminateActiveNoSignal |
|
2090 |
"hard terminate the active process, without sending any |
|
2091 |
terminate signal thus no unwind blocks are evaluated." |
|
2092 |
||
2093 |
self terminateNoSignal:activeProcess |
|
2094 |
! |
|
2095 |
||
2096 |
terminateNoSignal:aProcess |
|
2097 |
"hard terminate aProcess without sending the terminate signal, thus |
|
10747 | 2098 |
no unwind blocks or exitAction are performed in the process.. |
13577
5caa91ac2963
comment/format in: #terminateNoSignal:
Claus Gittinger <cg@exept.de>
parents:
13556
diff
changeset
|
2099 |
If it's not the current process, it is simply removed from its list |
699 | 2100 |
and physically destroyed. Otherwise (since we can't take away the chair |
10747 | 2101 |
we are sitting on), a switch is forced and the process |
2102 |
will be physically destroyed by the next running process. |
|
699 | 2103 |
(see zombie handling)" |
2104 |
||
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
2105 |
|pri id l wasBlocked| |
699 | 2106 |
|
2107 |
aProcess isNil ifTrue:[^ self]. |
|
20723 | 2108 |
|
807
e51ce11ca948
and dont allow quickTerminate as well.
Claus Gittinger <cg@exept.de>
parents:
806
diff
changeset
|
2109 |
aProcess == scheduler ifTrue:[ |
25422
3b02b0f1f647
Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
23107
diff
changeset
|
2110 |
InvalidProcessSignal raiseWith:aProcess errorString:'attempt to terminate scheduler'. |
3b02b0f1f647
Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
23107
diff
changeset
|
2111 |
^ self |
807
e51ce11ca948
and dont allow quickTerminate as well.
Claus Gittinger <cg@exept.de>
parents:
806
diff
changeset
|
2112 |
]. |
e51ce11ca948
and dont allow quickTerminate as well.
Claus Gittinger <cg@exept.de>
parents:
806
diff
changeset
|
2113 |
|
6990
a6bda971619f
race with threadDestroy (leftOver process-structures in VM);
ca
parents:
6940
diff
changeset
|
2114 |
wasBlocked := OperatingSystem blockInterrupts. |
a6bda971619f
race with threadDestroy (leftOver process-structures in VM);
ca
parents:
6940
diff
changeset
|
2115 |
|
699 | 2116 |
id := aProcess id. |
6990
a6bda971619f
race with threadDestroy (leftOver process-structures in VM);
ca
parents:
6940
diff
changeset
|
2117 |
id isNil ifTrue:[ "already dead" |
25422
3b02b0f1f647
Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
23107
diff
changeset
|
2118 |
self checkForEndOfDispatch. |
3b02b0f1f647
Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
23107
diff
changeset
|
2119 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
3b02b0f1f647
Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
23107
diff
changeset
|
2120 |
^ self |
10747 | 2121 |
]. |
699 | 2122 |
|
2123 |
aProcess setId:nil state:#dead. |
|
2124 |
||
2125 |
"remove the process from the runnable list" |
|
2126 |
||
2127 |
pri := aProcess priority. |
|
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
2128 |
l := quiescentProcessLists at:pri. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
2129 |
l notNil ifTrue:[ |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
2130 |
(l removeIdentical:aProcess ifAbsent:nil) "notNil ifTrue:[ |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
2131 |
l isEmpty ifTrue:[ |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
2132 |
quiescentProcessLists at:pri put:nil |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
2133 |
] |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
2134 |
]." |
699 | 2135 |
]. |
2136 |
||
2137 |
aProcess == activeProcess ifTrue:[ |
|
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
2138 |
" |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
2139 |
hard case - it's the currently running process |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
2140 |
we must have the next active process destroy this one |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
2141 |
(we cannot destroy the chair we are sitting on ... :-) |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
2142 |
" |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
2143 |
zombie notNil ifTrue:[ |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
2144 |
self error:'active process is zombie' mayProceed:true. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
2145 |
self class threadDestroy:zombie. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
2146 |
]. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
2147 |
|
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
2148 |
self unRemember:aProcess. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
2149 |
zombie := id. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
2150 |
|
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
2151 |
self checkForEndOfDispatch. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
2152 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
2153 |
self threadSwitch:scheduler. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
2154 |
"not reached" |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
2155 |
^ self |
699 | 2156 |
]. |
6990
a6bda971619f
race with threadDestroy (leftOver process-structures in VM);
ca
parents:
6940
diff
changeset
|
2157 |
|
699 | 2158 |
self unRemember:aProcess. |
6990
a6bda971619f
race with threadDestroy (leftOver process-structures in VM);
ca
parents:
6940
diff
changeset
|
2159 |
self class threadDestroy:id. |
a6bda971619f
race with threadDestroy (leftOver process-structures in VM);
ca
parents:
6940
diff
changeset
|
2160 |
|
20736 | 2161 |
self checkForEndOfDispatch. |
6990
a6bda971619f
race with threadDestroy (leftOver process-structures in VM);
ca
parents:
6940
diff
changeset
|
2162 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
1618 | 2163 |
|
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
2164 |
"Modified: / 23-09-1996 / 13:50:24 / stefan" |
13577
5caa91ac2963
comment/format in: #terminateNoSignal:
Claus Gittinger <cg@exept.de>
parents:
13556
diff
changeset
|
2165 |
"Modified: / 20-03-1997 / 16:03:39 / cg" |
5caa91ac2963
comment/format in: #terminateNoSignal:
Claus Gittinger <cg@exept.de>
parents:
13556
diff
changeset
|
2166 |
"Modified (comment): / 10-08-2011 / 19:57:08 / cg" |
699 | 2167 |
! |
2168 |
||
2169 |
yield |
|
17271 | 2170 |
"move the currently running process to the end of the current list |
10747 | 2171 |
and reschedule to the first in the list, thus switching to the |
699 | 2172 |
next same-prio-process." |
2173 |
||
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
2174 |
|l sz wasBlocked| |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
2175 |
|
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
2176 |
wasBlocked := OperatingSystem blockInterrupts. |
699 | 2177 |
|
12981 | 2178 |
activeProcess == scheduler ifTrue:[ |
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
2179 |
'Processor [warning]: scheduler tries to yield' errorPrintCR. |
18295 | 2180 |
^ self |
12981 | 2181 |
]. |
2182 |
||
699 | 2183 |
" |
2184 |
debugging consistency check - will be removed later |
|
2185 |
" |
|
2186 |
activeProcess priority ~~ currentPriority ifTrue:[ |
|
25422
3b02b0f1f647
Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
23107
diff
changeset
|
2187 |
Logger warning:'Processor: process changed its priority'. |
18295 | 2188 |
currentPriority := activeProcess priority. |
699 | 2189 |
]. |
2190 |
||
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
2191 |
l := quiescentProcessLists at:currentPriority. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
2192 |
sz := l size. |
699 | 2193 |
|
2194 |
" |
|
2195 |
debugging consistency checks - will be removed later |
|
2196 |
" |
|
1618 | 2197 |
sz == 0 ifTrue:[ |
18295 | 2198 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
25422
3b02b0f1f647
Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
23107
diff
changeset
|
2199 |
Logger warning:'Processor : empty runnable list'. |
18295 | 2200 |
^ self |
699 | 2201 |
]. |
2202 |
||
2203 |
" |
|
2204 |
check if the running process is not the only one |
|
2205 |
" |
|
1618 | 2206 |
sz ~~ 1 ifTrue:[ |
18295 | 2207 |
" |
2208 |
bring running process to the end |
|
2209 |
" |
|
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
2210 |
l removeFirst. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
2211 |
l addLast:activeProcess. |
18295 | 2212 |
|
2213 |
" |
|
2214 |
and switch to first in the list |
|
2215 |
" |
|
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
2216 |
self threadSwitch:(l firstLink). |
699 | 2217 |
]. |
2218 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
1086 | 2219 |
|
12981 | 2220 |
"Modified: / 02-08-2010 / 13:36:25 / cg" |
699 | 2221 |
! ! |
2222 |
||
7264 | 2223 |
!ProcessorScheduler methodsFor:'scheduling-preemptive'! |
2188 | 2224 |
|
3722
1114c2014bea
added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents:
3718
diff
changeset
|
2225 |
recomputeDynamicPriorities |
1114c2014bea
added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents:
3718
diff
changeset
|
2226 |
"recompute dynamic priorities." |
1114c2014bea
added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents:
3718
diff
changeset
|
2227 |
|
15402 | 2228 |
|processesToDecrease processesToIncrease| |
3728
970b2b4c9118
try to avoid object allocations in timeSlicers #recomputeDynamicPriorities.
Claus Gittinger <cg@exept.de>
parents:
3724
diff
changeset
|
2229 |
|
970b2b4c9118
try to avoid object allocations in timeSlicers #recomputeDynamicPriorities.
Claus Gittinger <cg@exept.de>
parents:
3724
diff
changeset
|
2230 |
scheduledProcesses notNil ifTrue:[ |
18295 | 2231 |
"/ this is written a bit cryptic - to avoid creation |
2232 |
"/ of garbage objects (Id'sets) if possible. |
|
2233 |
"/ since this runs 50 times a second and most of the |
|
2234 |
"/ time, no rescheduling is req'd |
|
2235 |
||
2236 |
scheduledProcesses do:[:aProcess | |
|
2237 |
|range| |
|
2238 |
||
2239 |
"/ decrease priority of processes that did run |
|
2240 |
(range := aProcess priorityRange) notNil ifTrue:[ |
|
2241 |
aProcess priority > range start ifTrue:[ |
|
2242 |
processesToDecrease isNil ifTrue:[ |
|
2243 |
processesToDecrease := IdentitySet new. |
|
2244 |
]. |
|
2245 |
processesToDecrease add:aProcess. |
|
2246 |
] |
|
2247 |
] |
|
2248 |
]. |
|
2249 |
||
2250 |
processesToDecrease notNil ifTrue:[ |
|
2251 |
processesToDecrease do:[:aProcess | |
|
2252 |
|newPri| |
|
2253 |
||
2254 |
"/ newPri := aProcess priority - 1. |
|
2255 |
newPri := aProcess priorityRange start. |
|
2256 |
self changePriority:newPri for:aProcess. |
|
2257 |
]. |
|
2258 |
]. |
|
2259 |
||
2260 |
"/ and increase all prios of those that did not run, but are runnable |
|
2261 |
||
2262 |
TimeSlicingPriorityLimit to:1 by:-1 do:[:i | |
|
2263 |
|list| |
|
2264 |
||
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
2265 |
(list := quiescentProcessLists at:i) size > 0 ifTrue:[ |
18295 | 2266 |
list linksDo:[:aProcess | |
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
2267 |
|range prio| |
18295 | 2268 |
|
2269 |
(range := aProcess priorityRange) notNil ifTrue:[ |
|
2270 |
(processesToDecrease isNil |
|
2271 |
or:[(processesToDecrease includes:aProcess) not]) ifTrue:[ |
|
2272 |
aProcess priority < range stop ifTrue:[ |
|
2273 |
processesToIncrease isNil ifTrue:[ |
|
2274 |
processesToIncrease := OrderedCollection new. |
|
2275 |
]. |
|
2276 |
processesToIncrease add:aProcess |
|
2277 |
] |
|
2278 |
] |
|
2279 |
] |
|
2280 |
] |
|
2281 |
] |
|
2282 |
]. |
|
2283 |
processesToIncrease notNil ifTrue:[ |
|
2284 |
processesToIncrease do:[:aProcess | |
|
2285 |
self changePriority:(aProcess priority + 1) for:aProcess. |
|
2286 |
]. |
|
2287 |
]. |
|
3722
1114c2014bea
added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents:
3718
diff
changeset
|
2288 |
]. |
1114c2014bea
added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents:
3718
diff
changeset
|
2289 |
|
15581 | 2290 |
"Modified: / 30-07-2013 / 19:33:14 / cg" |
3790
629791828694
also keep track of scheduler processes, if
Claus Gittinger <cg@exept.de>
parents:
3787
diff
changeset
|
2291 |
! |
629791828694
also keep track of scheduler processes, if
Claus Gittinger <cg@exept.de>
parents:
3787
diff
changeset
|
2292 |
|
629791828694
also keep track of scheduler processes, if
Claus Gittinger <cg@exept.de>
parents:
3787
diff
changeset
|
2293 |
scheduledProcesses |
629791828694
also keep track of scheduler processes, if
Claus Gittinger <cg@exept.de>
parents:
3787
diff
changeset
|
2294 |
"return a collection of recently scheduled processes. |
629791828694
also keep track of scheduler processes, if
Claus Gittinger <cg@exept.de>
parents:
3787
diff
changeset
|
2295 |
This is only non-empty, if the dynamic priority |
629791828694
also keep track of scheduler processes, if
Claus Gittinger <cg@exept.de>
parents:
3787
diff
changeset
|
2296 |
scheduler is running" |
629791828694
also keep track of scheduler processes, if
Claus Gittinger <cg@exept.de>
parents:
3787
diff
changeset
|
2297 |
|
629791828694
also keep track of scheduler processes, if
Claus Gittinger <cg@exept.de>
parents:
3787
diff
changeset
|
2298 |
^ scheduledProcesses ? #() |
629791828694
also keep track of scheduler processes, if
Claus Gittinger <cg@exept.de>
parents:
3787
diff
changeset
|
2299 |
|
629791828694
also keep track of scheduler processes, if
Claus Gittinger <cg@exept.de>
parents:
3787
diff
changeset
|
2300 |
"Created: / 27.8.1998 / 09:23:21 / cg" |
629791828694
also keep track of scheduler processes, if
Claus Gittinger <cg@exept.de>
parents:
3787
diff
changeset
|
2301 |
"Modified: / 27.8.1998 / 12:56:35 / cg" |
3722
1114c2014bea
added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents:
3718
diff
changeset
|
2302 |
! |
1114c2014bea
added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents:
3718
diff
changeset
|
2303 |
|
2188 | 2304 |
slice |
2305 |
"Give other Processes at the current priority a chance to run." |
|
2306 |
||
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
2307 |
|i "{ Class: SmallInteger }" |
11590
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
2308 |
list wasBlocked anyShuffle| |
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
2309 |
|
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
2310 |
anyShuffle := false. |
3745 | 2311 |
wasBlocked := OperatingSystem blockInterrupts. |
2188 | 2312 |
|
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
2313 |
i := TimeSlicingPriorityLimit. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
2314 |
[(i > 0) and:[(list := quiescentProcessLists at:i) size <= 1]] whileTrue: [i := i - 1]. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
2315 |
i ~~ 0 ifTrue: [ |
18295 | 2316 |
"/ shuffle that list |
2317 |
list addLast:(list removeFirst). |
|
2318 |
anyShuffle := true. |
|
3745 | 2319 |
]. |
2320 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
11590
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
2321 |
anyShuffle ifFalse:[ |
18295 | 2322 |
"/ wait for the scheduler to make some process runnable... |
2323 |
timeSliceNeededSemaphore wait. |
|
11590
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
2324 |
]. |
2188 | 2325 |
|
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
2326 |
"Modified: / 4.8.1998 / 00:13:32 / cg" |
2188 | 2327 |
! |
2328 |
||
2329 |
startTimeSlicing |
|
2190 | 2330 |
"start preemptive scheduling (timeSlicing)" |
2331 |
||
2332 |
timeSliceProcess notNil ifTrue: [^ self]. |
|
2333 |
||
14775 | 2334 |
timeSliceNeededSemaphore := Semaphore new name:'timeSlice needed'. |
11590
f98b955212c2
timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents:
11585
diff
changeset
|
2335 |
|
2188 | 2336 |
timeSliceProcess := [ |
18295 | 2337 |
[ |
2338 |
self timeSlicingLoop. |
|
2339 |
] ifCurtailed:[ |
|
2340 |
timeSliceProcess := nil. |
|
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
2341 |
'Processor [info]: timeslicer finished' infoPrintCR. |
18295 | 2342 |
] |
2188 | 2343 |
] newProcess. |
18295 | 2344 |
timeSliceProcess |
2345 |
priority:HighestPriority; |
|
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
2346 |
name:'time slicer'; |
18295 | 2347 |
restartable:true; |
2348 |
beSystemProcess; |
|
2349 |
resume. |
|
2188 | 2350 |
|
2351 |
" |
|
2258 | 2352 |
Processor stopTimeSlicing. |
2353 |
Processor startTimeSlicing. |
|
2188 | 2354 |
" |
2355 |
||
13813 | 2356 |
"Created: / 17-01-1997 / 16:42:02 / cg" |
2357 |
"Modified: / 03-11-2011 / 21:21:10 / cg" |
|
2188 | 2358 |
! |
2359 |
||
2360 |
stopTimeSlicing |
|
2190 | 2361 |
"stop preemptive scheduling (timeSlicing)" |
2188 | 2362 |
|
2363 |
timeSliceProcess notNil ifTrue: [ |
|
18295 | 2364 |
timeSliceProcess terminate. |
2365 |
timeSliceProcess := nil. |
|
2366 |
scheduledProcesses := nil. |
|
2367 |
timeSliceNeededSemaphore := nil. |
|
2188 | 2368 |
] |
2369 |
||
2370 |
" |
|
2371 |
Processor stopTimeSlicing |
|
2372 |
" |
|
2373 |
||
3790
629791828694
also keep track of scheduler processes, if
Claus Gittinger <cg@exept.de>
parents:
3787
diff
changeset
|
2374 |
"Created: / 17.1.1997 / 16:43:03 / cg" |
629791828694
also keep track of scheduler processes, if
Claus Gittinger <cg@exept.de>
parents:
3787
diff
changeset
|
2375 |
"Modified: / 27.8.1998 / 13:00:37 / cg" |
3722
1114c2014bea
added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents:
3718
diff
changeset
|
2376 |
! |
1114c2014bea
added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents:
3718
diff
changeset
|
2377 |
|
1114c2014bea
added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents:
3718
diff
changeset
|
2378 |
supportDynamicPriorities |
1114c2014bea
added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents:
3718
diff
changeset
|
2379 |
"return true, if dynamic priorities are enabled" |
1114c2014bea
added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents:
3718
diff
changeset
|
2380 |
|
1114c2014bea
added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents:
3718
diff
changeset
|
2381 |
^ supportDynamicPriorities |
1114c2014bea
added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents:
3718
diff
changeset
|
2382 |
|
1114c2014bea
added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents:
3718
diff
changeset
|
2383 |
"Created: / 3.8.1998 / 22:05:15 / cg" |
1114c2014bea
added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents:
3718
diff
changeset
|
2384 |
"Modified: / 3.8.1998 / 22:55:08 / cg" |
1114c2014bea
added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents:
3718
diff
changeset
|
2385 |
! |
1114c2014bea
added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents:
3718
diff
changeset
|
2386 |
|
1114c2014bea
added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents:
3718
diff
changeset
|
2387 |
supportDynamicPriorities:aBoolean |
1114c2014bea
added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents:
3718
diff
changeset
|
2388 |
"enable/disable dynamic priorities" |
1114c2014bea
added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents:
3718
diff
changeset
|
2389 |
|
1114c2014bea
added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents:
3718
diff
changeset
|
2390 |
supportDynamicPriorities := aBoolean. |
1114c2014bea
added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents:
3718
diff
changeset
|
2391 |
|
1114c2014bea
added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents:
3718
diff
changeset
|
2392 |
" |
1114c2014bea
added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents:
3718
diff
changeset
|
2393 |
Processor supportDynamicPriorities:true |
1114c2014bea
added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents:
3718
diff
changeset
|
2394 |
Processor supportDynamicPriorities:false |
1114c2014bea
added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents:
3718
diff
changeset
|
2395 |
" |
1114c2014bea
added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents:
3718
diff
changeset
|
2396 |
|
1114c2014bea
added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents:
3718
diff
changeset
|
2397 |
"Modified: / 3.8.1998 / 22:54:52 / cg" |
15687 | 2398 |
! |
2399 |
||
2400 |
timeSlicingLoop |
|
2401 |
|myDelay t flipFlop| |
|
2402 |
||
2403 |
myDelay := Delay forMilliseconds:(t := TimeSliceInterval). |
|
2404 |
flipFlop := true. |
|
2405 |
||
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
2406 |
Smalltalk verbose ifTrue:[ 'Processor [info]: timeslicer started' infoPrintCR ]. |
17412 | 2407 |
[ |
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
2408 |
t ~~ TimeSliceInterval ifTrue:[ |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
2409 |
"/ interval changed -> need a new delay |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
2410 |
myDelay delay:(t := TimeSliceInterval). |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
2411 |
]. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
2412 |
myDelay wait. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
2413 |
self slice. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
2414 |
|
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
2415 |
"/ every other tick, recompute priorities. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
2416 |
flipFlop := flipFlop not. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
2417 |
flipFlop ifTrue:[ |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
2418 |
scheduledProcesses notNil ifTrue:[ |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
2419 |
supportDynamicPriorities ifTrue:[ |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
2420 |
self recomputeDynamicPriorities. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
2421 |
]. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
2422 |
scheduledProcesses clearContents. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
2423 |
] ifFalse:[ |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
2424 |
scheduledProcesses := IdentitySet new. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
2425 |
]. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
2426 |
]. |
17412 | 2427 |
] loop. |
2188 | 2428 |
! ! |
2429 |
||
699 | 2430 |
!ProcessorScheduler methodsFor:'semaphore signalling'! |
2431 |
||
19063 | 2432 |
disableFd:aFileDescriptor doSignal:doSignal |
2433 |
"disable triggering of a semaphore for aFileDescriptor.. |
|
20643 | 2434 |
If doSignal is true, the associated semaphore is signaled. |
2435 |
Answer a collection of semaphores that haven't been signaled." |
|
19063 | 2436 |
|
2437 |
|idx "{ Class: SmallInteger }" |
|
20643 | 2438 |
wasBlocked sema semaCollection| |
19063 | 2439 |
|
2440 |
wasBlocked := OperatingSystem blockInterrupts. |
|
2441 |
useIOInterrupts ifTrue:[ |
|
20706
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20643
diff
changeset
|
2442 |
OperatingSystem disableIOInterruptsOn:aFileDescriptor. |
19063 | 2443 |
]. |
2444 |
||
20643 | 2445 |
idx := readFdArray indexOf:aFileDescriptor startingAt:1. |
19063 | 2446 |
[idx ~~ 0] whileTrue:[ |
20706
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20643
diff
changeset
|
2447 |
readFdArray at:idx put:nil. |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20643
diff
changeset
|
2448 |
readCheckArray at:idx put:nil. |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20643
diff
changeset
|
2449 |
(sema := readSemaphoreArray at:idx) notNil ifTrue:[ |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20643
diff
changeset
|
2450 |
readSemaphoreArray at:idx put:nil. |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20643
diff
changeset
|
2451 |
semaCollection isNil ifTrue:[semaCollection := Set new]. |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20643
diff
changeset
|
2452 |
semaCollection add:sema. |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20643
diff
changeset
|
2453 |
]. |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20643
diff
changeset
|
2454 |
idx := readFdArray indexOf:aFileDescriptor startingAt:idx+1. |
19063 | 2455 |
]. |
20643 | 2456 |
idx := writeFdArray indexOf:aFileDescriptor startingAt:1. |
19063 | 2457 |
[idx ~~ 0] whileTrue:[ |
20706
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20643
diff
changeset
|
2458 |
writeFdArray at:idx put:nil. |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20643
diff
changeset
|
2459 |
writeCheckArray at:idx put:nil. |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20643
diff
changeset
|
2460 |
(sema := writeSemaphoreArray at:idx) notNil ifTrue:[ |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20643
diff
changeset
|
2461 |
writeSemaphoreArray at:idx put:nil. |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20643
diff
changeset
|
2462 |
semaCollection isNil ifTrue:[semaCollection := Set new]. |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20643
diff
changeset
|
2463 |
semaCollection add:sema. |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20643
diff
changeset
|
2464 |
]. |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20643
diff
changeset
|
2465 |
idx := writeFdArray indexOf:aFileDescriptor startingAt:idx+1. |
19063 | 2466 |
]. |
20643 | 2467 |
idx := exceptFdArray indexOf:aFileDescriptor startingAt:1. |
19063 | 2468 |
[idx ~~ 0] whileTrue:[ |
20706
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20643
diff
changeset
|
2469 |
exceptFdArray at:idx put:nil. |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20643
diff
changeset
|
2470 |
(sema := exceptSemaphoreArray at:idx) notNil ifTrue:[ |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20643
diff
changeset
|
2471 |
exceptSemaphoreArray at:idx put:nil. |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20643
diff
changeset
|
2472 |
semaCollection isNil ifTrue:[semaCollection := Set new]. |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20643
diff
changeset
|
2473 |
semaCollection add:sema. |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20643
diff
changeset
|
2474 |
]. |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20643
diff
changeset
|
2475 |
idx := exceptFdArray indexOf:aFileDescriptor startingAt:idx+1. |
20643 | 2476 |
]. |
2477 |
||
2478 |
semaCollection isNil ifTrue:[ |
|
20706
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20643
diff
changeset
|
2479 |
semaCollection := #(). |
20643 | 2480 |
] ifFalse:[ |
20706
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20643
diff
changeset
|
2481 |
doSignal ifTrue:[ |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20643
diff
changeset
|
2482 |
semaCollection do:[:eachSema| |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20643
diff
changeset
|
2483 |
eachSema signalForAll. |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20643
diff
changeset
|
2484 |
semaCollection := #(). |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20643
diff
changeset
|
2485 |
]. |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20643
diff
changeset
|
2486 |
]. |
19063 | 2487 |
]. |
2488 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
20643 | 2489 |
^ semaCollection |
19063 | 2490 |
! |
2491 |
||
699 | 2492 |
disableSemaphore:aSemaphore |
2493 |
"disable triggering of a semaphore" |
|
2494 |
||
2495 |
|idx "{ Class: SmallInteger }" |
|
2831
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
2496 |
wasBlocked fd| |
699 | 2497 |
|
2498 |
wasBlocked := OperatingSystem blockInterrupts. |
|
20052 | 2499 |
idx := 0. |
2500 |
[idx := readSemaphoreArray identityIndexOf:aSemaphore startingAt:idx+1. |
|
2501 |
idx ~~ 0] whileTrue:[ |
|
20706
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20643
diff
changeset
|
2502 |
useIOInterrupts ifTrue:[ |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20643
diff
changeset
|
2503 |
fd := readFdArray at:idx. |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20643
diff
changeset
|
2504 |
fd notNil ifTrue:[ |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20643
diff
changeset
|
2505 |
OperatingSystem disableIOInterruptsOn:fd |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20643
diff
changeset
|
2506 |
]. |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20643
diff
changeset
|
2507 |
]. |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20643
diff
changeset
|
2508 |
readFdArray at:idx put:nil. |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20643
diff
changeset
|
2509 |
readSemaphoreArray at:idx put:nil. |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20643
diff
changeset
|
2510 |
readCheckArray at:idx put:nil. |
699 | 2511 |
]. |
20052 | 2512 |
idx := 0. |
2513 |
[idx := writeSemaphoreArray identityIndexOf:aSemaphore startingAt:idx+1. |
|
2514 |
idx ~~ 0] whileTrue:[ |
|
20706
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20643
diff
changeset
|
2515 |
useIOInterrupts ifTrue:[ |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20643
diff
changeset
|
2516 |
fd := writeFdArray at:idx. |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20643
diff
changeset
|
2517 |
fd notNil ifTrue:[ |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20643
diff
changeset
|
2518 |
OperatingSystem disableIOInterruptsOn:fd |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20643
diff
changeset
|
2519 |
]. |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20643
diff
changeset
|
2520 |
]. |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20643
diff
changeset
|
2521 |
writeFdArray at:idx put:nil. |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20643
diff
changeset
|
2522 |
writeSemaphoreArray at:idx put:nil. |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20643
diff
changeset
|
2523 |
writeCheckArray at:idx put:nil. |
699 | 2524 |
]. |
20052 | 2525 |
idx := 0. |
2526 |
[idx := exceptSemaphoreArray identityIndexOf:aSemaphore startingAt:idx+1. |
|
2527 |
idx ~~ 0] whileTrue:[ |
|
20706
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20643
diff
changeset
|
2528 |
exceptFdArray at:idx put:nil. |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20643
diff
changeset
|
2529 |
exceptSemaphoreArray at:idx put:nil. |
18957 | 2530 |
]. |
20052 | 2531 |
self removeTimeoutForSemaphore:aSemaphore. |
699 | 2532 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
2831
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
2533 |
|
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
2534 |
"Modified: 4.8.1997 / 15:19:33 / cg" |
699 | 2535 |
! |
2536 |
||
1683 | 2537 |
signal:aSemaphore |
2538 |
"arrange for a semaphore to be triggered as soon as possible. |
|
2539 |
The actual signalling is performed slightly delayed, when the dispatcher |
|
2618 | 2540 |
looks for a process to resume the next time. I.e. here, the current |
2541 |
process continues to execute, even if the semaphore signalling would |
|
2542 |
make a higher prio process runnable. |
|
2543 |
This is provided as entry for primitive-code (external functions) |
|
2544 |
which want to signal a semaphore AND make certain that they do not get |
|
2545 |
suspended (i.e. it is called by __STX_SignalSemaphore()). |
|
2546 |
Normal smalltalk code should always send an appropriate message directly |
|
2547 |
to the semaphore (i.e. aSemaphore signal)." |
|
1683 | 2548 |
|
3917 | 2549 |
self signal:aSemaphore atMilliseconds:OperatingSystem getMillisecondTime. |
2550 |
||
2551 |
"Modified: / 9.11.1998 / 20:39:06 / cg" |
|
1683 | 2552 |
! |
2553 |
||
25422
3b02b0f1f647
Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
23107
diff
changeset
|
2554 |
signal:aSemaphore after:secondsOrTimeDuration |
16461 | 2555 |
"arrange for a semaphore to be triggered after aTimeDuration" |
2556 |
||
25422
3b02b0f1f647
Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
23107
diff
changeset
|
2557 |
|ms| |
3b02b0f1f647
Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
23107
diff
changeset
|
2558 |
|
3b02b0f1f647
Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
23107
diff
changeset
|
2559 |
secondsOrTimeDuration isTimeDuration ifTrue:[ |
3b02b0f1f647
Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
23107
diff
changeset
|
2560 |
ms := secondsOrTimeDuration getMilliseconds. |
3b02b0f1f647
Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
23107
diff
changeset
|
2561 |
] ifFalse:[ |
3b02b0f1f647
Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
23107
diff
changeset
|
2562 |
ms := (secondsOrTimeDuration * 1000) rounded. |
3b02b0f1f647
Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
23107
diff
changeset
|
2563 |
]. |
3b02b0f1f647
Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
23107
diff
changeset
|
2564 |
|
3b02b0f1f647
Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
23107
diff
changeset
|
2565 |
self signal:aSemaphore afterMilliseconds:ms. |
3b02b0f1f647
Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
23107
diff
changeset
|
2566 |
|
3b02b0f1f647
Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
23107
diff
changeset
|
2567 |
"Modified: / 04-03-2020 / 14:32:10 / Stefan Vogel" |
16461 | 2568 |
! |
2569 |
||
699 | 2570 |
signal:aSemaphore afterMilliseconds:millis |
2571 |
"arrange for a semaphore to be triggered after some milliseconds" |
|
2572 |
||
3917 | 2573 |
|now then| |
2574 |
||
699 | 2575 |
now := OperatingSystem getMillisecondTime. |
2576 |
then := OperatingSystem millisecondTimeAdd:now and:millis rounded. |
|
2577 |
self signal:aSemaphore atMilliseconds:then. |
|
3917 | 2578 |
|
2579 |
"Modified: / 9.11.1998 / 20:39:27 / cg" |
|
699 | 2580 |
! |
2581 |
||
2582 |
signal:aSemaphore afterSeconds:seconds |
|
2583 |
"arrange for a semaphore to be triggered after some seconds" |
|
2584 |
||
2585 |
self signal:aSemaphore afterMilliseconds:(seconds * 1000) |
|
2586 |
! |
|
2587 |
||
2588 |
signal:aSemaphore atMilliseconds:aMillisecondTime |
|
2589 |
"arrange for a semaphore to be triggered at a specific millisecond time. |
|
2618 | 2590 |
If there is already a pending trigger time installed for that semaphore, |
2591 |
the time of the pending trigger is changed." |
|
699 | 2592 |
|
2593 |
|index "{ Class: SmallInteger }" |
|
2594 |
wasBlocked| |
|
2595 |
||
2596 |
wasBlocked := OperatingSystem blockInterrupts. |
|
2597 |
index := timeoutSemaphoreArray identityIndexOf:aSemaphore startingAt:1. |
|
2598 |
index ~~ 0 ifTrue:[ |
|
18295 | 2599 |
timeoutArray at:index put:aMillisecondTime |
699 | 2600 |
] ifFalse:[ |
18295 | 2601 |
index := timeoutArray identityIndexOf:nil startingAt:1. |
2602 |
index ~~ 0 ifTrue:[ |
|
2603 |
timeoutSemaphoreArray at:index put:aSemaphore. |
|
2604 |
timeoutArray at:index put:aMillisecondTime. |
|
2605 |
timeoutActionArray at:index put:nil. |
|
2606 |
timeoutProcessArray at:index put:nil |
|
2607 |
] ifFalse:[ |
|
2608 |
timeoutSemaphoreArray := timeoutSemaphoreArray copyWith:aSemaphore. |
|
2609 |
timeoutArray := timeoutArray copyWith:aMillisecondTime. |
|
2610 |
timeoutActionArray := timeoutActionArray copyWith:nil. |
|
2611 |
timeoutProcessArray := timeoutProcessArray copyWith:nil |
|
2612 |
]. |
|
699 | 2613 |
]. |
2614 |
||
2615 |
anyTimeouts := true. |
|
2616 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
2617 |
! |
|
2618 |
||
18957 | 2619 |
signal:aSemaphore onException:aFileDescriptor |
2620 |
"arrange for a semaphore to be triggered when output on aFileDescriptor |
|
2621 |
is possible (i.e. can be written without blocking) or aBlock returns true. |
|
2622 |
The checkBlock will be evaluated by the scheduler from time to time |
|
2623 |
(i.e. every few milliseconds). |
|
2624 |
This checkBlock is required for poor windows, where a WaitForObject does |
|
2625 |
not know about sockets. |
|
2626 |
If aBlock is nil, the semaphore is removed from the set of semaphores, after being signaled." |
|
2627 |
||
2628 |
|idx "{ Class: SmallInteger }" |
|
2629 |
wasBlocked slot| |
|
2630 |
||
2631 |
wasBlocked := OperatingSystem blockInterrupts. |
|
2632 |
||
2633 |
"Here we assume, that for every triple (aSemaphore, aFileDescriptor, aBlock) |
|
2634 |
aSemphore is never nil, but one of aFileDescriptor, aBlock may be nil" |
|
2635 |
||
2636 |
aFileDescriptor isNil ifTrue:[ |
|
19850 | 2637 |
idx := exceptSemaphoreArray identityIndexOf:aSemaphore or:nil. |
2638 |
idx == 0 ifTrue:[ |
|
2639 |
"aSemaphore is not registered yet, have to create a new slot" |
|
2640 |
exceptFdArray := exceptFdArray copyWith:nil. |
|
2641 |
exceptSemaphoreArray := exceptSemaphoreArray copyWith:aSemaphore. |
|
2642 |
] ifFalse:[ |
|
2643 |
slot := exceptSemaphoreArray at:idx. |
|
2644 |
slot isNil ifTrue:[ |
|
2645 |
exceptSemaphoreArray at:idx put:aSemaphore. |
|
2646 |
] |
|
2647 |
] |
|
18957 | 2648 |
] ifFalse:[ |
19850 | 2649 |
idx := exceptFdArray identityIndexOf:aFileDescriptor or:nil. |
2650 |
idx == 0 ifTrue:[ |
|
2651 |
"aFileDescriptor is not registered yet, have to create a new slot" |
|
2652 |
exceptFdArray := exceptFdArray copyWith:aFileDescriptor. |
|
2653 |
exceptSemaphoreArray := exceptSemaphoreArray copyWith:aSemaphore. |
|
2654 |
] ifFalse:[ |
|
2655 |
slot := exceptFdArray at:idx. |
|
2656 |
slot isNil ifTrue:[ |
|
2657 |
exceptFdArray at:idx put:aFileDescriptor. |
|
2658 |
exceptSemaphoreArray at:idx put:aSemaphore. |
|
2659 |
]. |
|
2660 |
]. |
|
18957 | 2661 |
"/ (useIOInterrupts and:[slot isNil]) ifTrue:[ |
2662 |
"/ OperatingSystem enableIOInterruptsOn:aFileDescriptor |
|
2663 |
"/ ]. |
|
2664 |
]. |
|
2665 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
2666 |
||
2667 |
"Modified: 4.8.1997 / 15:21:49 / cg" |
|
2668 |
! |
|
2669 |
||
699 | 2670 |
signal:aSemaphore onInput:aFileDescriptor |
2671 |
"arrange for a semaphore to be triggered when input on aFileDescriptor |
|
16461 | 2672 |
arrives. This will only happen, if the OS supports selecting on fileDescriptors. |
2673 |
The semaphore is removed from the set of semaphores, after being signaled." |
|
699 | 2674 |
|
2675 |
self signal:aSemaphore onInput:aFileDescriptor orCheck:nil |
|
2676 |
! |
|
2677 |
||
2678 |
signal:aSemaphore onInput:aFileDescriptor orCheck:aBlock |
|
2679 |
"arrange for a semaphore to be triggered when input on aFileDescriptor |
|
10747 | 2680 |
arrives OR checkblock evaluates to true. |
2681 |
The checkBlock will be evaluated by the scheduler from time to time |
|
5101 | 2682 |
(i.e. every few milliseconds). |
10747 | 2683 |
(This is req'd for buffered input, where a select may not detect |
2618 | 2684 |
data which has already been read into a buffer - as in Xlib. |
16461 | 2685 |
Or on systems, where we cannot select on a displays eventQ, such as windows). |
2686 |
If aBlock is nil, the semaphore is removed from the set of semaphores, after being signaled." |
|
699 | 2687 |
|
2688 |
|idx "{ Class: SmallInteger }" |
|
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
2689 |
wasBlocked slot| |
1627
f95285226059
infoPrint for NT (no select)
Claus Gittinger <cg@exept.de>
parents:
1618
diff
changeset
|
2690 |
|
699 | 2691 |
wasBlocked := OperatingSystem blockInterrupts. |
3116 | 2692 |
|
16319 | 2693 |
"Here we assume, that for every triple (aSemaphore, aFileDescriptor, aBlock) |
2694 |
aSemphore is never nil, but one of aFileDescriptor, aBlock may be nil" |
|
2695 |
||
6807
ba04d2e1a416
oops - hps lexer is not 8-bit clean
Claus Gittinger <cg@exept.de>
parents:
6619
diff
changeset
|
2696 |
aFileDescriptor isNil ifTrue:[ |
18295 | 2697 |
idx := readSemaphoreArray identityIndexOf:aSemaphore or:nil. |
2698 |
idx == 0 ifTrue:[ |
|
2699 |
"aSemaphore is not registered yet, have to create a new slot" |
|
2700 |
readFdArray := readFdArray copyWith:nil. |
|
2701 |
readSemaphoreArray := readSemaphoreArray copyWith:aSemaphore. |
|
2702 |
readCheckArray := readCheckArray copyWith:aBlock. |
|
2703 |
] ifFalse:[ |
|
2704 |
slot := readSemaphoreArray at:idx. |
|
2705 |
slot isNil ifTrue:[ |
|
2706 |
readSemaphoreArray at:idx put:aSemaphore. |
|
2707 |
readCheckArray at:idx put:aBlock |
|
2708 |
] ifFalse:[ |
|
2709 |
"/ someone has already registered aSemaphore. |
|
2710 |
"/ Check if it is the block changes... |
|
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
2711 |
(readCheckArray at:idx) notNil ifTrue:[ |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
2712 |
(readCheckArray at:idx) ~~ aBlock ifTrue:[ |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
2713 |
'Processor [info]: checkblock changed for read-check' infoPrintCR. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
2714 |
readCheckArray at:idx put:aBlock. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
2715 |
]. |
18295 | 2716 |
]. |
2717 |
]. |
|
2718 |
] |
|
16319 | 2719 |
] ifFalse:[ |
18295 | 2720 |
idx := readFdArray identityIndexOf:aFileDescriptor or:nil. |
2721 |
idx == 0 ifTrue:[ |
|
2722 |
"aFileDescriptor is not registered yet, have to create a new slot" |
|
2723 |
readFdArray := readFdArray copyWith:aFileDescriptor. |
|
2724 |
readSemaphoreArray := readSemaphoreArray copyWith:aSemaphore. |
|
2725 |
readCheckArray := readCheckArray copyWith:aBlock. |
|
2726 |
] ifFalse:[ |
|
2727 |
slot := readFdArray at:idx. |
|
2728 |
slot isNil ifTrue:[ |
|
2729 |
readFdArray at:idx put:aFileDescriptor. |
|
2730 |
readSemaphoreArray at:idx put:aSemaphore. |
|
2731 |
readCheckArray at:idx put:aBlock |
|
2732 |
] ifFalse:[ |
|
2733 |
"/ someone has already registered aFileDescriptor. |
|
2734 |
"/ Check if it is the semaphore or block changes... |
|
2735 |
(readSemaphoreArray at:idx) ~~ aSemaphore ifTrue:[ |
|
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
2736 |
'Processor [info]: sema changed for read-check' infoPrintCR. |
18295 | 2737 |
readSemaphoreArray at:idx put:aSemaphore. |
2738 |
]. |
|
2739 |
(readCheckArray at:idx) ~~ aBlock ifTrue:[ |
|
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
2740 |
'Processor [info]: checkblock changed for read-check' infoPrintCR. |
18295 | 2741 |
readCheckArray at:idx put:aBlock. |
2742 |
]. |
|
2743 |
]. |
|
2744 |
]. |
|
2745 |
(useIOInterrupts and:[slot isNil]) ifTrue:[ |
|
2746 |
OperatingSystem enableIOInterruptsOn:aFileDescriptor |
|
2747 |
]. |
|
699 | 2748 |
]. |
2749 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
2123 | 2750 |
|
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
2751 |
"Modified: 4.8.1997 / 15:20:45 / cg" |
699 | 2752 |
! |
2753 |
||
5103 | 2754 |
signal:aSemaphore onInputStream:aStream |
10747 | 2755 |
"arrange for a semaphore to be triggered when input on aStream arrives. |
5101 | 2756 |
This will do a select, if the OS supports selecting on that filedescriptor, |
2757 |
otherwise, it will be polled every few milliseconds (MSDOS)." |
|
2758 |
||
2759 |
aStream canBeSelected ifTrue:[ |
|
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
2760 |
"/ can this stream be selected on ? |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
2761 |
self signal:aSemaphore onInput:aStream fileHandle orCheck:nil |
5101 | 2762 |
] ifFalse:[ |
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
2763 |
"/ nope - must poll ... |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
2764 |
self signal:aSemaphore onInput:nil orCheck:[aStream canReadWithoutBlocking] |
5101 | 2765 |
] |
5107 | 2766 |
|
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
2767 |
"Modified: / 14.12.1999 / 23:58:50 / cg" |
5101 | 2768 |
! |
2769 |
||
5103 | 2770 |
signal:aSemaphore onOutput:aFileDescriptor |
2771 |
"arrange for a semaphore to be triggered when output on aFileDescriptor |
|
16461 | 2772 |
is possible without blocking. |
2773 |
The semaphore is removed from the set of semaphores, after being signaled." |
|
5103 | 2774 |
|
2775 |
self signal:aSemaphore onOutput:aFileDescriptor orCheck:nil |
|
2776 |
||
2777 |
"Created: / 14.12.1999 / 19:54:12 / cg" |
|
2778 |
! |
|
2779 |
||
5101 | 2780 |
signal:aSemaphore onOutput:aFileDescriptor orCheck:aBlock |
699 | 2781 |
"arrange for a semaphore to be triggered when output on aFileDescriptor |
5101 | 2782 |
is possible (i.e. can be written without blocking) or aBlock returns true. |
10747 | 2783 |
The checkBlock will be evaluated by the scheduler from time to time |
5101 | 2784 |
(i.e. every few milliseconds). |
2785 |
This checkBlock is required for poor windows, where a WaitForObject does |
|
16461 | 2786 |
not know about sockets. |
2787 |
If aBlock is nil, the semaphore is removed from the set of semaphores, after being signaled." |
|
699 | 2788 |
|
2789 |
|idx "{ Class: SmallInteger }" |
|
16319 | 2790 |
wasBlocked slot| |
699 | 2791 |
|
2792 |
wasBlocked := OperatingSystem blockInterrupts. |
|
5101 | 2793 |
|
16319 | 2794 |
"Here we assume, that for every triple (aSemaphore, aFileDescriptor, aBlock) |
2795 |
aSemphore is never nil, but one of aFileDescriptor, aBlock may be nil" |
|
2796 |
||
5101 | 2797 |
aFileDescriptor isNil ifTrue:[ |
18295 | 2798 |
idx := writeSemaphoreArray identityIndexOf:aSemaphore or:nil. |
2799 |
idx == 0 ifTrue:[ |
|
2800 |
"aSemaphore is not registered yet, have to create a new slot" |
|
2801 |
writeFdArray := writeFdArray copyWith:nil. |
|
2802 |
writeSemaphoreArray := writeSemaphoreArray copyWith:aSemaphore. |
|
2803 |
writeCheckArray := writeCheckArray copyWith:aBlock. |
|
2804 |
] ifFalse:[ |
|
2805 |
slot := writeSemaphoreArray at:idx. |
|
2806 |
slot isNil ifTrue:[ |
|
2807 |
writeSemaphoreArray at:idx put:aSemaphore. |
|
2808 |
writeCheckArray at:idx put:aBlock |
|
2809 |
] ifFalse:[ |
|
2810 |
"/ someone has already registered aSemaphore. |
|
2811 |
"/ Check if it is the block changes... |
|
2812 |
(writeCheckArray at:idx) notNil ifTrue:[ |
|
2813 |
(writeCheckArray at:idx) ~~ aBlock ifTrue:[ |
|
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
2814 |
'Processor [info]: checkblock changed for write-check' infoPrintCR. |
18295 | 2815 |
writeCheckArray at:idx put:aBlock. |
2816 |
]. |
|
2817 |
]. |
|
2818 |
]. |
|
2819 |
] |
|
16319 | 2820 |
] ifFalse:[ |
18295 | 2821 |
idx := writeFdArray identityIndexOf:aFileDescriptor or:nil. |
2822 |
idx == 0 ifTrue:[ |
|
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
2823 |
"aFileDescriptor is not registered yet, have to create a new slot" |
18295 | 2824 |
writeFdArray := writeFdArray copyWith:aFileDescriptor. |
2825 |
writeSemaphoreArray := writeSemaphoreArray copyWith:aSemaphore. |
|
2826 |
writeCheckArray := writeCheckArray copyWith:aBlock. |
|
2827 |
] ifFalse:[ |
|
2828 |
slot := writeFdArray at:idx. |
|
2829 |
slot isNil ifTrue:[ |
|
2830 |
writeFdArray at:idx put:aFileDescriptor. |
|
2831 |
writeSemaphoreArray at:idx put:aSemaphore. |
|
2832 |
writeCheckArray at:idx put:aBlock |
|
2833 |
] ifFalse:[ |
|
2834 |
"/ someone has already registered aFileDescriptor. |
|
2835 |
"/ Check if it is the semaphore or block changes... |
|
2836 |
(writeSemaphoreArray at:idx) ~~ aSemaphore ifTrue:[ |
|
25422
3b02b0f1f647
Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
23107
diff
changeset
|
2837 |
Logger warning:'Processor: sema changed for write-check'. |
18295 | 2838 |
writeSemaphoreArray at:idx put:aSemaphore. |
2839 |
]. |
|
2840 |
(writeCheckArray at:idx) ~~ aBlock ifTrue:[ |
|
25422
3b02b0f1f647
Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
23107
diff
changeset
|
2841 |
Logger info:'Processor: checkblock changed for write-check'. |
18295 | 2842 |
writeCheckArray at:idx put:aBlock. |
2843 |
]. |
|
2844 |
]. |
|
2845 |
]. |
|
2846 |
(useIOInterrupts and:[slot isNil]) ifTrue:[ |
|
2847 |
OperatingSystem enableIOInterruptsOn:aFileDescriptor |
|
2848 |
]. |
|
699 | 2849 |
]. |
2850 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
2831
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
2851 |
|
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
2852 |
"Modified: 4.8.1997 / 15:21:49 / cg" |
5103 | 2853 |
! |
2854 |
||
2855 |
signal:aSemaphore onOutputStream:aStream |
|
10747 | 2856 |
"arrange for a semaphore to be triggered when output on aStream is possible. |
5103 | 2857 |
This will do a select, if the OS supports selecting on that filedescriptor, |
2858 |
otherwise, it will be polled every few milliseconds (MSDOS)." |
|
2859 |
||
2860 |
aStream canBeSelected ifTrue:[ |
|
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
2861 |
"/ can this stream be selected on ? |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
2862 |
self signal:aSemaphore onOutput:aStream fileHandle orCheck:nil |
5103 | 2863 |
] ifFalse:[ |
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
2864 |
"/ nope - must poll ... |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
2865 |
self signal:aSemaphore onOutput:nil orCheck:[aStream canWriteWithoutBlocking] |
5103 | 2866 |
] |
5107 | 2867 |
|
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
2868 |
"Modified: / 14.12.1999 / 23:59:19 / cg" |
699 | 2869 |
! ! |
2870 |
||
3650
523781600982
added #useIOInterrupts: to allow disabling this feature
Claus Gittinger <cg@exept.de>
parents:
3644
diff
changeset
|
2871 |
!ProcessorScheduler methodsFor:'special configuration'! |
523781600982
added #useIOInterrupts: to allow disabling this feature
Claus Gittinger <cg@exept.de>
parents:
3644
diff
changeset
|
2872 |
|
523781600982
added #useIOInterrupts: to allow disabling this feature
Claus Gittinger <cg@exept.de>
parents:
3644
diff
changeset
|
2873 |
useIOInterrupts:aBoolean |
523781600982
added #useIOInterrupts: to allow disabling this feature
Claus Gittinger <cg@exept.de>
parents:
3644
diff
changeset
|
2874 |
"enable/disable the use of IO-interrupts. |
523781600982
added #useIOInterrupts: to allow disabling this feature
Claus Gittinger <cg@exept.de>
parents:
3644
diff
changeset
|
2875 |
If disabled, communication channels (socket, X-server connection etc.) |
523781600982
added #useIOInterrupts: to allow disabling this feature
Claus Gittinger <cg@exept.de>
parents:
3644
diff
changeset
|
2876 |
are polled in regular intervals. |
523781600982
added #useIOInterrupts: to allow disabling this feature
Claus Gittinger <cg@exept.de>
parents:
3644
diff
changeset
|
2877 |
If enabled, arrangements are made for data-availability to trigger an |
523781600982
added #useIOInterrupts: to allow disabling this feature
Claus Gittinger <cg@exept.de>
parents:
3644
diff
changeset
|
2878 |
interrupt. |
523781600982
added #useIOInterrupts: to allow disabling this feature
Claus Gittinger <cg@exept.de>
parents:
3644
diff
changeset
|
2879 |
Using IO interrupts reduces the idle CPU usage of ST/X by some percent |
523781600982
added #useIOInterrupts: to allow disabling this feature
Claus Gittinger <cg@exept.de>
parents:
3644
diff
changeset
|
2880 |
(typically 2-7%). |
10747 | 2881 |
Notice: |
18295 | 2882 |
some systems do not support IO-interrupts (or have a broken stdio-lib), |
2883 |
and this feature is always disabled; |
|
3650
523781600982
added #useIOInterrupts: to allow disabling this feature
Claus Gittinger <cg@exept.de>
parents:
3644
diff
changeset
|
2884 |
Also notice: |
18295 | 2885 |
we found that in some Xlib-implementations, interrupted reads are not |
2886 |
handled correctly (especially in multi-headed applications), and this |
|
2887 |
feature should be disabled to avoid a blocking XPending. |
|
3650
523781600982
added #useIOInterrupts: to allow disabling this feature
Claus Gittinger <cg@exept.de>
parents:
3644
diff
changeset
|
2888 |
|
10747 | 2889 |
If this method is used to disable IO interrupts in multi-headed apps, |
3650
523781600982
added #useIOInterrupts: to allow disabling this feature
Claus Gittinger <cg@exept.de>
parents:
3644
diff
changeset
|
2890 |
it should be invoked BEFORE the display event dispatcher processes are started." |
523781600982
added #useIOInterrupts: to allow disabling this feature
Claus Gittinger <cg@exept.de>
parents:
3644
diff
changeset
|
2891 |
|
523781600982
added #useIOInterrupts: to allow disabling this feature
Claus Gittinger <cg@exept.de>
parents:
3644
diff
changeset
|
2892 |
OperatingSystem supportsIOInterrupts ifTrue:[ |
18295 | 2893 |
useIOInterrupts := aBoolean |
3650
523781600982
added #useIOInterrupts: to allow disabling this feature
Claus Gittinger <cg@exept.de>
parents:
3644
diff
changeset
|
2894 |
]. |
523781600982
added #useIOInterrupts: to allow disabling this feature
Claus Gittinger <cg@exept.de>
parents:
3644
diff
changeset
|
2895 |
|
523781600982
added #useIOInterrupts: to allow disabling this feature
Claus Gittinger <cg@exept.de>
parents:
3644
diff
changeset
|
2896 |
"Created: / 15.7.1998 / 13:32:29 / cg" |
523781600982
added #useIOInterrupts: to allow disabling this feature
Claus Gittinger <cg@exept.de>
parents:
3644
diff
changeset
|
2897 |
! ! |
523781600982
added #useIOInterrupts: to allow disabling this feature
Claus Gittinger <cg@exept.de>
parents:
3644
diff
changeset
|
2898 |
|
699 | 2899 |
!ProcessorScheduler methodsFor:'timeout handling'! |
2900 |
||
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
2901 |
addTimedBlock:aBlock after:timeDuration |
16496 | 2902 |
"add the argument, aBlock to the list of time-scheduled-blocks; to be |
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
2903 |
evaluated after timeDuration. The process which installs this timed |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
2904 |
block will be interrupted for execution of the block. |
16496 | 2905 |
(if it is running, the interrupt will occur in whatever method it is |
2906 |
executing; if it is suspended, it will be resumed). |
|
2907 |
The block will be removed from the timed-block list after evaluation |
|
2908 |
(i.e. it will trigger only once). |
|
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
2909 |
Returns an ID, which can be used in #removeTimeoutWidthID:" |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
2910 |
|
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
2911 |
^ self addTimedBlock:aBlock for:activeProcess afterMilliseconds:timeDuration getMilliseconds |
16496 | 2912 |
! |
2913 |
||
699 | 2914 |
addTimedBlock:aBlock afterMilliseconds:delta |
2915 |
"add the argument, aBlock to the list of time-scheduled-blocks; to be |
|
10747 | 2916 |
evaluated after delta milliseconds. The process which installs this timed |
699 | 2917 |
block will be interrupted for execution of the block. |
2918 |
(if it is running, the interrupt will occur in whatever method it is |
|
2919 |
executing; if it is suspended, it will be resumed). |
|
10747 | 2920 |
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
|
2921 |
(i.e. it will trigger only once). |
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
2922 |
Returns an ID, which can be used in #removeTimeoutWidthID:" |
699 | 2923 |
|
2924 |
^ self addTimedBlock:aBlock for:activeProcess afterMilliseconds:delta |
|
1676
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2925 |
|
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
2926 |
"Modified: 23.9.1996 / 14:33:59 / cg" |
699 | 2927 |
! |
2928 |
||
2929 |
addTimedBlock:aBlock afterSeconds:delta |
|
2930 |
"add the argument, aBlock to the list of time-scheduled-blocks. |
|
10747 | 2931 |
to be evaluated after delta seconds. The process which installs this timed |
699 | 2932 |
block will be interrupted for execution of the block. |
2933 |
(if it is running, the interrupt will occur in whatever method it is |
|
2934 |
executing; if it is suspended, it will be resumed). |
|
10747 | 2935 |
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
|
2936 |
(i.e. it will trigger only once). |
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
2937 |
Returns an ID, which can be used in #removeTimeoutWidthID:" |
699 | 2938 |
|
1676
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2939 |
^ self addTimedBlock:aBlock for:activeProcess afterMilliseconds:(delta * 1000) rounded |
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2940 |
|
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
2941 |
"Modified: 23.9.1996 / 14:34:04 / cg" |
699 | 2942 |
! |
2943 |
||
2944 |
addTimedBlock:aBlock atMilliseconds:aMillisecondTime |
|
2945 |
"add the argument, aBlock to the list of time-scheduled-blocks; to be |
|
2946 |
evaluated when the millisecondClock value passes aMillisecondTime. |
|
10747 | 2947 |
The process which installs this timed block will be interrupted for |
699 | 2948 |
execution of the block. |
2949 |
(if it is running, the interrupt will occur in whatever method it is |
|
2950 |
executing; if it is suspended, it will be resumed). |
|
10747 | 2951 |
The block will be removed from the timed-block list after evaluation |
2952 |
(i.e. it will trigger only once). |
|
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
2953 |
Returns an ID, which can be used in #removeTimeoutWidthID:" |
699 | 2954 |
|
1676
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2955 |
^ self addTimedBlock:aBlock for:activeProcess atMilliseconds:aMillisecondTime |
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
2956 |
|
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
2957 |
"Modified: 23.9.1996 / 14:34:09 / cg" |
699 | 2958 |
! |
2959 |
||
16496 | 2960 |
addTimedBlock:aBlock for:aProcess after:timeDuration |
2961 |
"add the argument, aBlock to the list of time-scheduled-blocks. |
|
2962 |
to be evaluated after timeDuration. aProcess will be interrupted for |
|
2963 |
execution of the block. |
|
2964 |
(if it is running, the interrupt will occur in whatever method it is |
|
2965 |
executing; if it is suspended, it will be resumed). |
|
2966 |
If aProcess is nil, the block will be evaluated by the scheduler itself |
|
2967 |
(which is dangerous - the block should not raise any error conditions). |
|
2968 |
The block will be removed from the timed-block list after evaluation |
|
2969 |
(i.e. it will trigger only once). |
|
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
2970 |
Returns an ID, which can be used in #removeTimeoutWidthID:" |
16496 | 2971 |
|
2972 |
^ self addTimedBlock:aBlock for:aProcess afterMilliseconds:timeDuration getMilliseconds |
|
2973 |
||
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
2974 |
"Modified: 23.9.1996 / 14:34:18 / cg" |
16496 | 2975 |
! |
2976 |
||
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
2977 |
addTimedBlock:aBlock for:aProcess afterMilliseconds:delta |
699 | 2978 |
"add the argument, aBlock to the list of time-scheduled-blocks; to be |
2979 |
evaluated after delta milliseconds. The process specified by the argument, |
|
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
2980 |
aProcess will be interrupted for execution of the block. |
699 | 2981 |
(if it is running, the interrupt will occur in whatever method it is |
2982 |
executing; if it is suspended, it will be resumed). |
|
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
2983 |
If aProcess is nil, the block will be evaluated by the scheduler itself |
699 | 2984 |
(which is dangerous - the block should not raise any error conditions). |
10747 | 2985 |
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
|
2986 |
(i.e. it will trigger only once). |
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
2987 |
Returns an ID, which can be used in #removeTimeoutWidthID:" |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
2988 |
|
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
2989 |
|now then wasBlocked id| |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
2990 |
|
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
2991 |
wasBlocked := OperatingSystem blockInterrupts. |
699 | 2992 |
now := OperatingSystem getMillisecondTime. |
2993 |
then := OperatingSystem millisecondTimeAdd:now and:delta. |
|
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
2994 |
id := self addTimedBlock:aBlock for:aProcess atMilliseconds:then. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
2995 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
2996 |
^ id |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
2997 |
|
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
2998 |
"Modified: 23.9.1996 / 14:34:13 / cg" |
699 | 2999 |
! |
3000 |
||
3001 |
addTimedBlock:aBlock for:aProcess afterSeconds:delta |
|
3002 |
"add the argument, aBlock to the list of time-scheduled-blocks. |
|
10747 | 3003 |
to be evaluated after delta seconds. aProcess will be interrupted for |
699 | 3004 |
execution of the block. |
3005 |
(if it is running, the interrupt will occur in whatever method it is |
|
3006 |
executing; if it is suspended, it will be resumed). |
|
3007 |
If aProcess is nil, the block will be evaluated by the scheduler itself |
|
3008 |
(which is dangerous - the block should not raise any error conditions). |
|
10747 | 3009 |
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
|
3010 |
(i.e. it will trigger only once). |
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3011 |
Returns an ID, which can be used in #removeTimeoutWidthID:" |
699 | 3012 |
|
1676
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
3013 |
^ self addTimedBlock:aBlock for:aProcess afterMilliseconds:(delta * 1000) rounded |
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
3014 |
|
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3015 |
"Modified: 23.9.1996 / 14:34:18 / cg" |
699 | 3016 |
! |
3017 |
||
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3018 |
addTimedBlock:aBlock for:aProcess atMilliseconds:aMillisecondTime |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3019 |
"add the argument, aBlock to the list of time-scheduled-blocks; |
20736 | 3020 |
to be evaluated by aProcess when the millisecondClock value passes |
10747 | 3021 |
aMillisecondTime. |
20736 | 3022 |
If that block is already in the timeout list, its trigger-time is changed. |
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3023 |
The process specified by the argument, aProcess |
20736 | 3024 |
will be interrupted for execution of the block. |
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3025 |
If aProcess is nil, the block will be evaluated by the scheduler itself |
20736 | 3026 |
(which is dangerous: the block should not raise any error conditions). |
10747 | 3027 |
If the process is active at trigger time, the interrupt will occur in |
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3028 |
whatever method it is executing; |
20736 | 3029 |
if suspended at trigger time, it will be resumed. |
10747 | 3030 |
The block will be removed from the timed-block list after evaluation |
3031 |
(i.e. it will trigger only once). |
|
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3032 |
Returns an ID, which can be used in #removeTimeoutWidthID:" |
699 | 3033 |
|
3034 |
|index "{ Class: SmallInteger }" |
|
3035 |
wasBlocked| |
|
3036 |
||
3037 |
wasBlocked := OperatingSystem blockInterrupts. |
|
3038 |
index := timeoutActionArray identityIndexOf:aBlock startingAt:1. |
|
3039 |
index ~~ 0 ifTrue:[ |
|
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3040 |
timeoutArray at:index put:aMillisecondTime |
699 | 3041 |
] ifFalse:[ |
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3042 |
index := timeoutArray indexOf:nil. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3043 |
index ~~ 0 ifTrue:[ |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3044 |
timeoutArray at:index put:aMillisecondTime. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3045 |
timeoutActionArray at:index put:aBlock. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3046 |
timeoutSemaphoreArray at:index put:nil. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3047 |
timeoutProcessArray at:index put:aProcess |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3048 |
] ifFalse:[ |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3049 |
timeoutArray := timeoutArray copyWith:aMillisecondTime. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3050 |
timeoutActionArray := timeoutActionArray copyWith:aBlock. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3051 |
timeoutSemaphoreArray := timeoutSemaphoreArray copyWith:nil. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3052 |
timeoutProcessArray := timeoutProcessArray copyWith:aProcess. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3053 |
index := timeoutArray size. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3054 |
]. |
699 | 3055 |
]. |
3056 |
||
3057 |
anyTimeouts := true. |
|
3058 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
1676
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
3059 |
^ index |
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
3060 |
|
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3061 |
"Modified: 23.9.1996 / 14:34:23 / cg" |
1676
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
3062 |
! |
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
3063 |
|
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
3064 |
addTimeoutFunctionCall:anExternalFunction for:aProcess afterMilliseconds:delta with:argument |
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
3065 |
"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
|
3066 |
after some millisecond-Delay. |
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
3067 |
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
|
3068 |
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
|
3069 |
in this processes context. |
10747 | 3070 |
The callBack 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
|
3071 |
(i.e. it will trigger only once). |
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3072 |
Returns an ID, which can be used in #removeTimeoutWidthID:" |
1676
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
3073 |
|
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
3074 |
|now then wasBlocked id| |
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
3075 |
|
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
3076 |
wasBlocked := OperatingSystem blockInterrupts. |
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
3077 |
now := OperatingSystem getMillisecondTime. |
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
3078 |
then := OperatingSystem millisecondTimeAdd:now and:delta. |
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
3079 |
|
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
3080 |
id := self |
18295 | 3081 |
addTimeoutFunctionCall:anExternalFunction |
3082 |
for:aProcess |
|
3083 |
atMilliseconds:then |
|
3084 |
with:argument. |
|
1676
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
3085 |
|
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
3086 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
3087 |
^ id |
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
3088 |
|
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3089 |
"Created: 23.9.1996 / 14:28:27 / cg" |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3090 |
"Modified: 23.9.1996 / 14:34:42 / cg" |
1676
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
3091 |
! |
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
3092 |
|
1681 | 3093 |
addTimeoutFunctionCall:anExternalFunction for:aProcess atMilliseconds:milliTime with:argument |
1676
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
3094 |
"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
|
3095 |
at some millisecond-time. |
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
3096 |
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
|
3097 |
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
|
3098 |
in this processes context. |
10747 | 3099 |
The callBack 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
|
3100 |
(i.e. it will trigger only once). |
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3101 |
Returns an ID, which can be used in #removeTimeoutWidthID:" |
1676
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
3102 |
|
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
3103 |
|action| |
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
3104 |
|
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
3105 |
action := [anExternalFunction callWith:argument]. |
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
3106 |
^ self |
18295 | 3107 |
addTimedBlock:action |
3108 |
for:aProcess |
|
3109 |
atMilliseconds:milliTime. |
|
1676
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
3110 |
|
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3111 |
"Created: 23.9.1996 / 14:29:30 / cg" |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3112 |
"Modified: 23.9.1996 / 14:34:57 / cg" |
699 | 3113 |
! |
3114 |
||
3115 |
evaluateTimeouts |
|
3116 |
"walk through timeouts and evaluate blocks or signal semas that need to be .." |
|
3117 |
||
16210 | 3118 |
|sema now aTime block blocksAndProcessesToEvaluate |
18295 | 3119 |
firstBlockToEvaluate firstProcess |
16231 | 3120 |
n "{ Class: SmallInteger }" |
15657 | 3121 |
indexOfLastTimeout "{ Class: SmallInteger }" |
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3122 |
halfSize "{ Class: SmallInteger }" |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3123 |
wasBlocked p| |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3124 |
|
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3125 |
anyTimeouts ifFalse:[ ^ self]. |
11164
8cbff6ed574f
#timeToNextTimeout - handling of negative time deltas
Stefan Vogel <sv@exept.de>
parents:
10748
diff
changeset
|
3126 |
anyTimeouts := false. |
19858 | 3127 |
indexOfLastTimeout := 0. |
699 | 3128 |
|
18295 | 3129 |
"have to collect the blocks first, then evaluate them. |
16210 | 3130 |
This avoids problems due to newly inserted blocks." |
3131 |
||
3132 |
"/ notice: the code looks uglier than seems to be required; |
|
3133 |
"/ the observation is that in almost all cases, only a single block (or no block at all) |
|
3134 |
"/ is found in the loops below. |
|
16231 | 3135 |
"/ To avoid idle memory allocation, we avoid the allocation of the OrderedCollection in this case, |
3136 |
"/ by remembering the first block+process in a variable until another block is found. |
|
16210 | 3137 |
"/ Thus firstBlockToEvaluate+firstProcess effectively cache the first slot of the lazy allocated collection. |
3138 |
"/ looks ugly, but as this is called very often, reduces idle allocation by a lot. |
|
699 | 3139 |
|
3140 |
now := OperatingSystem getMillisecondTime. |
|
3141 |
n := timeoutArray size. |
|
3142 |
1 to:n do:[:index | |
|
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3143 |
aTime := timeoutArray at:index. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3144 |
aTime notNil ifTrue:[ |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3145 |
(OperatingSystem millisecondTime:now isAfter:aTime) ifTrue:[ |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3146 |
"this one should be triggered" |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3147 |
|
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3148 |
sema := timeoutSemaphoreArray at:index. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3149 |
sema notNil ifTrue:[ |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3150 |
timeoutSemaphoreArray at:index put:nil. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3151 |
timedActionCounter := (timedActionCounter + 1 bitAnd:SmallInteger maxVal). |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3152 |
sema signalOnce. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3153 |
] ifFalse:[ |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3154 |
"to support pure-events" |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3155 |
block := timeoutActionArray at:index. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3156 |
block notNil ifTrue:[ |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3157 |
"/ usually (>99%), there is only one single timeout action to call; |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3158 |
"/ avoid creation of an OrderedCollection |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3159 |
firstBlockToEvaluate isNil ifTrue:[ |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3160 |
firstBlockToEvaluate := block. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3161 |
firstProcess := timeoutProcessArray at:index. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3162 |
] ifFalse:[ |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3163 |
blocksAndProcessesToEvaluate isNil ifTrue:[ |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3164 |
blocksAndProcessesToEvaluate := OrderedCollection |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3165 |
with:firstBlockToEvaluate |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3166 |
with:firstProcess. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3167 |
]. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3168 |
blocksAndProcessesToEvaluate add:block. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3169 |
blocksAndProcessesToEvaluate add:(timeoutProcessArray at:index). |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3170 |
]. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3171 |
timeoutActionArray at:index put:nil. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3172 |
timeoutProcessArray at:index put:nil. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3173 |
] |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3174 |
]. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3175 |
timeoutArray at:index put:nil. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3176 |
] ifFalse:[ |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3177 |
"there are still pending timeouts" |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3178 |
anyTimeouts := true. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3179 |
indexOfLastTimeout := index. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3180 |
] |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3181 |
] |
699 | 3182 |
]. |
3183 |
||
16231 | 3184 |
"shrink the arrays, if they are 50% free" |
15657 | 3185 |
n > 20 ifTrue:[ |
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3186 |
halfSize := n // 2. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3187 |
(indexOfLastTimeout ~~ 0 and:[indexOfLastTimeout < halfSize]) ifTrue:[ |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3188 |
wasBlocked := OperatingSystem blockInterrupts. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3189 |
(timeoutArray at:indexOfLastTimeout+1) isNil ifTrue:[ "/ no new timeouts arrived |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3190 |
timeoutArray := timeoutArray copyTo:halfSize. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3191 |
timeoutSemaphoreArray := timeoutSemaphoreArray copyTo:halfSize. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3192 |
timeoutActionArray := timeoutActionArray copyTo:halfSize. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3193 |
timeoutProcessArray := timeoutProcessArray copyTo:halfSize. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3194 |
]. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3195 |
wasBlocked ifFalse:[ OperatingSystem unblockInterrupts ]. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3196 |
]. |
15657 | 3197 |
]. |
3198 |
||
19850 | 3199 |
"/ usually (>99%), there is only one single timeout action to call; |
20706
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20643
diff
changeset
|
3200 |
"/ above code avoided the creation of an OrderedCollection |
16210 | 3201 |
blocksAndProcessesToEvaluate isNil ifTrue:[ |
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3202 |
firstBlockToEvaluate notNil ifTrue:[ |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3203 |
timedActionCounter := (timedActionCounter + 1 bitAnd:SmallInteger maxVal). |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3204 |
(firstProcess isNil or:[firstProcess == scheduler or:[PureEventDriven]]) ifTrue:[ |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3205 |
firstBlockToEvaluate value |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3206 |
] ifFalse:[ |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3207 |
firstProcess isDead ifTrue:[ |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3208 |
"/ a timedBlock for a process which has already terminated |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3209 |
"/ issue a warning and do not execute it. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3210 |
"/ (executing here may be dangerous, since it would run at scheduler priority here, |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3211 |
"/ and thereby could block the whole smalltalk system. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3212 |
"/ For this reason is it IGNORED here.) |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3213 |
|
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3214 |
"/ Could handle it in timeoutProcess, but we don't, |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3215 |
"/ because otherwise timeouts might be reissued forever... |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3216 |
"/ (timeoutHandlerProcess notNil and:[timeoutHandlerProcess isDead not]) ifTrue:[ |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3217 |
"/ timeoutHandlerProcess interruptWith:block. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3218 |
"/ ] ifFalse:[ |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3219 |
('ProcessorScheduler [warning]: cannot evaluate timedBlock (', firstBlockToEvaluate displayString, ') for dead process: ''' , firstProcess name , '''') errorPrintCR. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3220 |
"/ ]. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3221 |
] ifFalse:[ |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3222 |
firstProcess interruptWith:firstBlockToEvaluate |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3223 |
] |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3224 |
] |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3225 |
]. |
16210 | 3226 |
] ifFalse:[ |
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3227 |
n := blocksAndProcessesToEvaluate size. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3228 |
1 to:n by:2 do:[:index | |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3229 |
block := blocksAndProcessesToEvaluate at:index. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3230 |
p := blocksAndProcessesToEvaluate at:index+1. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3231 |
(p isNil or:[p == scheduler or:[PureEventDriven]]) ifTrue:[ |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3232 |
block value. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3233 |
timedActionCounter := (timedActionCounter + 1 bitAnd:SmallInteger maxVal). |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3234 |
] ifFalse:[ |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3235 |
p isDead ifTrue:[ |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3236 |
"/ a timedBlock for a process which has already terminated |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3237 |
"/ issue a warning and do not execute it. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3238 |
"/ (executing here may be dangerous, since it would run at scheduler priority here, |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3239 |
"/ and thereby could block the whole smalltalk system. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3240 |
"/ For this reason is it IGNORED here.) |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3241 |
|
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3242 |
"/ Could handle it in timeoutProcess, but we don't, |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3243 |
"/ because otherwise timeouts might be reissued forever... |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3244 |
"/ (timeoutHandlerProcess notNil and:[timeoutHandlerProcess isDead not]) ifTrue:[ |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3245 |
"/ timeoutHandlerProcess interruptWith:block. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3246 |
"/ ] ifFalse:[ |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3247 |
('ProcessorScheduler [warning]: cannot evaluate timedBlock (', block displayString, ') for dead process: ''' , p name , '''') errorPrintCR. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3248 |
"/ ]. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3249 |
] ifFalse:[ |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3250 |
timedActionCounter := (timedActionCounter + 1 bitAnd:SmallInteger maxVal). |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3251 |
p interruptWith:block |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3252 |
] |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3253 |
] |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3254 |
] |
16210 | 3255 |
]. |
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3256 |
|
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3257 |
"Modified: / 30-07-2013 / 19:33:24 / cg" |
699 | 3258 |
! |
3259 |
||
3260 |
removeTimedBlock:aBlock |
|
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3261 |
"remove the argument, aBlock from the list of time-sceduled-blocks." |
699 | 3262 |
|
3263 |
|index "{ Class: SmallInteger }" |
|
3264 |
wasBlocked| |
|
3265 |
||
3916 | 3266 |
aBlock isNil ifTrue:[^ self]. |
3267 |
||
699 | 3268 |
wasBlocked := OperatingSystem blockInterrupts. |
3269 |
index := timeoutActionArray identityIndexOf:aBlock startingAt:1. |
|
3270 |
(index ~~ 0) ifTrue:[ |
|
18295 | 3271 |
timeoutArray at:index put:nil. |
3272 |
timeoutActionArray at:index put:nil. |
|
3273 |
timeoutSemaphoreArray at:index put:nil. |
|
3274 |
timeoutProcessArray at:index put:nil. |
|
699 | 3275 |
]. |
3276 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
1676
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
3277 |
! |
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
3278 |
|
20052 | 3279 |
removeTimeoutForSemaphore:aSemaphore |
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3280 |
"remove the timeOut that signals aSemaphore |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3281 |
from the list of time-scheduled-blocks." |
20052 | 3282 |
|
3283 |
|index "{ Class: SmallInteger }" |
|
3284 |
wasBlocked| |
|
3285 |
||
3286 |
wasBlocked := OperatingSystem blockInterrupts. |
|
3287 |
||
3288 |
index := 0. |
|
20736 | 3289 |
[ |
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3290 |
index := timeoutSemaphoreArray identityIndexOf:aSemaphore startingAt:index+1. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3291 |
index ~~ 0 |
20736 | 3292 |
] whileTrue:[ |
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3293 |
timeoutArray at:index put:nil. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3294 |
timeoutSemaphoreArray at:index put:nil. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3295 |
timeoutActionArray at:index put:nil. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3296 |
timeoutProcessArray at:index put:nil. |
20052 | 3297 |
]. |
3298 |
||
3299 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
3300 |
! |
|
3301 |
||
1680 | 3302 |
removeTimeoutWithID:anID |
1676
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
3303 |
"remove the timeOut with anID (as returned by #addTimedBlock) |
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3304 |
from the list of time-scheduled-blocks." |
1676
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
3305 |
|
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
3306 |
|index "{ Class: SmallInteger }" |
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
3307 |
wasBlocked| |
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
3308 |
|
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
3309 |
index := anID. |
1680 | 3310 |
(index > 0) ifTrue:[ |
18295 | 3311 |
wasBlocked := OperatingSystem blockInterrupts. |
3312 |
||
3313 |
timeoutArray at:index put:nil. |
|
3314 |
timeoutActionArray at:index put:nil. |
|
3315 |
timeoutSemaphoreArray at:index put:nil. |
|
3316 |
timeoutProcessArray at:index put:nil. |
|
3317 |
||
3318 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
1680 | 3319 |
] |
1676
12b3b5dcf68f
return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents:
1641
diff
changeset
|
3320 |
|
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3321 |
"Created: 23.9.1996 / 14:32:33 / cg" |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3322 |
"Modified: 23.9.1996 / 14:35:09 / cg" |
9437 | 3323 |
! |
3324 |
||
18774 | 3325 |
removeTimeoutWithID:anID object:aBlockOrSemaphore |
3326 |
"remove the timeOut with anID (as returned by #addTimedBlock) |
|
3327 |
from the list of time-scheduled-blocks. |
|
3328 |
If aBlockOrSempahore is not nil, check if the id is really for the block |
|
3329 |
or for the semphore." |
|
3330 |
||
3331 |
|index "{ Class: SmallInteger }" |
|
3332 |
wasBlocked| |
|
3333 |
||
3334 |
index := anID. |
|
18776 | 3335 |
(anID notNil and:[index > 0]) ifTrue:[ |
19850 | 3336 |
wasBlocked := OperatingSystem blockInterrupts. |
3337 |
||
3338 |
(aBlockOrSemaphore notNil |
|
3339 |
and:[(timeoutActionArray at:index ifAbsent:[]) ~~ aBlockOrSemaphore |
|
3340 |
and:[(timeoutSemaphoreArray at:index ifAbsent:[]) ~~ aBlockOrSemaphore]]) ifTrue:[ |
|
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3341 |
'Processor: trying to remove stale timeout id - ignored' errorPrintCR. |
19850 | 3342 |
] ifFalse:[ |
3343 |
timeoutArray at:index put:nil. |
|
3344 |
timeoutActionArray at:index put:nil. |
|
3345 |
timeoutSemaphoreArray at:index put:nil. |
|
3346 |
timeoutProcessArray at:index put:nil. |
|
3347 |
]. |
|
3348 |
||
3349 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
18774 | 3350 |
] |
3351 |
! |
|
3352 |
||
9437 | 3353 |
timeoutHandlerProcess |
9452 | 3354 |
(timeoutHandlerProcess isNil or:[timeoutHandlerProcess isDead]) ifTrue:[ |
18295 | 3355 |
timeoutHandlerProcess := |
3356 |
[ |
|
3357 |
[ |
|
3358 |
self timeoutHandlerProcessLoop. |
|
3359 |
] ensure:[ |
|
3360 |
timeoutHandlerProcess := nil |
|
3361 |
]. |
|
3362 |
] newProcess. |
|
3363 |
||
3364 |
timeoutHandlerProcess |
|
3365 |
priority:TimingPriority; |
|
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3366 |
name:'timeout handler'; |
18295 | 3367 |
beSystemProcess; |
3368 |
resume. |
|
9437 | 3369 |
]. |
3370 |
^ timeoutHandlerProcess. |
|
9450 | 3371 |
|
9452 | 3372 |
"Modified: / 20-07-2006 / 09:52:27 / cg" |
9437 | 3373 |
! |
3374 |
||
3375 |
timeoutHandlerProcessLoop |
|
10489
e55d1a27d02b
Mark timeoutHandlerProcess as system process
Stefan Vogel <sv@exept.de>
parents:
10435
diff
changeset
|
3376 |
"The timeoutHandlerProcess does nothing but wait. |
19850 | 3377 |
It exists only, so that timeout blocks may be executed in its context |
3378 |
(i.e. it will always just wait forever, and perform timeout actions |
|
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3379 |
in its interrupt handler)." |
14775 | 3380 |
|
20887 | 3381 |
|mySema| |
3382 |
||
3383 |
mySema := Semaphore new name:'timeoutHandler'. |
|
16538 | 3384 |
[ |
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3385 |
[ |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3386 |
mySema wait. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3387 |
] on:Exception do:[:ex| |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3388 |
"/ an error occurred in one of the timeout actions. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3389 |
|
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3390 |
"ignore errors, but tell the user" |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3391 |
InfoPrinting == true ifTrue:[ |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3392 |
('ProcessorScheduler [warning]: error while handling timeouts in TimeoutHandlerProcess: ''' , ex description , '''') infoPrintCR. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3393 |
thisContext fullPrintAll. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3394 |
]. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3395 |
]. |
16538 | 3396 |
] loop. |
25422
3b02b0f1f647
Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
23107
diff
changeset
|
3397 |
|
3b02b0f1f647
Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
23107
diff
changeset
|
3398 |
"Modified (comment): / 23-02-2019 / 09:18:28 / Claus Gittinger" |
3b02b0f1f647
Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
23107
diff
changeset
|
3399 |
! |
3b02b0f1f647
Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
23107
diff
changeset
|
3400 |
|
3b02b0f1f647
Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
23107
diff
changeset
|
3401 |
timeoutList |
3b02b0f1f647
Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
23107
diff
changeset
|
3402 |
"return (a copy of) the list of current timeouts; only for debugging (i.e. for the monitor). |
3b02b0f1f647
Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
23107
diff
changeset
|
3403 |
The info is a pair where the first element is the current time (in OS-milliseconds) |
3b02b0f1f647
Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
23107
diff
changeset
|
3404 |
and the second element is a collection of timeouts which are valid at this time." |
3b02b0f1f647
Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
23107
diff
changeset
|
3405 |
|
3b02b0f1f647
Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
23107
diff
changeset
|
3406 |
|info wasBlocked now| |
3b02b0f1f647
Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
23107
diff
changeset
|
3407 |
|
3b02b0f1f647
Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
23107
diff
changeset
|
3408 |
wasBlocked := OperatingSystem blockInterrupts. |
3b02b0f1f647
Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
23107
diff
changeset
|
3409 |
now := OperatingSystem getMillisecondTime. |
3b02b0f1f647
Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
23107
diff
changeset
|
3410 |
info := OrderedCollection new. |
3b02b0f1f647
Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
23107
diff
changeset
|
3411 |
1 to:timeoutActionArray size do:[:i | |
3b02b0f1f647
Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
23107
diff
changeset
|
3412 |
|time| |
3b02b0f1f647
Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
23107
diff
changeset
|
3413 |
|
3b02b0f1f647
Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
23107
diff
changeset
|
3414 |
time := timeoutArray at:i. |
3b02b0f1f647
Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
23107
diff
changeset
|
3415 |
time notNil ifTrue:[ |
3b02b0f1f647
Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
23107
diff
changeset
|
3416 |
info add:((SmallDictionary new:4) |
3b02b0f1f647
Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
23107
diff
changeset
|
3417 |
at:'time' put:time; |
3b02b0f1f647
Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
23107
diff
changeset
|
3418 |
at:'action' put:(timeoutActionArray at:i); |
3b02b0f1f647
Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
23107
diff
changeset
|
3419 |
at:'sema' put:(timeoutSemaphoreArray at:i); |
3b02b0f1f647
Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
23107
diff
changeset
|
3420 |
at:'process' put:(timeoutProcessArray at:i); |
3b02b0f1f647
Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
23107
diff
changeset
|
3421 |
yourself) |
3b02b0f1f647
Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
23107
diff
changeset
|
3422 |
] |
3b02b0f1f647
Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
23107
diff
changeset
|
3423 |
]. |
3b02b0f1f647
Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
23107
diff
changeset
|
3424 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
3b02b0f1f647
Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
23107
diff
changeset
|
3425 |
^ { now . info } |
3b02b0f1f647
Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
23107
diff
changeset
|
3426 |
|
3b02b0f1f647
Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
23107
diff
changeset
|
3427 |
" |
3b02b0f1f647
Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
23107
diff
changeset
|
3428 |
Processor timeoutList |
3b02b0f1f647
Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
23107
diff
changeset
|
3429 |
" |
3b02b0f1f647
Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
23107
diff
changeset
|
3430 |
|
3b02b0f1f647
Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
23107
diff
changeset
|
3431 |
"Modified: / 05-02-2020 / 15:31:39 / Stefan Vogel" |
10 | 3432 |
! ! |
1 | 3433 |
|
6619 | 3434 |
!ProcessorScheduler methodsFor:'wait hooks'! |
3435 |
||
3436 |
addPreWaitAction:aBlock |
|
3437 |
"add the argument, aBlock to the list of preWait-actions. |
|
3438 |
These blocks are evaluated right before the CPU is given up for the OS-wait. |
|
3439 |
(i.e. the OS-wait for next event or timeout). |
|
3440 |
Systems with buffered output (i.e. Xlib) can install a flush-block here, |
|
3441 |
to force unflushed output to be sent out in regular intervals)" |
|
3442 |
||
3443 |
|wasBlocked| |
|
3444 |
||
3445 |
wasBlocked := OperatingSystem blockInterrupts. |
|
3446 |
preWaitActions isNil ifTrue:[ |
|
18295 | 3447 |
preWaitActions := OrderedCollection new |
6619 | 3448 |
]. |
3449 |
preWaitActions add:aBlock. |
|
3450 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
3451 |
! |
|
3452 |
||
3453 |
removePreWaitAction:aBlock |
|
3454 |
"remove the argument, aBlock from the list of preWait-actions." |
|
3455 |
||
3456 |
|wasBlocked| |
|
3457 |
||
3458 |
wasBlocked := OperatingSystem blockInterrupts. |
|
3459 |
preWaitActions notNil ifTrue:[ |
|
3460 |
preWaitActions removeIdentical:aBlock ifAbsent:nil |
|
3461 |
]. |
|
3462 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
3463 |
! ! |
|
3464 |
||
10 | 3465 |
!ProcessorScheduler methodsFor:'waiting'! |
3466 |
||
20722 | 3467 |
checkForEndOfDispatch |
20736 | 3468 |
|wasBlocked| |
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3469 |
|
20722 | 3470 |
exitWhenNoMoreUserProcesses ifTrue:[ |
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3471 |
"/ check if there are any processes at all |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3472 |
"/ stop dispatching if there is none |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3473 |
"/ (and anyTimeouts is false, which means that no timeout blocks are present) |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3474 |
"/ and no readSemaphores are present (which means that noone is waiting for input) |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3475 |
"/ and no writeSemaphores are present |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3476 |
wasBlocked := OperatingSystem blockInterrupts. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3477 |
|
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3478 |
"/ 'scheduled: ' _errorPrint. self anyScheduledWindowGroupAtAll asString _errorPrintCR. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3479 |
"/ 'anyUserProcess: ' _errorPrint. self anyUserProcessAtAll asString _errorPrintCR. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3480 |
|
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3481 |
self anyScheduledWindowGroupAtAll ifFalse:[ |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3482 |
self anyUserProcessAtAll ifFalse:[ |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3483 |
Smalltalk verbose ifTrue:[ |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3484 |
'Processor [info]: end of dispatch' infoPrintCR. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3485 |
]. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3486 |
dispatching := false. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3487 |
"/ false ifTrue:[ |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3488 |
"/ MiniInspector basicNew printInstVarsOf:self. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3489 |
"/ MiniDebugger enter:thisContext withMessage:'about to exit' mayProceed:true. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3490 |
"/ ]. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3491 |
]. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3492 |
]. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3493 |
|
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3494 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
20722 | 3495 |
]. |
3496 |
! |
|
3497 |
||
7510
46a848d466b5
select: wake up readFDs if readable only;
Claus Gittinger <cg@exept.de>
parents:
7495
diff
changeset
|
3498 |
checkForIOWithTimeout:millis |
699 | 3499 |
"this is called, when there is absolutely nothing to do; |
7510
46a848d466b5
select: wake up readFDs if readable only;
Claus Gittinger <cg@exept.de>
parents:
7495
diff
changeset
|
3500 |
hard wait for either input to arrive, or output to be possible |
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3501 |
or a timeout to occur." |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3502 |
|
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3503 |
|nReady index sema action wasBlocked err fd readyIndex |
18957 | 3504 |
newProcessMaybeReady fdOrPid exceptArray| |
2116
1bcb6ee86fca
fixed pending sigChild problem;
Claus Gittinger <cg@exept.de>
parents:
2111
diff
changeset
|
3505 |
|
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3506 |
"/ must enable interrupts, to be able to get out of a |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3507 |
"/ long wait (especially, to handle sigChild in the meantime) |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3508 |
|
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3509 |
wasBlocked := OperatingSystem unblockInterrupts. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3510 |
|
7493
5c67c45b11cb
New select for fair scheduling (not giving low filedescriptors
Stefan Vogel <sv@exept.de>
parents:
7264
diff
changeset
|
3511 |
newProcessMaybeReady := false. |
14943 | 3512 |
readableResultFdArray size < readFdArray size ifTrue:[ |
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3513 |
readableResultFdArray := Array new:(40 max:readFdArray size). |
14943 | 3514 |
]. |
3515 |
writableResultFdArray size < writeFdArray size ifTrue:[ |
|
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3516 |
writableResultFdArray := Array new:(40 max:writeFdArray size). |
14943 | 3517 |
]. |
7510
46a848d466b5
select: wake up readFDs if readable only;
Claus Gittinger <cg@exept.de>
parents:
7495
diff
changeset
|
3518 |
|
18957 | 3519 |
exceptArray := exceptFdArray. |
3520 |
||
16858 | 3521 |
OperatingSystem isMSWINDOWSlike ifTrue:[ |
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3522 |
"/ |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3523 |
"/ win32 does a WaitForMultipleObjects in select... |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3524 |
"/ unix waits for SIGCHLD |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3525 |
"/ |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3526 |
|hasPids| |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3527 |
|
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3528 |
hasPids := false. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3529 |
osChildExitActions keysDo:[:eachPid| |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3530 |
eachPid address = 0 ifTrue:[ |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3531 |
Logger warning:'Processor: remove 0-handle pid: %1' with:eachPid. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3532 |
osChildExitActions safeRemoveKey:eachPid. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3533 |
] ifFalse:[ |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3534 |
hasPids := true. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3535 |
]. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3536 |
]. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3537 |
hasPids ifTrue:[ |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3538 |
exceptArray := (exceptArray upTo:nil), osChildExitActions keys asArray. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3539 |
"/'exceptArray: ' print. exceptArray printCR. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3540 |
]. |
16338 | 3541 |
]. |
3542 |
||
18957 | 3543 |
exceptResultFdArray size < exceptArray size ifTrue:[ |
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3544 |
exceptResultFdArray := Array new:(40 max:exceptArray size). |
18957 | 3545 |
]. |
3546 |
||
7510
46a848d466b5
select: wake up readFDs if readable only;
Claus Gittinger <cg@exept.de>
parents:
7495
diff
changeset
|
3547 |
nReady := OperatingSystem |
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3548 |
selectOnAnyReadable:readFdArray |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3549 |
writable:writeFdArray |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3550 |
exception:exceptArray |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3551 |
readableInto:readableResultFdArray |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3552 |
writableInto:writableResultFdArray |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3553 |
exceptionInto:exceptResultFdArray |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3554 |
withTimeOut:millis. |
1061
61012b7bed9c
protect myself against invalid fd's in readFdArray/writeFdArray
Claus Gittinger <cg@exept.de>
parents:
1042
diff
changeset
|
3555 |
|
2116
1bcb6ee86fca
fixed pending sigChild problem;
Claus Gittinger <cg@exept.de>
parents:
2111
diff
changeset
|
3556 |
wasBlocked ifTrue:[ |
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3557 |
OperatingSystem blockInterrupts. |
2116
1bcb6ee86fca
fixed pending sigChild problem;
Claus Gittinger <cg@exept.de>
parents:
2111
diff
changeset
|
3558 |
]. |
1bcb6ee86fca
fixed pending sigChild problem;
Claus Gittinger <cg@exept.de>
parents:
2111
diff
changeset
|
3559 |
|
11836
0d70352a70bc
Avoid blocking in PipeStream (e.g. when doing a CVS checkin)
Stefan Vogel <sv@exept.de>
parents:
11622
diff
changeset
|
3560 |
nReady <= 0 ifTrue:[ |
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3561 |
"/ either still nothing to do, |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3562 |
"/ or error (which should not happen) |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3563 |
|
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3564 |
(nReady < 0 and:[(err := OperatingSystem lastErrorSymbol) notNil]) ifTrue:[ |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3565 |
err == #EBADF ifTrue:[ |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3566 |
"/ mhmh - one of the fd's given to me is corrupt. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3567 |
"/ find out which one .... and remove it |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3568 |
self removeCorruptedFds |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3569 |
] ifFalse:[ |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3570 |
err == #ENOENT ifTrue:[ |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3571 |
'Processor [warning]: ENOENT in select; rd=' infoPrint. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3572 |
readFdArray infoPrint. ' wr=' infoPrint. writeFdArray infoPrintCR. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3573 |
] ifFalse:[ |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3574 |
'Processor [warning]: error in select: ' infoPrint. err infoPrintCR. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3575 |
] |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3576 |
]. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3577 |
] |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3578 |
] ifFalse:[ |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3579 |
readyIndex := 1. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3580 |
[nReady > 0 |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3581 |
and:[ readyIndex <= readableResultFdArray size |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3582 |
and:[ (fd := readableResultFdArray at:readyIndex) notNil ]] |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3583 |
] whileTrue:[ |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3584 |
index := readFdArray identityIndexOf:fd. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3585 |
index ~~ 0 ifTrue:[ |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3586 |
action := readCheckArray at:index. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3587 |
sema := readSemaphoreArray at:index. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3588 |
sema notNil ifTrue:[ |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3589 |
sema signalOnce. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3590 |
newProcessMaybeReady := true. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3591 |
action isNil ifTrue:[ |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3592 |
"before May 2014 we disabled the sema in the caller after wakeup. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3593 |
This caused ST/X to consume 100% cpu, when the caller didn't read |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3594 |
the data (e.g. because his process was stopped)." |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3595 |
"disable possible write side and timeouts as well" |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3596 |
self disableSemaphore:sema. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3597 |
]. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3598 |
]. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3599 |
(action notNil and:[action value]) ifTrue:[ |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3600 |
newProcessMaybeReady := true. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3601 |
]. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3602 |
]. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3603 |
nReady := nReady - 1. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3604 |
readyIndex := readyIndex + 1. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3605 |
]. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3606 |
|
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3607 |
readyIndex := 1. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3608 |
[nReady > 0 |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3609 |
and:[ readyIndex <= writableResultFdArray size |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3610 |
and:[ (fd := writableResultFdArray at:readyIndex) notNil ]] |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3611 |
] whileTrue:[ |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3612 |
index := writeFdArray identityIndexOf:fd. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3613 |
index ~~ 0 ifTrue:[ |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3614 |
action := writeCheckArray at:index. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3615 |
sema := writeSemaphoreArray at:index. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3616 |
sema notNil ifTrue:[ |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3617 |
sema signalOnce. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3618 |
newProcessMaybeReady := true. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3619 |
action isNil ifTrue:[ |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3620 |
"now this is a one shot operation - see the input above" |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3621 |
"disable possible read side and timeouts as well" |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3622 |
self disableSemaphore:sema. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3623 |
]. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3624 |
]. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3625 |
(action notNil and:[action value]) ifTrue:[ |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3626 |
newProcessMaybeReady := true. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3627 |
]. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3628 |
]. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3629 |
nReady := nReady - 1. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3630 |
readyIndex := readyIndex + 1. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3631 |
]. |
18957 | 3632 |
|
3633 |
"/'except result got: ' print. exceptArray printCR. exceptResultFdArray printCR. |
|
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3634 |
readyIndex := 1. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3635 |
[nReady > 0 |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3636 |
and:[ readyIndex <= exceptResultFdArray size |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3637 |
and:[ (fdOrPid := exceptResultFdArray at:readyIndex) notNil ]] |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3638 |
] whileTrue:[ |
18957 | 3639 |
"/'except got: ' print. fdOrPid printCR. |
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3640 |
index := exceptFdArray identityIndexOf:fdOrPid. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3641 |
index ~~ 0 ifTrue:[ |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3642 |
sema := exceptSemaphoreArray at:index. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3643 |
sema notNil ifTrue:[ |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3644 |
sema signalOnce. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3645 |
newProcessMaybeReady := true. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3646 |
"disable possible read/write side and timeouts as well" |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3647 |
self disableSemaphore:sema. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3648 |
]. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3649 |
] ifFalse:[ "may be a PID?" |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3650 |
|osProcessStatus actionBlock| |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3651 |
|
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3652 |
actionBlock := osChildExitActions removeKey:fdOrPid ifAbsent:nil. |
18957 | 3653 |
"/'pid signaled: ' print. fdOrPid printCR. |
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3654 |
actionBlock notNil ifTrue:[ |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3655 |
osProcessStatus := OperatingSystem childProcessWait:false pid:fdOrPid. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3656 |
(osProcessStatus notNil and:[osProcessStatus pid = fdOrPid]) ifTrue:[ |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3657 |
actionBlock value:osProcessStatus. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3658 |
newProcessMaybeReady := true. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3659 |
]. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3660 |
]. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3661 |
]. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3662 |
nReady := nReady - 1. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3663 |
readyIndex := readyIndex + 1. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3664 |
]. |
699 | 3665 |
]. |
7493
5c67c45b11cb
New select for fair scheduling (not giving low filedescriptors
Stefan Vogel <sv@exept.de>
parents:
7264
diff
changeset
|
3666 |
^ newProcessMaybeReady |
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
|
3667 |
|
10233 | 3668 |
"Modified: / 12-04-1996 / 09:31:22 / stefan" |
10269
c9eae9f888c7
changed #checkForIOWithTimeout:
Claus Gittinger <cg@exept.de>
parents:
10268
diff
changeset
|
3669 |
"Modified: / 07-12-2006 / 19:48:17 / cg" |
699 | 3670 |
! |
3671 |
||
10 | 3672 |
ioInterrupt |
1787
32632b6f969d
remember threadSwitch:from: idea for later implementation;
Claus Gittinger <cg@exept.de>
parents:
1783
diff
changeset
|
3673 |
"{ Pragma: +returnable }" |
32632b6f969d
remember threadSwitch:from: idea for later implementation;
Claus Gittinger <cg@exept.de>
parents:
1783
diff
changeset
|
3674 |
|
10747 | 3675 |
"data arrived while waiting - switch to scheduler process which will decide |
1783
be7402f74d94
hide timerInterrupt & ioInterrupt contexts when switching
Claus Gittinger <cg@exept.de>
parents:
1780
diff
changeset
|
3676 |
what to do now. |
be7402f74d94
hide timerInterrupt & ioInterrupt contexts when switching
Claus Gittinger <cg@exept.de>
parents:
1780
diff
changeset
|
3677 |
This method is called by the VM' interrupt handling mechanism. |
be7402f74d94
hide timerInterrupt & ioInterrupt contexts when switching
Claus Gittinger <cg@exept.de>
parents:
1780
diff
changeset
|
3678 |
Notice, that at the time of the message, we are still in the context |
be7402f74d94
hide timerInterrupt & ioInterrupt contexts when switching
Claus Gittinger <cg@exept.de>
parents:
1780
diff
changeset
|
3679 |
of whichever process is currently running." |
10 | 3680 |
|
804
264d440a67a0
Fixes when useIOInterrupts == true.
Stefan Vogel <sv@exept.de>
parents:
786
diff
changeset
|
3681 |
gotIOInterrupt := true. |
2966 | 3682 |
activeProcess ~~ scheduler ifTrue:[ |
20706
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20643
diff
changeset
|
3683 |
interruptCounter := interruptCounter + 1 bitAnd:SmallInteger maxVal. |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20643
diff
changeset
|
3684 |
interruptedProcess := activeProcess. |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20643
diff
changeset
|
3685 |
self threadSwitch:scheduler |
2966 | 3686 |
] |
804
264d440a67a0
Fixes when useIOInterrupts == true.
Stefan Vogel <sv@exept.de>
parents:
786
diff
changeset
|
3687 |
|
264d440a67a0
Fixes when useIOInterrupts == true.
Stefan Vogel <sv@exept.de>
parents:
786
diff
changeset
|
3688 |
"Modified: 21.12.1995 / 16:17:40 / stefan" |
2831
02f9aa61f71b
ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents:
2830
diff
changeset
|
3689 |
"Modified: 4.8.1997 / 14:23:08 / cg" |
10 | 3690 |
! |
3691 |
||
1086 | 3692 |
removeCorruptedFds |
10747 | 3693 |
"this is sent when select returns an error due to some invalid |
3694 |
fileDescriptor. May happen, if someone does a readWait/writeWait on a |
|
3695 |
socket connection, which somehow got corrupted |
|
2280 | 3696 |
(shutdown by partner, or closed by another thread, while being in a read/write-wait). |
10747 | 3697 |
Without special care, all following selects would immediately return with |
1086 | 3698 |
an #EBADF error, leading to high-frequency polling and a locked up system. |
3699 |
(you could still fix things by interrupting on the console and fixing the |
|
3700 |
readFdArray/writeFdArray in the debugger)" |
|
3701 |
||
3702 |
readFdArray keysAndValuesDo:[:idx :fd | |
|
20706
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20643
diff
changeset
|
3703 |
|result sema| |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20643
diff
changeset
|
3704 |
|
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20643
diff
changeset
|
3705 |
fd notNil ifTrue:[ |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20643
diff
changeset
|
3706 |
result := OperatingSystem |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20643
diff
changeset
|
3707 |
selectOnAnyReadable:(Array with:fd) writable:nil exception:nil |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20643
diff
changeset
|
3708 |
readableInto:nil writableInto:nil exceptionInto:nil |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20643
diff
changeset
|
3709 |
withTimeOut:0. |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20643
diff
changeset
|
3710 |
|
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20643
diff
changeset
|
3711 |
result < 0 ifTrue:[ |
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3712 |
'Processor [info]: removing invalid read-select fileDescriptor: ' infoPrint. fd infoPrint. ' idx: 'infoPrint. idx infoPrintCR. |
20706
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20643
diff
changeset
|
3713 |
readFdArray at:idx put:nil. |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20643
diff
changeset
|
3714 |
readCheckArray at:idx put:nil. |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20643
diff
changeset
|
3715 |
(sema := readSemaphoreArray at:idx) notNil ifTrue:[ |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20643
diff
changeset
|
3716 |
readSemaphoreArray at:idx put:nil. |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20643
diff
changeset
|
3717 |
self removeTimeoutForSemaphore:sema. |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20643
diff
changeset
|
3718 |
sema signalForAll. |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20643
diff
changeset
|
3719 |
]. |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20643
diff
changeset
|
3720 |
] |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20643
diff
changeset
|
3721 |
]. |
1086 | 3722 |
]. |
3723 |
||
3724 |
writeFdArray keysAndValuesDo:[:idx :fd | |
|
20706
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20643
diff
changeset
|
3725 |
|result sema| |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20643
diff
changeset
|
3726 |
|
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20643
diff
changeset
|
3727 |
fd notNil ifTrue:[ |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20643
diff
changeset
|
3728 |
result := OperatingSystem |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20643
diff
changeset
|
3729 |
selectOnAnyReadable:nil writable:(Array with:fd) exception:nil |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20643
diff
changeset
|
3730 |
readableInto:nil writableInto:nil exceptionInto:nil |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20643
diff
changeset
|
3731 |
withTimeOut:0. |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20643
diff
changeset
|
3732 |
|
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20643
diff
changeset
|
3733 |
result < 0 ifTrue:[ |
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3734 |
'Processor [info]: removing invalid write-select fileDescriptor: ' infoPrint. fd infoPrint. ' idx: 'infoPrint. idx infoPrintCR. |
20706
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20643
diff
changeset
|
3735 |
writeFdArray at:idx put:nil. |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20643
diff
changeset
|
3736 |
writeCheckArray at:idx put:nil. |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20643
diff
changeset
|
3737 |
(sema := writeSemaphoreArray at:idx) notNil ifTrue:[ |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20643
diff
changeset
|
3738 |
writeSemaphoreArray at:idx put:nil. |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20643
diff
changeset
|
3739 |
self removeTimeoutForSemaphore:sema. |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20643
diff
changeset
|
3740 |
sema signalForAll. |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20643
diff
changeset
|
3741 |
]. |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20643
diff
changeset
|
3742 |
] |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20643
diff
changeset
|
3743 |
] |
1086 | 3744 |
]. |
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
|
3745 |
|
18957 | 3746 |
exceptFdArray keysAndValuesDo:[:idx :fd | |
20706
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20643
diff
changeset
|
3747 |
|result sema| |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20643
diff
changeset
|
3748 |
|
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20643
diff
changeset
|
3749 |
fd notNil ifTrue:[ |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20643
diff
changeset
|
3750 |
result := OperatingSystem |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20643
diff
changeset
|
3751 |
selectOnAnyReadable:nil writable:nil exception:(Array with:fd) |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20643
diff
changeset
|
3752 |
readableInto:nil writableInto:nil exceptionInto:nil |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20643
diff
changeset
|
3753 |
withTimeOut:0. |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20643
diff
changeset
|
3754 |
|
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20643
diff
changeset
|
3755 |
result < 0 ifTrue:[ |
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3756 |
'Processor [info]: removing invalid exception-select fileDescriptor: ' infoPrint. fd infoPrint. ' idx: 'infoPrint. idx infoPrintCR. |
20706
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20643
diff
changeset
|
3757 |
exceptFdArray at:idx put:nil. |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20643
diff
changeset
|
3758 |
(sema := exceptSemaphoreArray at:idx) notNil ifTrue:[ |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20643
diff
changeset
|
3759 |
exceptSemaphoreArray at:idx put:nil. |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20643
diff
changeset
|
3760 |
self removeTimeoutForSemaphore:sema. |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20643
diff
changeset
|
3761 |
sema signalForAll. |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20643
diff
changeset
|
3762 |
]. |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20643
diff
changeset
|
3763 |
] |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20643
diff
changeset
|
3764 |
] |
18957 | 3765 |
]. |
3766 |
||
3767 |
||
16858 | 3768 |
OperatingSystem isMSWINDOWSlike ifTrue:[ |
20706
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20643
diff
changeset
|
3769 |
"/ |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20643
diff
changeset
|
3770 |
"/ win32 does a WaitForMultipleObjects in select... |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20643
diff
changeset
|
3771 |
"/ unix waits for SIGCHLD |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20643
diff
changeset
|
3772 |
"/ |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20643
diff
changeset
|
3773 |
osChildExitActions keysDo:[:eachPid | |
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3774 |
|result sema| |
20706
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20643
diff
changeset
|
3775 |
|
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20643
diff
changeset
|
3776 |
eachPid notNil ifTrue:[ |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20643
diff
changeset
|
3777 |
result := OperatingSystem |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20643
diff
changeset
|
3778 |
selectOnAnyReadable:nil writable:nil exception:(Array with:eachPid) |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20643
diff
changeset
|
3779 |
readableInto:nil writableInto:nil exceptionInto:nil |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20643
diff
changeset
|
3780 |
withTimeOut:0. |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20643
diff
changeset
|
3781 |
|
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20643
diff
changeset
|
3782 |
result < 0 ifTrue:[ |
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3783 |
'Processor [info]: removing invalid exception-select pid: ' infoPrint. eachPid infoPrintCR. |
20706
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20643
diff
changeset
|
3784 |
osChildExitActions safeRemoveKey:eachPid. |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20643
diff
changeset
|
3785 |
] |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20643
diff
changeset
|
3786 |
] |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20643
diff
changeset
|
3787 |
]. |
16338 | 3788 |
]. |
3789 |
||
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3790 |
"Modified: 12.4.1996 / 09:32:58 / stefan" |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3791 |
"Modified: 27.1.1997 / 20:09:27 / cg" |
1086 | 3792 |
! |
3793 |
||
750
f4ed622893ce
added schedulerInterrupt - for soon to come semaSignal primitive function
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
3794 |
schedulerInterrupt |
f4ed622893ce
added schedulerInterrupt - for soon to come semaSignal primitive function
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
3795 |
"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
|
3796 |
what to do now." |
f4ed622893ce
added schedulerInterrupt - for soon to come semaSignal primitive function
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
3797 |
|
2966 | 3798 |
activeProcess ~~ scheduler ifTrue:[ |
20706
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20643
diff
changeset
|
3799 |
interruptCounter := interruptCounter + 1 bitAnd:SmallInteger maxVal. |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20643
diff
changeset
|
3800 |
interruptedProcess := activeProcess. |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20643
diff
changeset
|
3801 |
self threadSwitch:scheduler |
2966 | 3802 |
] |
750
f4ed622893ce
added schedulerInterrupt - for soon to come semaSignal primitive function
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
3803 |
! |
f4ed622893ce
added schedulerInterrupt - for soon to come semaSignal primitive function
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
3804 |
|
10 | 3805 |
timeToNextTimeout |
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3806 |
"return the delta-T (in millis) to next timeout, or nil if |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3807 |
there is none" |
10 | 3808 |
|
231 | 3809 |
|aTime now delta minDelta n "{ Class: SmallInteger }"| |
10 | 3810 |
|
3811 |
"find next timeout. since there are usually not many, just search. |
|
302 | 3812 |
If there were many, the list should be kept sorted ... keeping deltas |
10 | 3813 |
to next (as in Unix kernel)" |
3814 |
||
231 | 3815 |
n := timeoutArray size. |
10 | 3816 |
1 to:n do:[:index | |
18295 | 3817 |
aTime := timeoutArray at:index. |
3818 |
aTime notNil ifTrue:[ |
|
3819 |
now isNil ifTrue:[ |
|
3820 |
now := OperatingSystem getMillisecondTime. |
|
3821 |
]. |
|
3822 |
delta := OperatingSystem millisecondTimeDeltaBetween:aTime and:now. |
|
3823 |
delta <= 0 ifTrue:[ |
|
25422
3b02b0f1f647
Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
23107
diff
changeset
|
3824 |
"timeout is due" |
18295 | 3825 |
^ 0. |
3826 |
]. |
|
3827 |
minDelta isNil ifTrue:[ |
|
3828 |
minDelta := delta |
|
3829 |
] ifFalse:[ |
|
3830 |
minDelta := minDelta min:delta |
|
3831 |
] |
|
3832 |
] |
|
15634 | 3833 |
]. |
3834 |
minDelta isNil ifTrue:[ |
|
18295 | 3835 |
"this is safe, since always called with interruptsBlocked" |
3836 |
anyTimeouts := false. |
|
10 | 3837 |
]. |
3838 |
||
3839 |
^ minDelta |
|
25422
3b02b0f1f647
Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
23107
diff
changeset
|
3840 |
|
3b02b0f1f647
Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
23107
diff
changeset
|
3841 |
"Modified (format): / 20-05-2020 / 17:27:04 / Stefan Vogel" |
10 | 3842 |
! |
3843 |
||
699 | 3844 |
timerInterrupt |
1787
32632b6f969d
remember threadSwitch:from: idea for later implementation;
Claus Gittinger <cg@exept.de>
parents:
1783
diff
changeset
|
3845 |
"{ Pragma: +returnable }" |
25422
3b02b0f1f647
Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
23107
diff
changeset
|
3846 |
<resource: #skipInDebuggersWalkBack> |
3b02b0f1f647
Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
23107
diff
changeset
|
3847 |
|
1787
32632b6f969d
remember threadSwitch:from: idea for later implementation;
Claus Gittinger <cg@exept.de>
parents:
1783
diff
changeset
|
3848 |
|
10747 | 3849 |
"timer expired while waiting - switch to scheduler process which will decide |
1783
be7402f74d94
hide timerInterrupt & ioInterrupt contexts when switching
Claus Gittinger <cg@exept.de>
parents:
1780
diff
changeset
|
3850 |
what to do now. |
be7402f74d94
hide timerInterrupt & ioInterrupt contexts when switching
Claus Gittinger <cg@exept.de>
parents:
1780
diff
changeset
|
3851 |
This method is called by the VM' interrupt handling mechanism. |
be7402f74d94
hide timerInterrupt & ioInterrupt contexts when switching
Claus Gittinger <cg@exept.de>
parents:
1780
diff
changeset
|
3852 |
Notice, that at the time of the message, we are still in the context |
be7402f74d94
hide timerInterrupt & ioInterrupt contexts when switching
Claus Gittinger <cg@exept.de>
parents:
1780
diff
changeset
|
3853 |
of whichever process is currently running." |
699 | 3854 |
|
2966 | 3855 |
activeProcess ~~ scheduler ifTrue:[ |
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3856 |
interruptCounter := interruptCounter + 1 bitAnd:SmallInteger maxVal. |
20706
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20643
diff
changeset
|
3857 |
interruptedProcess := activeProcess. |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
20643
diff
changeset
|
3858 |
self threadSwitch:scheduler |
2966 | 3859 |
] |
1783
be7402f74d94
hide timerInterrupt & ioInterrupt contexts when switching
Claus Gittinger <cg@exept.de>
parents:
1780
diff
changeset
|
3860 |
|
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3861 |
"Modified: 18.10.1996 / 20:35:54 / cg" |
699 | 3862 |
! |
3863 |
||
10 | 3864 |
waitForEventOrTimeout |
44 | 3865 |
"entered when no process is runnable - wait for either input on |
3866 |
any file descriptors to arrive or a timeout to happen. |
|
3867 |
If it makes sense, do some background garbage collection. |
|
3868 |
The idle actions are a leftover from previous ST/X releases and will |
|
93 | 3869 |
vanish (installing a low-prio process has the same effect)." |
44 | 3870 |
|
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3871 |
|millis doingGC dT| |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3872 |
|
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3873 |
doingGC := true. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3874 |
[doingGC] whileTrue:[ |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3875 |
anyTimeouts ifTrue:[ |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3876 |
millis := self timeToNextTimeout. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3877 |
(millis notNil and:[millis <= 0]) ifTrue:[ |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3878 |
^ self "oops - hurry up checking" |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3879 |
]. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3880 |
]. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3881 |
|
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3882 |
" |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3883 |
if its worth doing, collect a bit of garbage; |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3884 |
but not, if a backgroundCollector is active |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3885 |
" |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3886 |
ObjectMemory backgroundCollectorRunning ifTrue:[ |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3887 |
doingGC := false |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3888 |
] ifFalse:[ |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3889 |
doingGC := ObjectMemory gcStepIfUseful. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3890 |
]. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3891 |
|
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3892 |
"then do idle actions" |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3893 |
(idleActions notNil and:[idleActions size ~~ 0]) ifTrue:[ |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3894 |
idleActions do:[:aBlock | |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3895 |
aBlock value. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3896 |
]. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3897 |
^ self "go back checking" |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3898 |
]. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3899 |
|
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3900 |
doingGC ifTrue:[ |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3901 |
(self checkForIOWithTimeout:0) ifTrue:[ |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3902 |
^ self "go back checking" |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3903 |
] |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3904 |
] |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3905 |
]. |
10 | 3906 |
|
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
|
3907 |
exitWhenNoMoreUserProcesses ifTrue:[ |
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3908 |
"/ check if there are any processes at all |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3909 |
"/ stop dispatching if there is none |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3910 |
"/ (and anyTimeouts is false, which means that no timeout blocks are present) |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3911 |
"/ and no readSemaphores are present (which means that noone is waiting for input) |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3912 |
"/ and no writeSemaphores are present |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3913 |
|
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3914 |
"/ cg: changed to only check when a process terminated |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3915 |
"/ self checkForEndOfDispatch. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3916 |
dispatching ifFalse:[ |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3917 |
^ self |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3918 |
]. |
6619 | 3919 |
]. |
3920 |
||
3921 |
preWaitActions notNil ifTrue:[ |
|
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3922 |
preWaitActions do:[:action | action value]. |
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
|
3923 |
]. |
10 | 3924 |
|
1627
f95285226059
infoPrint for NT (no select)
Claus Gittinger <cg@exept.de>
parents:
1618
diff
changeset
|
3925 |
"/ |
f95285226059
infoPrint for NT (no select)
Claus Gittinger <cg@exept.de>
parents:
1618
diff
changeset
|
3926 |
"/ absolutely nothing to do - simply wait |
f95285226059
infoPrint for NT (no select)
Claus Gittinger <cg@exept.de>
parents:
1618
diff
changeset
|
3927 |
"/ |
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3928 |
OperatingSystem supportsSelect ifFalse:[ |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3929 |
"SCO instant ShitStation has a bug here, |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3930 |
waiting always 1 sec in the select - therefore we delay a bit and |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3931 |
return - effectively polling in 50ms cycles |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3932 |
" |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3933 |
(self checkForIOWithTimeout:0) ifTrue:[ |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3934 |
^ self "go back checking" |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3935 |
]. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3936 |
OperatingSystem millisecondDelay:EventPollingInterval. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3937 |
^ self |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3938 |
]. |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3939 |
|
25422
3b02b0f1f647
Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
23107
diff
changeset
|
3940 |
useIOInterrupts ifTrue:[ |
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3941 |
dT := 999999 |
25422
3b02b0f1f647
Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
23107
diff
changeset
|
3942 |
] ifFalse:[ |
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3943 |
dT := EventPollingInterval |
10 | 3944 |
]. |
3945 |
||
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3946 |
millis isNil ifTrue:[ |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3947 |
millis := dT. |
3745 | 3948 |
] ifFalse:[ |
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3949 |
millis := millis rounded min:dT. |
3745 | 3950 |
]. |
3951 |
||
25429
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3952 |
self checkForIOWithTimeout:millis |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3953 |
|
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3954 |
"Modified: 14.12.1995 / 13:37:46 / stefan" |
14ed0c85e7ab
Backout changes in 3b02b0f1f647 to `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents:
25422
diff
changeset
|
3955 |
"Modified: 18.7.1996 / 20:42:17 / cg" |
10 | 3956 |
! ! |
3957 |
||
1783
be7402f74d94
hide timerInterrupt & ioInterrupt contexts when switching
Claus Gittinger <cg@exept.de>
parents:
1780
diff
changeset
|
3958 |
!ProcessorScheduler class methodsFor:'documentation'! |
10 | 3959 |
|
699 | 3960 |
version |
18620
b4e9f25d6ce6
preparations for lined index list in WeakArray
Claus Gittinger <cg@exept.de>
parents:
18295
diff
changeset
|
3961 |
^ '$Header$' |
12717 | 3962 |
! |
3963 |
||
3964 |
version_CVS |
|
18620
b4e9f25d6ce6
preparations for lined index list in WeakArray
Claus Gittinger <cg@exept.de>
parents:
18295
diff
changeset
|
3965 |
^ '$Header$' |
1 | 3966 |
! ! |
6939
6f6ea7b0a5ab
stopping an suspended process fix
Claus Gittinger <cg@exept.de>
parents:
6807
diff
changeset
|
3967 |
|
14771 | 3968 |
|
699 | 3969 |
ProcessorScheduler initialize! |