21 classVariableNames:'KnownProcesses KnownProcessIds |
21 classVariableNames:'KnownProcesses KnownProcessIds |
22 PureEventDriven |
22 PureEventDriven |
23 UserSchedulingPriority |
23 UserSchedulingPriority |
24 UserInterruptPriority |
24 UserInterruptPriority |
25 TimingPriority |
25 TimingPriority |
|
26 HighestPriority |
26 SchedulingPriority' |
27 SchedulingPriority' |
27 poolDictionaries:'' |
28 poolDictionaries:'' |
28 category:'Kernel-Processes' |
29 category:'Kernel-Processes' |
29 ! |
30 ! |
30 |
31 |
31 ProcessorScheduler comment:' |
32 ProcessorScheduler comment:' |
32 COPYRIGHT (c) 1993 by Claus Gittinger |
33 COPYRIGHT (c) 1993 by Claus Gittinger |
33 All Rights Reserved |
34 All Rights Reserved |
34 |
35 |
35 $Header: /cvs/stx/stx/libbasic/ProcessorScheduler.st,v 1.27 1995-02-05 21:33:24 claus Exp $ |
36 $Header: /cvs/stx/stx/libbasic/ProcessorScheduler.st,v 1.28 1995-02-08 03:11:03 claus Exp $ |
36 '! |
37 '! |
37 |
38 |
38 Smalltalk at:#Processor put:nil! |
39 Smalltalk at:#Processor put:nil! |
39 |
40 |
40 !ProcessorScheduler class methodsFor:'documentation'! |
41 !ProcessorScheduler class methodsFor:'documentation'! |
89 |
90 |
90 class variables: |
91 class variables: |
91 |
92 |
92 KnownProcesses <Collection> all known processes |
93 KnownProcesses <Collection> all known processes |
93 KnownProcessIds <Collection> and their IDs |
94 KnownProcessIds <Collection> and their IDs |
|
95 |
94 PureEventDriven <Boolean> true, if no process support |
96 PureEventDriven <Boolean> true, if no process support |
95 is available |
97 is available |
|
98 |
96 UserSchedulingPriority <Integer> the priority at which normal |
99 UserSchedulingPriority <Integer> the priority at which normal |
97 user interfaces run |
100 user interfaces run |
|
101 |
98 UserInterruptPriority the priority at which user- |
102 UserInterruptPriority the priority at which user- |
99 interrupts (Cntl-C) processing |
103 interrupts (Cntl-C) processing |
100 takes place. Processes with |
104 takes place. Processes with |
101 a greater or equal priority are |
105 a greater or equal priority are |
102 not interruptable. |
106 not interruptable. |
|
107 |
103 TimingPriority the priority used for timing. |
108 TimingPriority the priority used for timing. |
104 Processes with a greater or |
109 Processes with a greater or |
105 equal priority are not interrupted |
110 equal priority are not interrupted |
106 by timers. |
111 by timers. |
|
112 |
|
113 HighestPriority The highest allowed prio for processes |
|
114 |
107 SchedulingPriority The priority of the scheduler (must |
115 SchedulingPriority The priority of the scheduler (must |
108 me higher than any other). |
116 me higher than any other). |
109 |
117 |
110 |
118 |
111 most interresting methods: |
119 most interresting methods: |
132 |
140 |
133 UserSchedulingPriority := 8. |
141 UserSchedulingPriority := 8. |
134 UserInterruptPriority := 24. |
142 UserInterruptPriority := 24. |
135 TimingPriority := 16. |
143 TimingPriority := 16. |
136 SchedulingPriority := 31. |
144 SchedulingPriority := 31. |
|
145 HighestPriority := 30. |
137 |
146 |
138 Processor isNil ifTrue:[ |
147 Processor isNil ifTrue:[ |
139 "create the one and only processor" |
148 "create the one and only processor" |
140 |
149 |
141 Processor := self basicNew initialize. |
150 Processor := self basicNew initialize. |
304 (dont add any message sends here) |
313 (dont add any message sends here) |
305 " |
314 " |
306 activeProcess := aProcess. |
315 activeProcess := aProcess. |
307 currentPriority := pri. |
316 currentPriority := pri. |
308 %{ |
317 %{ |
309 extern OBJ __threadSwitch(), __threadSwitchWithSingleStep(); |
318 extern OBJ ___threadSwitch(); |
310 |
319 |
311 if (singleStep == true) |
320 ok = ___threadSwitch(__context, _intVal(id), (singleStep == true) ? 1 : 0); |
312 ok = __threadSwitchWithSingleStep(__context, _intVal(id)); |
|
313 else |
|
314 ok = __threadSwitch(__context, _intVal(id)); |
|
315 %}. |
321 %}. |
316 "time passes spent in some other process ... |
322 "time passes spent in some other process ... |
317 ... here again" |
323 ... here again" |
318 |
324 |
319 p := activeProcess. |
325 p := activeProcess. |
600 |
606 |
601 " |
607 " |
602 check if the running process is not the only one |
608 check if the running process is not the only one |
603 " |
609 " |
604 l size ~~ 1 ifTrue:[ |
610 l size ~~ 1 ifTrue:[ |
605 " |
611 " |
606 bring running process to the end |
612 bring running process to the end |
607 " |
613 " |
608 l removeFirst. |
614 l removeFirst. |
609 l addLast:activeProcess. |
615 l addLast:activeProcess. |
610 |
616 |
611 " |
617 " |
612 and switch to first in the list |
618 and switch to first in the list |
613 " |
619 " |
614 self threadSwitch:(l first). |
620 self threadSwitch:(l first). |
615 ]. |
621 ]. |
616 wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
622 wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
617 ! |
623 ! |
618 |
624 |
619 suspend:aProcess |
625 suspend:aProcess |
952 !ProcessorScheduler methodsFor:'queries'! |
958 !ProcessorScheduler methodsFor:'queries'! |
953 |
959 |
954 highestPriorityRunnableProcess |
960 highestPriorityRunnableProcess |
955 "return the highest prio runnable process" |
961 "return the highest prio runnable process" |
956 |
962 |
957 |l p maxPri "{ Class: SmallInteger }" | |
963 |listArray l p maxPri "{ Class: SmallInteger }" | |
958 |
964 |
959 maxPri := self highestPriority. |
965 maxPri := HighestPriority. |
|
966 listArray := quiescentProcessLists. |
960 maxPri to:1 by:-1 do:[:prio | |
967 maxPri to:1 by:-1 do:[:prio | |
961 l := quiescentProcessLists at:prio. |
968 l := listArray at:prio. |
962 l notNil ifTrue:[ |
969 l notNil ifTrue:[ |
963 l isEmpty ifTrue:[ |
970 l isEmpty ifTrue:[ |
964 " |
971 " |
965 on the fly clear out empty lists |
972 on the fly clear out empty lists |
966 " |
973 " |
967 quiescentProcessLists at:prio put:nil |
974 listArray at:prio put:nil |
968 ] ifFalse:[ |
975 ] ifFalse:[ |
969 p := l first. |
976 p := l first. |
970 " |
977 " |
971 if it got corrupted somehow |
978 if it got corrupted somehow |
972 " |
979 " |
980 ] |
987 ] |
981 ]. |
988 ]. |
982 ^ nil |
989 ^ nil |
983 ! |
990 ! |
984 |
991 |
|
992 isSystemProcess:aProcess |
|
993 "return true if aProcess is a system process, |
|
994 which should not be suspended/terminated etc.." |
|
995 |
|
996 (self class isPureEventDriven |
|
997 or:[aProcess id == 0 |
|
998 or:[aProcess nameOrId endsWith:'dispatcher']]) ifTrue:[ |
|
999 ^ true |
|
1000 ]. |
|
1001 ^ false |
|
1002 |
|
1003 " |
|
1004 Processor activeProcessIsSystemProcess |
|
1005 " |
|
1006 ! |
|
1007 |
985 activeProcessIsSystemProcess |
1008 activeProcessIsSystemProcess |
986 "return true if the active process is a system process, |
1009 "return true if the active process is a system process, |
987 which should not be suspended." |
1010 which should not be suspended." |
988 |
1011 |
989 |active| |
1012 ^ self isSystemProcess:activeProcess |
990 |
|
991 (self class isPureEventDriven |
|
992 or:[(active := self activeProcess) id == 0 |
|
993 or:[active nameOrId endsWith:'dispatcher']]) ifTrue:[ |
|
994 ^ true |
|
995 ]. |
|
996 ^ false |
|
997 |
1013 |
998 " |
1014 " |
999 Processor activeProcessIsSystemProcess |
1015 Processor activeProcessIsSystemProcess |
1000 " |
1016 " |
1001 ! ! |
1017 ! ! |