ProcessorScheduler.st
author Stefan Vogel <sv@exept.de>
Fri, 27 Oct 2017 16:14:37 +0200
branchexpecco_2_11_1_branch
changeset 22329 20662662693b
parent 21009 d4035978c3c7
child 21027 ad86468de3a0
child 21099 284f7688b860
permissions -rw-r--r--
Add 2.11.0 Patch
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
     1
"
a27a279701f8 Initial revision
claus
parents:
diff changeset
     2
 COPYRIGHT (c) 1993 by Claus Gittinger
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
     3
	      All Rights Reserved
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
     4
a27a279701f8 Initial revision
claus
parents:
diff changeset
     5
 This software is furnished under a license and may be used
a27a279701f8 Initial revision
claus
parents:
diff changeset
     6
 only in accordance with the terms of that license and with the
a27a279701f8 Initial revision
claus
parents:
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
a27a279701f8 Initial revision
claus
parents:
diff changeset
     8
 be provided or otherwise made available to, or used by, any
a27a279701f8 Initial revision
claus
parents:
diff changeset
     9
 other person.  No title to or ownership of the software is
a27a279701f8 Initial revision
claus
parents:
diff changeset
    10
 hereby transferred.
a27a279701f8 Initial revision
claus
parents:
diff changeset
    11
"
5396
92bf7d0b1b66 Fix typo.
Stefan Vogel <sv@exept.de>
parents: 5389
diff changeset
    12
"{ Package: 'stx:libbasic' }"
92bf7d0b1b66 Fix typo.
Stefan Vogel <sv@exept.de>
parents: 5389
diff changeset
    13
17271
47341245c458 class: ProcessorScheduler
Claus Gittinger <cg@exept.de>
parents: 16858
diff changeset
    14
"{ NameSpace: Smalltalk }"
47341245c458 class: ProcessorScheduler
Claus Gittinger <cg@exept.de>
parents: 16858
diff changeset
    15
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    16
Object subclass:#ProcessorScheduler
15687
7679c998f5ac class: ProcessorScheduler
Claus Gittinger <cg@exept.de>
parents: 15658
diff changeset
    17
	instanceVariableNames:'quiescentProcessLists scheduler zombie activeProcess
7679c998f5ac class: ProcessorScheduler
Claus Gittinger <cg@exept.de>
parents: 15658
diff changeset
    18
		activeProcessId currentPriority readFdArray readSemaphoreArray
7679c998f5ac class: ProcessorScheduler
Claus Gittinger <cg@exept.de>
parents: 15658
diff changeset
    19
		readCheckArray writeFdArray writeSemaphoreArray writeCheckArray
7679c998f5ac class: ProcessorScheduler
Claus Gittinger <cg@exept.de>
parents: 15658
diff changeset
    20
		timeoutArray timeoutActionArray timeoutProcessArray
7679c998f5ac class: ProcessorScheduler
Claus Gittinger <cg@exept.de>
parents: 15658
diff changeset
    21
		timeoutSemaphoreArray idleActions anyTimeouts dispatching
7679c998f5ac class: ProcessorScheduler
Claus Gittinger <cg@exept.de>
parents: 15658
diff changeset
    22
		interruptedProcess useIOInterrupts gotIOInterrupt
7679c998f5ac class: ProcessorScheduler
Claus Gittinger <cg@exept.de>
parents: 15658
diff changeset
    23
		osChildExitActions gotChildSignalInterrupt
7679c998f5ac class: ProcessorScheduler
Claus Gittinger <cg@exept.de>
parents: 15658
diff changeset
    24
		exitWhenNoMoreUserProcesses suspendScheduler timeSliceProcess
7679c998f5ac class: ProcessorScheduler
Claus Gittinger <cg@exept.de>
parents: 15658
diff changeset
    25
		supportDynamicPriorities timeSliceNeededSemaphore
7679c998f5ac class: ProcessorScheduler
Claus Gittinger <cg@exept.de>
parents: 15658
diff changeset
    26
		scheduledProcesses preWaitActions timeoutHandlerProcess
18957
e0bb91eae748 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18941
diff changeset
    27
		readableResultFdArray writableResultFdArray exceptFdArray
19850
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
    28
		exceptResultFdArray exceptSemaphoreArray interruptCounter
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
    29
		timedActionCounter'
15687
7679c998f5ac class: ProcessorScheduler
Claus Gittinger <cg@exept.de>
parents: 15658
diff changeset
    30
	classVariableNames:'KnownProcesses KnownProcessIds PureEventDriven
7679c998f5ac class: ProcessorScheduler
Claus Gittinger <cg@exept.de>
parents: 15658
diff changeset
    31
		UserSchedulingPriority UserInterruptPriority TimingPriority
7679c998f5ac class: ProcessorScheduler
Claus Gittinger <cg@exept.de>
parents: 15658
diff changeset
    32
		HighestPriority SchedulingPriority MaxNumberOfProcesses
7679c998f5ac class: ProcessorScheduler
Claus Gittinger <cg@exept.de>
parents: 15658
diff changeset
    33
		InvalidProcessSignal TimeSlicingPriorityLimit TimeSliceInterval
16841
9e5808800de0 Added MaxProcessId variable & accessor.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16624
diff changeset
    34
		EventPollingInterval MaxProcessId'
15687
7679c998f5ac class: ProcessorScheduler
Claus Gittinger <cg@exept.de>
parents: 15658
diff changeset
    35
	poolDictionaries:''
7679c998f5ac class: ProcessorScheduler
Claus Gittinger <cg@exept.de>
parents: 15658
diff changeset
    36
	category:'Kernel-Processes'
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    37
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
    38
1783
be7402f74d94 hide timerInterrupt & ioInterrupt contexts when switching
Claus Gittinger <cg@exept.de>
parents: 1780
diff changeset
    39
!ProcessorScheduler class methodsFor:'documentation'!
88
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    40
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    41
copyright
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    42
"
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    43
 COPYRIGHT (c) 1993 by Claus Gittinger
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
    44
	      All Rights Reserved
88
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    45
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    46
 This software is furnished under a license and may be used
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    47
 only in accordance with the terms of that license and with the
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    48
 inclusion of the above copyright notice.   This software may not
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    49
 be provided or otherwise made available to, or used by, any
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    50
 other person.  No title to or ownership of the software is
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    51
 hereby transferred.
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    52
"
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    53
!
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    54
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    55
documentation
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    56
"
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    57
    This class has only one instance, which is bound to the global
2193
Claus Gittinger <cg@exept.de>
parents: 2191
diff changeset
    58
    'Processor' (well, on future multiprocessor systems, things may look
Claus Gittinger <cg@exept.de>
parents: 2191
diff changeset
    59
    different ... ;-). It is responsible for scheduling among the smalltalk
88
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    60
    processes (threads; not to confuse with heavy weight unix processes).
93
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
    61
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
    62
    Scheduling is fully done in smalltalk (the always runnable scheduler-
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
    63
    process, running at highest priority does this).
2193
Claus Gittinger <cg@exept.de>
parents: 2191
diff changeset
    64
    See the 'scheduling' documentation.
Claus Gittinger <cg@exept.de>
parents: 2191
diff changeset
    65
231
fd0e55e352f8 cleanup
claus
parents: 217
diff changeset
    66
    The main VM primitive to support this is found in threadSwitch, which passes
93
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
    67
    control to another process (usually selected by the scheduler).
159
514c749165c3 *** empty log message ***
claus
parents: 144
diff changeset
    68
    Thus it is possible to modify the schedulers policy and implementation
514c749165c3 *** empty log message ***
claus
parents: 144
diff changeset
    69
    at the smalltalk level.
93
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
    70
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
    71
    Notice: Smalltalk/X can (still) be compiled & configured without
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
    72
    process support. This non-process mode is called 'pureEventDriven' mode
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
    73
    and is useful to quickly port ST/X to systems, where these facilities
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
    74
    are either not needed (server applications), or are difficult to
10747
e9ea71d01445 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10497
diff changeset
    75
    implement (threads require some assembler support functions).
93
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
    76
    To allow pureEvent mode, kludges are built into some places in the
10747
e9ea71d01445 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10497
diff changeset
    77
    system, where either a process is forked, or a timeout is used instead
93
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
    78
    (for examples, see ProcessMonitor or MemoryMonitor).
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
    79
10747
e9ea71d01445 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10497
diff changeset
    80
    This pure-event mode may not be supported in the future
20810
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
    81
    (actually, it is no longer maintained, so don't run the system without Processes).
93
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
    82
6619
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
    83
    [instance variables:]
20810
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
    84
        quiescentProcessLists           - list of waiting processes
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
    85
        scheduler                       - the scheduler process itself
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
    86
        zombie                          - internal temporary (recently died process)
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
    87
        activeProcess                   - the current process
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
    88
        activeProcessId                 - the current processes id
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
    89
        currentPriority                 - the current processes priority
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
    90
        readFdArray                     - fd-sema-checkBlock triple-association
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
    91
        readSemaphoreArray                (stupid historic 3-separate arrays for hi-speed-optimization reasons)
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
    92
        readCheckArray
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
    93
        writeFdArray                    - fd-sema-checkBlock triple-association
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
    94
        writeSemaphoreArray               (stupid historic 3-separate arrays for hi-speed-optimization reasons)
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
    95
        writeCheckArray
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
    96
        timeoutArray                    - time-action-process-sema quadruple-association
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
    97
        timeoutActionArray                (stupid historic 3-separate arrays for hi-speed-optimization reasons)
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
    98
        timeoutProcessArray
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
    99
        timeoutSemaphoreArray
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   100
        idleActions                     - actions to be executed when idle
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   101
        preWaitActions                  - actions to be executed BEFORE going into an OS-wait
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   102
        anyTimeouts                     - flag if any timeouts are pending
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   103
        dispatching                     - flag if dispatch process is running (i.e. NOT initializing)
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   104
        interruptedProcess              - the currently interrupted process.
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   105
        useIOInterrupts                 - flag if the OS supports I/O interrupts and if they are used (to get me out of an OS wait)
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   106
        gotIOInterrupt                  - flag if I came out of a wait due to an I/O interrupt
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   107
        osChildExitActions              - OS chid process actions
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   108
        gotChildSignalInterrupt         - flag if I came out of a wait due to an OS child interrupt
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   109
        exitWhenNoMoreUserProcesses     - flag which controls if ST/X should exit when the last process dies (for standalone apps)
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   110
        suspendScheduler                - internal use
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   111
        timeSliceProcess                - the timeSlicer process
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   112
        supportDynamicPriorities        - flag if dynamic priorities should be supported by the timeSlicer
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   113
        scheduledProcesses              - list of scheduled processes for the timeSlicers dynamic prio handling
369
claus
parents: 362
diff changeset
   114
1273
f8449f53a6a3 commentary
Claus Gittinger <cg@exept.de>
parents: 1177
diff changeset
   115
    [class variables:]
93
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   116
20810
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   117
        KnownProcesses          <WeakArray>     all known processes
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   118
        KnownProcessIds         <Collection>    and their IDs
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   119
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   120
        PureEventDriven         <Boolean>       true, if no process support
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   121
                                                is available
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   122
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   123
        UserSchedulingPriority  <Integer>       the priority at which normal
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   124
                                                user interfaces run
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   125
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   126
        UserInterruptPriority                   the priority at which user-
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   127
                                                interrupts (Cntl-C) processing
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   128
                                                takes place. Processes with
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   129
                                                a greater or equal priority are
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   130
                                                not interruptable.
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   131
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   132
        TimingPriority                          the priority used for timing.
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   133
                                                Processes with a greater or
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   134
                                                equal priority are not interrupted
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   135
                                                by timers.
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   136
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   137
        HighestPriority                         The highest allowed prio for processes
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   138
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   139
        SchedulingPriority                      The priority of the scheduler (must
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   140
                                                me higher than any other).
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   141
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   142
        MaxNumberOfProcesses                    if non-nil, no more than this
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   143
                                                number of processes are allowed
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   144
                                                (for debugging)
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   145
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   146
        TimeSliceInterval                       for preemptive priority scheduling only:
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   147
                                                the time interval in millis, at which processes
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   148
                                                are timesliced
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   149
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   150
        TimeSlicingPriorityLimit                for preemptive priority scheduling only:
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   151
                                                processes are only timesliced, if running
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   152
                                                at or below this priority.
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   153
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   154
        EventPollingInterval                    for systems which do not support select on
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   155
                                                a fileDescriptor: the polling interval in millis.
2626
4194d370d46f made event polling interval a variable
Claus Gittinger <cg@exept.de>
parents: 2625
diff changeset
   156
759
908363ce8a32 interest is written with one 'r' (shame on me)
Claus Gittinger <cg@exept.de>
parents: 752
diff changeset
   157
    most interesting methods:
93
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   158
20810
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   159
        Processor>>suspend:                  (see also Process>>suspend)
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   160
        Processor>>resume:                   (see also Process>>resume)
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   161
        Processor>>terminate:                (see also Process>>terminate)
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   162
        Processor>>yield
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   163
        Processor>>changePriority:for:       (see also Process>>priority:
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   164
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   165
        Processor>>signal:afterSeconds:      (see also Delay>>forSeconds:)
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   166
        Processor>>signal:afterMilliseconds: (see also Delay>>forMilliseconds:)
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   167
        Processor>>signal:onInput:           (see also ExternalStream>>readWait)
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   168
        Processor>>signal:onOutput:          (see also ExternalStream>>writeWait)
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   169
        Processor>>disableSemaphore:
1273
f8449f53a6a3 commentary
Claus Gittinger <cg@exept.de>
parents: 1177
diff changeset
   170
f8449f53a6a3 commentary
Claus Gittinger <cg@exept.de>
parents: 1177
diff changeset
   171
f8449f53a6a3 commentary
Claus Gittinger <cg@exept.de>
parents: 1177
diff changeset
   172
    [see also:]
20810
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   173
        Process
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   174
        Delay Semaphore SemaphoreSet SharedQueue
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   175
        WindowGroup
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   176
        (``Working with processes'': programming/processes.html)
1294
e26bbb61f6b2 documentation
Claus Gittinger <cg@exept.de>
parents: 1273
diff changeset
   177
e26bbb61f6b2 documentation
Claus Gittinger <cg@exept.de>
parents: 1273
diff changeset
   178
    [author:]
20810
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   179
        Claus Gittinger
88
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
   180
"
2193
Claus Gittinger <cg@exept.de>
parents: 2191
diff changeset
   181
!
Claus Gittinger <cg@exept.de>
parents: 2191
diff changeset
   182
Claus Gittinger <cg@exept.de>
parents: 2191
diff changeset
   183
scheduling
Claus Gittinger <cg@exept.de>
parents: 2191
diff changeset
   184
"
10747
e9ea71d01445 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10497
diff changeset
   185
    By default, the scheduler does 'non preemptive priority scheduling';
e9ea71d01445 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10497
diff changeset
   186
e9ea71d01445 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10497
diff changeset
   187
    this means, that the highest priority runnable process
2193
Claus Gittinger <cg@exept.de>
parents: 2191
diff changeset
   188
    is choosen and allowed to run, until it either gives back the CPU (via #yield),
Claus Gittinger <cg@exept.de>
parents: 2191
diff changeset
   189
    or suspends (i.e. waiting for I/O, the time or a semaphore),
Claus Gittinger <cg@exept.de>
parents: 2191
diff changeset
   190
    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
   191
    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
   192
    (i.e. signalling a semaphore), by a timer or by IO availability.
2193
Claus Gittinger <cg@exept.de>
parents: 2191
diff changeset
   193
Claus Gittinger <cg@exept.de>
parents: 2191
diff changeset
   194
    If another process is runnable at the same priority, it will not
Claus Gittinger <cg@exept.de>
parents: 2191
diff changeset
   195
    be given CPU-time, unless one of the above happens.
Claus Gittinger <cg@exept.de>
parents: 2191
diff changeset
   196
Claus Gittinger <cg@exept.de>
parents: 2191
diff changeset
   197
    The consequence is, that a user process running at (say) priority 8,
Claus Gittinger <cg@exept.de>
parents: 2191
diff changeset
   198
    may block other user processes at the same priority, if it does heavy
Claus Gittinger <cg@exept.de>
parents: 2191
diff changeset
   199
    processing, or loops.
10747
e9ea71d01445 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10497
diff changeset
   200
    (the event handling which is responsible to care for userInterrupts,
e9ea71d01445 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10497
diff changeset
   201
     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
   202
     so that interrupting the process should always be possible).
2193
Claus Gittinger <cg@exept.de>
parents: 2191
diff changeset
   203
Claus Gittinger <cg@exept.de>
parents: 2191
diff changeset
   204
Claus Gittinger <cg@exept.de>
parents: 2191
diff changeset
   205
    The scheduler also supports 'timesliced priority scheduling', which is enabled
Claus Gittinger <cg@exept.de>
parents: 2191
diff changeset
   206
    via the #startTimeSlicing message (and disabled by #stopTimeSlicing).
Claus Gittinger <cg@exept.de>
parents: 2191
diff changeset
   207
    In this mode, the highest priority running process is suspended in regular intervals
Claus Gittinger <cg@exept.de>
parents: 2191
diff changeset
   208
    (the TimeSliceInterval) IFF there is another runnable process with the same priority.
Claus Gittinger <cg@exept.de>
parents: 2191
diff changeset
   209
    I.e. the top highest priority processes are timeshared.
Claus Gittinger <cg@exept.de>
parents: 2191
diff changeset
   210
    In this mode, the other processes will also get a chance to make some progress - however,
Claus Gittinger <cg@exept.de>
parents: 2191
diff changeset
   211
    lower priority process will only run, IFF all higher prio processes are waiting for an
Claus Gittinger <cg@exept.de>
parents: 2191
diff changeset
   212
    event.
Claus Gittinger <cg@exept.de>
parents: 2191
diff changeset
   213
    Timeslicing will not be done for processes running above TimeSlicingPriorityLimit, which
Claus Gittinger <cg@exept.de>
parents: 2191
diff changeset
   214
    allows for critical processes to run unaffected to completion.
Claus Gittinger <cg@exept.de>
parents: 2191
diff changeset
   215
Claus Gittinger <cg@exept.de>
parents: 2191
diff changeset
   216
    WARNING:
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
   217
	timesliced priority scheduling is an experimental feature. There is no warranty,
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
   218
	(at the moment), that the system runs reliable in this mode.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
   219
	The problem is, that shared collections may now be easily modified by other
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
   220
	processes, running at the same time.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
   221
	The class library has being investigated for such possible trouble spots
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
   222
	(we have eliminated many weak spots, and added critical regions at many places,
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
   223
	 but cannot guarantee that all of them have been found so far ...)
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
   224
	We found that many existing public domain programs are not prepared for
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
   225
	being interrupted by a same-prio process and therefore may corrupt their
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
   226
	data. If in doubt, disable this fefature.
2193
Claus Gittinger <cg@exept.de>
parents: 2191
diff changeset
   227
Claus Gittinger <cg@exept.de>
parents: 2191
diff changeset
   228
    We think, that the timeSlicer is a useful add-on and that the system is fit enough
10747
e9ea71d01445 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10497
diff changeset
   229
    for it to be evaluated, therefore, its included.
2193
Claus Gittinger <cg@exept.de>
parents: 2191
diff changeset
   230
    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
   231
523781600982 added #useIOInterrupts: to allow disabling this feature
Claus Gittinger <cg@exept.de>
parents: 3644
diff changeset
   232
    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
   233
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
   234
	- disable timeSlicing (in the launchers misc-settings menu)
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
   235
	- open a workSpace
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
   236
	- in the workspace, evaluate:
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
   237
		[true] whileTrue:[1000 factorial]
3650
523781600982 added #useIOInterrupts: to allow disabling this feature
Claus Gittinger <cg@exept.de>
parents: 3644
diff changeset
   238
523781600982 added #useIOInterrupts: to allow disabling this feature
Claus Gittinger <cg@exept.de>
parents: 3644
diff changeset
   239
    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
   240
    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
   241
    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
   242
    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
   243
523781600982 added #useIOInterrupts: to allow disabling this feature
Claus Gittinger <cg@exept.de>
parents: 3644
diff changeset
   244
    Now, stop the factorial-loop, enable timeSlicing, and try again.
10747
e9ea71d01445 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10497
diff changeset
   245
    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
   246
    since the CPU is now divided equally among the runnable processes (timeSliced).
2193
Claus Gittinger <cg@exept.de>
parents: 2191
diff changeset
   247
"
88
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
   248
! !
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
   249
1783
be7402f74d94 hide timerInterrupt & ioInterrupt contexts when switching
Claus Gittinger <cg@exept.de>
parents: 1780
diff changeset
   250
!ProcessorScheduler class methodsFor:'initialization'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   251
a27a279701f8 Initial revision
claus
parents:
diff changeset
   252
initialize
44
b262907c93ea *** empty log message ***
claus
parents: 42
diff changeset
   253
    "class setup: create the one-and-only instance of myself and
b262907c93ea *** empty log message ***
claus
parents: 42
diff changeset
   254
     setup some priority values."
b262907c93ea *** empty log message ***
claus
parents: 42
diff changeset
   255
2193
Claus Gittinger <cg@exept.de>
parents: 2191
diff changeset
   256
    TimeSliceInterval := 50.
2626
4194d370d46f made event polling interval a variable
Claus Gittinger <cg@exept.de>
parents: 2625
diff changeset
   257
    EventPollingInterval := 20.
2193
Claus Gittinger <cg@exept.de>
parents: 2191
diff changeset
   258
93
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   259
    UserSchedulingPriority := 8.
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   260
    UserInterruptPriority := 24.
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   261
    TimingPriority := 16.
2190
8afa4709d8a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2188
diff changeset
   262
    TimeSlicingPriorityLimit := 26.
8afa4709d8a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2188
diff changeset
   263
    HighestPriority := 30.
93
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   264
    SchedulingPriority := 31.
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   265
1679
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   266
    InvalidProcessSignal isNil ifTrue:[
20706
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
   267
	InvalidProcessSignal := Error newSignalMayProceed:true.
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
   268
	InvalidProcessSignal nameClass:self message:#invalidProcessSignal.
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
   269
	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
   270
    ].
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   271
159
514c749165c3 *** empty log message ***
claus
parents: 144
diff changeset
   272
    Processor isNil ifTrue:[
20706
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
   273
	"create the one and only processor"
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
   274
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
   275
	Smalltalk at:#Processor put:(self basicNew initialize).
10
claus
parents: 3
diff changeset
   276
    ].
77
6c38ca59927f *** empty log message ***
claus
parents: 76
diff changeset
   277
6c38ca59927f *** empty log message ***
claus
parents: 76
diff changeset
   278
    "
6c38ca59927f *** empty log message ***
claus
parents: 76
diff changeset
   279
     allow configurations without processes
2129
e03cd7bc3475 newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents: 2123
diff changeset
   280
     (but such configurations are no longer distributed)
77
6c38ca59927f *** empty log message ***
claus
parents: 76
diff changeset
   281
    "
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   282
    PureEventDriven := self threadsAvailable not.
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   283
    PureEventDriven ifTrue:[
20706
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
   284
	'Processor [error]: no process support - running event driven' errorPrintCR
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   285
    ].
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
   286
    self initializeVMMaxProcessId
16841
9e5808800de0 Added MaxProcessId variable & accessor.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16624
diff changeset
   287
9e5808800de0 Added MaxProcessId variable & accessor.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16624
diff changeset
   288
    "Modified: / 23-09-1996 / 14:24:50 / stefan"
9e5808800de0 Added MaxProcessId variable & accessor.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16624
diff changeset
   289
    "Modified: / 10-01-1997 / 18:03:03 / cg"
9e5808800de0 Added MaxProcessId variable & accessor.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16624
diff changeset
   290
    "Modified: / 19-09-2014 / 12:47:51 / Jan Vrany <jan.vrany@fit.cvut.cz>"
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
   291
!
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
   292
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
   293
initializeVMMaxProcessId
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
   294
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
   295
    "/ for java locks, the VM may reserve some bits
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
   296
    "/ and reduce the maximum processID to be able to
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
   297
    "/ encode the id in an object's header field.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
   298
%{
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
   299
#ifndef __SCHTEAM__
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
   300
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
   301
# ifndef MAX_PROCESS_ID
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
   302
#  define MAX_PROCESS_ID _MAX_INT
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
   303
# endif
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
   304
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
   305
    @global(ProcessorScheduler:MaxProcessId) = __MKSMALLINT(MAX_PROCESS_ID);
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
   306
    RETURN (self);
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
   307
#endif /* not SCHTEAM */
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
   308
%}.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
   309
    MaxProcessId := SmallInteger maxVal.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   310
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   311
1783
be7402f74d94 hide timerInterrupt & ioInterrupt contexts when switching
Claus Gittinger <cg@exept.de>
parents: 1780
diff changeset
   312
!ProcessorScheduler class methodsFor:'instance creation'!
10
claus
parents: 3
diff changeset
   313
claus
parents: 3
diff changeset
   314
new
claus
parents: 3
diff changeset
   315
    "there is (currently) only one processor ..."
claus
parents: 3
diff changeset
   316
159
514c749165c3 *** empty log message ***
claus
parents: 144
diff changeset
   317
    self error:'only one processor is allowed in the system'
10
claus
parents: 3
diff changeset
   318
! !
claus
parents: 3
diff changeset
   319
1783
be7402f74d94 hide timerInterrupt & ioInterrupt contexts when switching
Claus Gittinger <cg@exept.de>
parents: 1780
diff changeset
   320
!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
   321
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   322
invalidProcessSignal
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   323
    ^ InvalidProcessSignal
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   324
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   325
    "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
   326
! !
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   327
1783
be7402f74d94 hide timerInterrupt & ioInterrupt contexts when switching
Claus Gittinger <cg@exept.de>
parents: 1780
diff changeset
   328
!ProcessorScheduler class methodsFor:'instance release'!
10
claus
parents: 3
diff changeset
   329
2091
c11bb3e29a1b Use dependent mechamism of WeakArray instead of #watcher.
Stefan Vogel <sv@exept.de>
parents: 1981
diff changeset
   330
update:something with:aParameter from:changedObject
10747
e9ea71d01445 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10497
diff changeset
   331
    "some Process has been garbage collected
e9ea71d01445 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10497
diff changeset
   332
     - terminate the underlying thread.
e9ea71d01445 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10497
diff changeset
   333
     Usually this does not happen; instead, the process terminates itself
335
claus
parents: 326
diff changeset
   334
     by sending #terminate."
10
claus
parents: 3
diff changeset
   335
claus
parents: 3
diff changeset
   336
    |id sz "{ Class: SmallInteger }"|
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   337
2091
c11bb3e29a1b Use dependent mechamism of WeakArray instead of #watcher.
Stefan Vogel <sv@exept.de>
parents: 1981
diff changeset
   338
    something == #ElementExpired ifTrue:[
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
   339
	sz := KnownProcessIds size.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
   340
	1 to:sz do:[:index |
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
   341
	    "/ (KnownProcesses at:index) isNil ifTrue:[
18620
b4e9f25d6ce6 preparations for lined index list in WeakArray
Claus Gittinger <cg@exept.de>
parents: 18295
diff changeset
   342
	    (KnownProcesses at:index) class == SmallInteger ifTrue:[
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
   343
		id := KnownProcessIds at:index.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
   344
		id notNil ifTrue:[
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
   345
		    'Processor [warning]: terminating thread ' errorPrint.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
   346
		    id errorPrint.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
   347
		    ' (no longer refd)' errorPrintCR.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
   348
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
   349
		    self threadDestroy:id.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
   350
		    KnownProcessIds at:index put:nil.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
   351
		].
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
   352
		KnownProcesses at:index put:nil.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
   353
	    ]
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
   354
	]
10
claus
parents: 3
diff changeset
   355
    ]
2091
c11bb3e29a1b Use dependent mechamism of WeakArray instead of #watcher.
Stefan Vogel <sv@exept.de>
parents: 1981
diff changeset
   356
c11bb3e29a1b Use dependent mechamism of WeakArray instead of #watcher.
Stefan Vogel <sv@exept.de>
parents: 1981
diff changeset
   357
    "Created: 7.1.1997 / 16:45:42 / stefan"
2137
3e210d26d0d8 *PrintNL eliminated
Claus Gittinger <cg@exept.de>
parents: 2129
diff changeset
   358
    "Modified: 10.1.1997 / 19:10:48 / cg"
10
claus
parents: 3
diff changeset
   359
! !
claus
parents: 3
diff changeset
   360
1783
be7402f74d94 hide timerInterrupt & ioInterrupt contexts when switching
Claus Gittinger <cg@exept.de>
parents: 1780
diff changeset
   361
!ProcessorScheduler class methodsFor:'primitive process primitives'!
10
claus
parents: 3
diff changeset
   362
339
claus
parents: 337
diff changeset
   363
threadCreate:aProcess withId:id
159
514c749165c3 *** empty log message ***
claus
parents: 144
diff changeset
   364
    "physical creation of a process.
10
claus
parents: 3
diff changeset
   365
     (warning: low level entry, no administration done).
339
claus
parents: 337
diff changeset
   366
     This may raise an exception, if a VM process could not be created."
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   367
369
claus
parents: 362
diff changeset
   368
    MaxNumberOfProcesses notNil ifTrue:[
20810
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   369
        KnownProcessIds size >= MaxNumberOfProcesses ifTrue:[
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   370
            (KnownProcessIds count:[:el | el notNil]) >= MaxNumberOfProcesses ifTrue:[
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   371
                "
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   372
                 the number of processes has reached the (soft) limit.
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   373
                 This limit prevents runaway programs from creating too many
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   374
                 processes. If you continue in the debugger, the process will be
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   375
                 created as usual. If you don't want this, abort or terminate.
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   376
                "
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   377
                self error:'too many processes'.
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   378
            ]
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   379
        ]
369
claus
parents: 362
diff changeset
   380
    ].
claus
parents: 362
diff changeset
   381
claus
parents: 362
diff changeset
   382
%{
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   383
    int tid;
a27a279701f8 Initial revision
claus
parents:
diff changeset
   384
    extern int __threadCreate();
a27a279701f8 Initial revision
claus
parents:
diff changeset
   385
10747
e9ea71d01445 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10497
diff changeset
   386
    tid = __threadCreate(aProcess,
20810
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   387
                         0   /* stackSize: no longer needed */,
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   388
                         __isSmallInteger(id) ? __intVal(id)     /* assign id */
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   389
                                              : -1              /* let VM assign one */  );
339
claus
parents: 337
diff changeset
   390
    if (tid) {
20810
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   391
        RETURN ( __mkSmallInteger(tid));
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   392
    }
a27a279701f8 Initial revision
claus
parents:
diff changeset
   393
%}
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   394
.
69
4564b6328136 *** empty log message ***
claus
parents: 59
diff changeset
   395
    "
4564b6328136 *** empty log message ***
claus
parents: 59
diff changeset
   396
     arrive here, if creation of process in VM failed.
159
514c749165c3 *** empty log message ***
claus
parents: 144
diff changeset
   397
     This may happen, if the VM does not support more processes,
514c749165c3 *** empty log message ***
claus
parents: 144
diff changeset
   398
     or if it ran out of memory, when allocating internal data
514c749165c3 *** empty log message ***
claus
parents: 144
diff changeset
   399
     structures.
69
4564b6328136 *** empty log message ***
claus
parents: 59
diff changeset
   400
    "
20706
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
   401
    ^ AllocationFailure raise.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   402
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   403
a27a279701f8 Initial revision
claus
parents:
diff changeset
   404
threadDestroy:id
a27a279701f8 Initial revision
claus
parents:
diff changeset
   405
    "physical destroy other process ...
a27a279701f8 Initial revision
claus
parents:
diff changeset
   406
     (warning: low level entry, no administration done)"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   407
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   408
%{  /* NOCONTEXT */
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   409
253
30daee717a53 *** empty log message ***
claus
parents: 243
diff changeset
   410
    if (__isSmallInteger(id)) {
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
   411
	__threadDestroy(__intVal(id));
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   412
    }
a27a279701f8 Initial revision
claus
parents:
diff changeset
   413
%}
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   414
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   415
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   416
threadInterrupt:id
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   417
    "make the process evaluate an interrupt. This sets a flag in the VMs
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   418
     threadSwitcher, to let the process perform a #interrupt when its set to
10747
e9ea71d01445 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10497
diff changeset
   419
     run the next time. The process itself can decide how to react on this
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   420
     interrupt (currently, it looks for interruptBlocks to evaluate)."
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   421
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   422
%{  /* NOCONTEXT */
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   423
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   424
    if (__isSmallInteger(id)) {
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
   425
	__threadInterrupt(__intVal(id));
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   426
    }
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   427
%}
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   428
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   429
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   430
threadsAvailable
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   431
    "return true, if the runtime system supports threads (i.e. processes);
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   432
     false otherwise."
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   433
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   434
%{  /* NOCONTEXT */
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   435
    RETURN (__threadsAvailable());
5406
4a6995b61c0e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5396
diff changeset
   436
%}.
4a6995b61c0e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5396
diff changeset
   437
    ^ true
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   438
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   439
1783
be7402f74d94 hide timerInterrupt & ioInterrupt contexts when switching
Claus Gittinger <cg@exept.de>
parents: 1780
diff changeset
   440
!ProcessorScheduler class methodsFor:'queries'!
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   441
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   442
isPureEventDriven
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   443
    "this is temporary - (maybe not :-).
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   444
     you can run ST/X either with or without processes.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   445
     Without, there is conceptionally a single process handling all
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   446
     outside events and timeouts. This has some negative implications
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   447
     (Debugger is ugly), but allows a fully portable ST/X without any
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   448
     assembler support - i.e. quick portability.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   449
     The PureEvent flag will automatically be set if the runtime system
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   450
     does not support threads - otherwise, it can be set manually
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   451
     (from rc-file).
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   452
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   453
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   454
    ^ PureEventDriven
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   455
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   456
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   457
knownProcesses
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   458
    "return a collection of all (living) processes in the system"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   459
18620
b4e9f25d6ce6 preparations for lined index list in WeakArray
Claus Gittinger <cg@exept.de>
parents: 18295
diff changeset
   460
    ^ KnownProcesses select:[:p | p notNil and:[p class ~~ SmallInteger]]
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   461
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   462
14442
92bfe052854b added: #knownProcessesDo:
Claus Gittinger <cg@exept.de>
parents: 14230
diff changeset
   463
knownProcessesDo:aBlock
92bfe052854b added: #knownProcessesDo:
Claus Gittinger <cg@exept.de>
parents: 14230
diff changeset
   464
    "evaluate aBlock for each (living) processes in the system"
92bfe052854b added: #knownProcessesDo:
Claus Gittinger <cg@exept.de>
parents: 14230
diff changeset
   465
14943
141d20b16378 class: ProcessorScheduler
Claus Gittinger <cg@exept.de>
parents: 14780
diff changeset
   466
    KnownProcesses do:[:p |
18620
b4e9f25d6ce6 preparations for lined index list in WeakArray
Claus Gittinger <cg@exept.de>
parents: 18295
diff changeset
   467
	(p notNil and:[p class ~~ SmallInteger]) ifTrue:[aBlock value:p]
14442
92bfe052854b added: #knownProcessesDo:
Claus Gittinger <cg@exept.de>
parents: 14230
diff changeset
   468
    ]
92bfe052854b added: #knownProcessesDo:
Claus Gittinger <cg@exept.de>
parents: 14230
diff changeset
   469
92bfe052854b added: #knownProcessesDo:
Claus Gittinger <cg@exept.de>
parents: 14230
diff changeset
   470
    "Created: / 26-10-2012 / 13:02:33 / cg"
92bfe052854b added: #knownProcessesDo:
Claus Gittinger <cg@exept.de>
parents: 14230
diff changeset
   471
!
92bfe052854b added: #knownProcessesDo:
Claus Gittinger <cg@exept.de>
parents: 14230
diff changeset
   472
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   473
maxNumberOfProcesses
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   474
    "return the limit on the number of processes;
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   475
     the default is nil (i.e. unlimited)."
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   476
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   477
    ^ MaxNumberOfProcesses
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   478
!
10
claus
parents: 3
diff changeset
   479
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   480
maxNumberOfProcesses:aNumber
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   481
    "set the limit on the number of processes.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   482
     This helps if you have a program which (by error) creates countless
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   483
     subprocesses. Without this limit, you may have a hard time to find
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   484
     this error (and repairing it). If nil (the default), the number of
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   485
     processes is unlimited."
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   486
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   487
    MaxNumberOfProcesses := aNumber
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   488
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   489
16841
9e5808800de0 Added MaxProcessId variable & accessor.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16624
diff changeset
   490
maxProcessId
9e5808800de0 Added MaxProcessId variable & accessor.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16624
diff changeset
   491
    "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
   492
9e5808800de0 Added MaxProcessId variable & accessor.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16624
diff changeset
   493
    ^ MaxProcessId
9e5808800de0 Added MaxProcessId variable & accessor.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16624
diff changeset
   494
9e5808800de0 Added MaxProcessId variable & accessor.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16624
diff changeset
   495
    "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
   496
!
9e5808800de0 Added MaxProcessId variable & accessor.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16624
diff changeset
   497
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   498
processDriven
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   499
    "turn on process driven mode"
10
claus
parents: 3
diff changeset
   500
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   501
    PureEventDriven := false
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   502
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   503
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   504
pureEventDriven
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   505
    "turn on pure-event driven mode - no processes, single dispatch loop"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   506
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   507
    PureEventDriven := true
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   508
! !
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   509
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   510
!ProcessorScheduler methodsFor:'I/O event actions'!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   511
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   512
enableIOAction:aBlock onInput:aFileDescriptor
5101
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
   513
    "obsolete event support: arrange for aBlock to be
10747
e9ea71d01445 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10497
diff changeset
   514
     evaluated when input on aFileDescriptor arrives.
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   515
     This is a leftover support for pure-event systems and may vanish."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   516
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   517
    |idx "{Class: SmallInteger }"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   518
     wasBlocked|
10
claus
parents: 3
diff changeset
   519
3116
e535e4e266dd more error handling;
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   520
    aFileDescriptor < 0 ifTrue:[
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
   521
	'Processor [warning]: ignored invalid fd for IO action.' errorPrintCR.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
   522
	thisContext fullPrintAll.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
   523
	^ self
3116
e535e4e266dd more error handling;
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   524
    ].
e535e4e266dd more error handling;
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   525
93
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   526
    wasBlocked := OperatingSystem blockInterrupts.
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   527
    (readFdArray identityIndexOf:aFileDescriptor startingAt:1) == 0 ifTrue:[
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
   528
	idx := readFdArray identityIndexOf:nil startingAt:1.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
   529
	idx ~~ 0 ifTrue:[
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
   530
	    readFdArray at:idx put:aFileDescriptor.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
   531
	    readCheckArray at:idx put:aBlock.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
   532
	    readSemaphoreArray at:idx put:nil
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
   533
	] ifFalse:[
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
   534
	    readFdArray := readFdArray copyWith:aFileDescriptor.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
   535
	    readCheckArray := readCheckArray copyWith:aBlock.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
   536
	    readSemaphoreArray := readSemaphoreArray copyWith:nil.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
   537
	].
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
   538
	useIOInterrupts ifTrue:[
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
   539
	    OperatingSystem enableIOInterruptsOn:aFileDescriptor
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
   540
	].
2831
02f9aa61f71b ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   541
93
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   542
    ].
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   543
    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
   544
02f9aa61f71b ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   545
    "Modified: 4.8.1997 / 15:17:28 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   546
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   547
a27a279701f8 Initial revision
claus
parents:
diff changeset
   548
!ProcessorScheduler methodsFor:'accessing'!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   549
69
4564b6328136 *** empty log message ***
claus
parents: 59
diff changeset
   550
activePriority
4564b6328136 *** empty log message ***
claus
parents: 59
diff changeset
   551
    "return the priority of the currently running process.
159
514c749165c3 *** empty log message ***
claus
parents: 144
diff changeset
   552
     GNU-ST & ST-80 compatibility; this is the same as currentPriority"
69
4564b6328136 *** empty log message ***
claus
parents: 59
diff changeset
   553
4564b6328136 *** empty log message ***
claus
parents: 59
diff changeset
   554
    ^ currentPriority
4564b6328136 *** empty log message ***
claus
parents: 59
diff changeset
   555
!
4564b6328136 *** empty log message ***
claus
parents: 59
diff changeset
   556
25
e34a6267c79b *** empty log message ***
claus
parents: 24
diff changeset
   557
activeProcess
10
claus
parents: 3
diff changeset
   558
    "return the currently running process"
claus
parents: 3
diff changeset
   559
25
e34a6267c79b *** empty log message ***
claus
parents: 24
diff changeset
   560
    ^ activeProcess
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   561
25
e34a6267c79b *** empty log message ***
claus
parents: 24
diff changeset
   562
    "Processor activeProcess"
181
ef3ccf27e2e0 interrupted process now kept for monitor
claus
parents: 161
diff changeset
   563
!
ef3ccf27e2e0 interrupted process now kept for monitor
claus
parents: 161
diff changeset
   564
2262
4c4d810f006f semaphore names
Claus Gittinger <cg@exept.de>
parents: 2258
diff changeset
   565
activeProcessId
4c4d810f006f semaphore names
Claus Gittinger <cg@exept.de>
parents: 2258
diff changeset
   566
    "return the currently running process's ID.
4c4d810f006f semaphore names
Claus Gittinger <cg@exept.de>
parents: 2258
diff changeset
   567
     The same as returned by 'Processor activeProcess id';
4c4d810f006f semaphore names
Claus Gittinger <cg@exept.de>
parents: 2258
diff changeset
   568
     added for to avoid another send in semaphores debugging support."
4c4d810f006f semaphore names
Claus Gittinger <cg@exept.de>
parents: 2258
diff changeset
   569
4c4d810f006f semaphore names
Claus Gittinger <cg@exept.de>
parents: 2258
diff changeset
   570
    ^ activeProcessId
4c4d810f006f semaphore names
Claus Gittinger <cg@exept.de>
parents: 2258
diff changeset
   571
!
4c4d810f006f semaphore names
Claus Gittinger <cg@exept.de>
parents: 2258
diff changeset
   572
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   573
currentPriority
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   574
    "return the priority of the currently running process"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   575
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   576
    ^ currentPriority
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   577
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   578
    "Processor currentPriority"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   579
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   580
19850
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
   581
interruptCounter
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
   582
    "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
   583
19850
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
   584
    ^ interruptCounter
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
   585
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
   586
    "
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
   587
     Processor interruptCounter
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
   588
    "
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
   589
!
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
   590
181
ef3ccf27e2e0 interrupted process now kept for monitor
claus
parents: 161
diff changeset
   591
interruptedProcess
ef3ccf27e2e0 interrupted process now kept for monitor
claus
parents: 161
diff changeset
   592
    "returns the process which was interrupted by the active one"
ef3ccf27e2e0 interrupted process now kept for monitor
claus
parents: 161
diff changeset
   593
ef3ccf27e2e0 interrupted process now kept for monitor
claus
parents: 161
diff changeset
   594
    ^ interruptedProcess
7046
b7ae8faff2ac Access method for scheduler
Stefan Vogel <sv@exept.de>
parents: 6990
diff changeset
   595
!
b7ae8faff2ac Access method for scheduler
Stefan Vogel <sv@exept.de>
parents: 6990
diff changeset
   596
16842
01a2d5d91c96 Oops, added #maxProcessId also to instance side.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16841
diff changeset
   597
maxProcessId
01a2d5d91c96 Oops, added #maxProcessId also to instance side.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16841
diff changeset
   598
    ^ self class maxProcessId
01a2d5d91c96 Oops, added #maxProcessId also to instance side.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16841
diff changeset
   599
01a2d5d91c96 Oops, added #maxProcessId also to instance side.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16841
diff changeset
   600
    "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
   601
!
01a2d5d91c96 Oops, added #maxProcessId also to instance side.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16841
diff changeset
   602
7046
b7ae8faff2ac Access method for scheduler
Stefan Vogel <sv@exept.de>
parents: 6990
diff changeset
   603
scheduler
b7ae8faff2ac Access method for scheduler
Stefan Vogel <sv@exept.de>
parents: 6990
diff changeset
   604
    "return the scheduling process"
b7ae8faff2ac Access method for scheduler
Stefan Vogel <sv@exept.de>
parents: 6990
diff changeset
   605
b7ae8faff2ac Access method for scheduler
Stefan Vogel <sv@exept.de>
parents: 6990
diff changeset
   606
    ^ scheduler
19850
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
   607
!
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
   608
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
   609
timedActionCounter
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
   610
    "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
   611
19850
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
   612
    ^ timedActionCounter
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
   613
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
   614
    "
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
   615
     Processor timedActionCounter
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
   616
    "
10
claus
parents: 3
diff changeset
   617
! !
claus
parents: 3
diff changeset
   618
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   619
!ProcessorScheduler methodsFor:'background processing'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   620
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   621
addIdleBlock:aBlock
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   622
    "add the argument, aBlock to the list of idle-actions.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   623
     Idle blocks are evaluated whenever no other process is runnable,
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   624
     and no events are pending.
10747
e9ea71d01445 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10497
diff changeset
   625
     Use of idle blocks is not recommended, use a low priority processes
14780
113129e94917 class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 14775
diff changeset
   626
     instead, which has the same effect. Idle blocks are still included
10747
e9ea71d01445 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10497
diff changeset
   627
     to support background actions in pure-event systems, where no processes
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   628
     are available.
6619
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
   629
     ATTENTION: Support for idle-blocks may vanish."
10
claus
parents: 3
diff changeset
   630
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   631
    |wasBlocked|
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   632
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   633
    wasBlocked := OperatingSystem blockInterrupts.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   634
    idleActions isNil ifTrue:[
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
   635
	idleActions := OrderedCollection new
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   636
    ].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   637
    idleActions add:aBlock.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   638
    wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   639
!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   640
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   641
removeIdleBlock:aBlock
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   642
    "remove the argument, aBlock from the list of idle-blocks.
6619
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
   643
     ATTENTION: Support for idle-blocks may vanish - use low prio processes instead."
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   644
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   645
    |wasBlocked|
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   646
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   647
    wasBlocked := OperatingSystem blockInterrupts.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   648
    idleActions notNil ifTrue:[
3969
0f30268b10c3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3967
diff changeset
   649
       idleActions removeIdentical:aBlock ifAbsent:nil
10
claus
parents: 3
diff changeset
   650
    ].
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   651
    wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
2353
ce92d04c41cc use removeIdentical
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   652
ce92d04c41cc use removeIdentical
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   653
    "Modified: 1.2.1997 / 12:09:46 / cg"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   654
! !
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   655
10
claus
parents: 3
diff changeset
   656
!ProcessorScheduler methodsFor:'dispatching'!
claus
parents: 3
diff changeset
   657
claus
parents: 3
diff changeset
   658
dispatch
93
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   659
     "It handles timeouts and switches to the highest prio runnable process"
44
b262907c93ea *** empty log message ***
claus
parents: 42
diff changeset
   660
19083
504ff3f2cfa0 #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 19063
diff changeset
   661
    |millis pri p nActions "{ Class: SmallInteger }"
3745
3fd121f2e74e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3740
diff changeset
   662
     checkBlock sema wasBlocked|
3fd121f2e74e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3740
diff changeset
   663
3fd121f2e74e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3740
diff changeset
   664
    wasBlocked := OperatingSystem blockInterrupts.
10
claus
parents: 3
diff changeset
   665
93
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   666
    "
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   667
     handle all timeout actions
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   668
    "
27
d98f9dd437f7 *** empty log message ***
claus
parents: 25
diff changeset
   669
    anyTimeouts ifTrue:[
20810
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   670
        self evaluateTimeouts
10
claus
parents: 3
diff changeset
   671
    ].
claus
parents: 3
diff changeset
   672
231
fd0e55e352f8 cleanup
claus
parents: 217
diff changeset
   673
    "first do a quick check for semaphores using checkActions - this is needed for
302
1f76060d58a4 *** empty log message ***
claus
parents: 271
diff changeset
   674
     devices like the X-connection, where some events might be in the event
10747
e9ea71d01445 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10497
diff changeset
   675
     queue but the sockets input queue is empty.
5101
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
   676
     Without these checks, a select might block even though there is work to do.
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
   677
     Also, this is needed for poor MSDOS, where WaitForObject does not work with
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
   678
     sockets and pipes (sigh)
93
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   679
    "
231
fd0e55e352f8 cleanup
claus
parents: 217
diff changeset
   680
    nActions := readCheckArray size.
10
claus
parents: 3
diff changeset
   681
    1 to:nActions do:[:index |
20810
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   682
        checkBlock := readCheckArray at:index.
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   683
        (checkBlock notNil and:[checkBlock value]) ifTrue:[
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   684
            sema := readSemaphoreArray at:index.
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   685
            sema notNil ifTrue:[
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   686
                sema signalOnce.
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   687
            ].
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   688
        ]
5101
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
   689
    ].
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
   690
    nActions := writeCheckArray size.
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
   691
    1 to:nActions do:[:index |
20810
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   692
        checkBlock := writeCheckArray at:index.
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   693
        (checkBlock notNil and:[checkBlock value]) ifTrue:[
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   694
            sema := writeSemaphoreArray at:index.
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   695
            sema notNil ifTrue:[
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   696
                sema signalOnce.
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   697
            ].
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   698
        ]
10
claus
parents: 3
diff changeset
   699
    ].
claus
parents: 3
diff changeset
   700
231
fd0e55e352f8 cleanup
claus
parents: 217
diff changeset
   701
    "now, someone might be runnable ..."
10
claus
parents: 3
diff changeset
   702
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   703
    p := self highestPriorityRunnableProcess.
10
claus
parents: 3
diff changeset
   704
    p isNil ifTrue:[
20810
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   705
        "/ no one runnable, hard wait for event or timeout
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   706
        "/ Trace ifTrue:['w' printCR.].
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   707
        self waitForEventOrTimeout.
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   708
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   709
        "/ check for OS process termination
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   710
        gotChildSignalInterrupt ifTrue:[
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   711
            gotChildSignalInterrupt := false.
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   712
            self handleChildSignalInterrupt
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   713
        ].
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   714
        wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   715
        ^ self
10
claus
parents: 3
diff changeset
   716
    ].
claus
parents: 3
diff changeset
   717
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   718
    pri := p priority.
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   719
302
1f76060d58a4 *** empty log message ***
claus
parents: 271
diff changeset
   720
    "
1f76060d58a4 *** empty log message ***
claus
parents: 271
diff changeset
   721
     want to give control to the process p.
10
claus
parents: 3
diff changeset
   722
     If the switched-to processes priority is lower than the
10747
e9ea71d01445 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10497
diff changeset
   723
     userSchedulingPriority, we have to make certain, that the
10
claus
parents: 3
diff changeset
   724
     next input or timer will bring us back for a reschedule.
claus
parents: 3
diff changeset
   725
     This is done by enabling ioInterrupts for all file descriptors.
10747
e9ea71d01445 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10497
diff changeset
   726
     If ioInterrupts are not available (OS does not support them),
302
1f76060d58a4 *** empty log message ***
claus
parents: 271
diff changeset
   727
     we schedule a timer interrupt to interrupt us after 1/20s of a second
1f76060d58a4 *** empty log message ***
claus
parents: 271
diff changeset
   728
     - effectively polling the filedescriptors 20 times a second.
1f76060d58a4 *** empty log message ***
claus
parents: 271
diff changeset
   729
     (which is bad, since low prio processes will be hurt in performance)
20810
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   730
     Therefore, don't let benchmarks run with low prio ...
302
1f76060d58a4 *** empty log message ***
claus
parents: 271
diff changeset
   731
10747
e9ea71d01445 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10497
diff changeset
   732
     Higher prio processes must be suspended,
302
1f76060d58a4 *** empty log message ***
claus
parents: 271
diff changeset
   733
     same prio ones must yield or suspend to get back control
1f76060d58a4 *** empty log message ***
claus
parents: 271
diff changeset
   734
    "
10
claus
parents: 3
diff changeset
   735
93
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   736
"
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   737
 uncommenting this will make timeouts interrupt the current process
10747
e9ea71d01445 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10497
diff changeset
   738
 (i.e. as if the interrupt runs at TimingPrio);
93
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   739
 if left commented, they are handled at UserSchedulingPrio.
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   740
 this will all change, when timeouts are removed and all is process driven
231
fd0e55e352f8 cleanup
claus
parents: 217
diff changeset
   741
 (a future version will have a process running to handle a timeout queue)
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   742
"
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   743
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   744
"
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   745
    pri < TimingPriority ifTrue:[
20810
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   746
        anyTimeouts ifTrue:[
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   747
            millis := self timeToNextTimeout.
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   748
            millis == 0 ifTrue:[
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   749
                wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   750
                ^ self
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   751
            ]
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   752
        ]
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   753
    ].
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   754
"
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   755
93
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   756
    "
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   757
     if the process to run has a lower than UserInterruptPriority,
302
1f76060d58a4 *** empty log message ***
claus
parents: 271
diff changeset
   758
     arrange for an interrupt to occur on I/O.
231
fd0e55e352f8 cleanup
claus
parents: 217
diff changeset
   759
     This is done by enabling IO-signals (if the OS supports them)
93
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   760
     or by installing a poll-interrupt after 50ms (if the OS does not).
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   761
    "
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   762
    pri < UserInterruptPriority ifTrue:[
10747
e9ea71d01445 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10497
diff changeset
   763
93
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   764
"comment out this if above is uncommented"
20810
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   765
        anyTimeouts ifTrue:[
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   766
            millis := self timeToNextTimeout.
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   767
            millis == 0 ifTrue:[
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   768
                wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   769
                ^ self
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   770
            ].
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   771
        ].
93
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   772
"---"
10
claus
parents: 3
diff changeset
   773
20810
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   774
        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
   775
"/            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
   776
"/                (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
   777
"/                    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
   778
"/                ].
02f9aa61f71b ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   779
"/            ].
20810
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   780
        ] ifFalse:[
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   781
            millis notNil ifTrue:[
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   782
                millis := millis min:EventPollingInterval
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   783
            ] ifFalse:[
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   784
                millis := EventPollingInterval
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   785
            ]
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   786
        ]
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   787
    ].
10
claus
parents: 3
diff changeset
   788
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   789
    millis notNil ifTrue:[
20810
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   790
        "/ Trace ifTrue:['C' print. millis printCR.].
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   791
        "schedule a clock interrupt after millis milliseconds"
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   792
        OperatingSystem enableTimer:millis rounded.
10
claus
parents: 3
diff changeset
   793
    ].
claus
parents: 3
diff changeset
   794
3722
1114c2014bea added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents: 3718
diff changeset
   795
    scheduledProcesses notNil ifTrue:[
20810
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   796
        scheduledProcesses add:p
3722
1114c2014bea added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents: 3718
diff changeset
   797
    ].
1114c2014bea added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents: 3718
diff changeset
   798
231
fd0e55e352f8 cleanup
claus
parents: 217
diff changeset
   799
    "
fd0e55e352f8 cleanup
claus
parents: 217
diff changeset
   800
     now let the process run - will come back here by reschedule
15438
9934d8542668 class: ProcessorScheduler
Claus Gittinger <cg@exept.de>
parents: 15402
diff changeset
   801
     from ioInterrupt, scheduler or timerInterrupt ... (running at max+1)
231
fd0e55e352f8 cleanup
claus
parents: 217
diff changeset
   802
    "
10747
e9ea71d01445 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10497
diff changeset
   803
    "/ Trace ifTrue:['->' print. p printCR.].
10
claus
parents: 3
diff changeset
   804
    self threadSwitch:p.
10747
e9ea71d01445 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10497
diff changeset
   805
    "/ Trace ifTrue:['<-' printCR.].
10
claus
parents: 3
diff changeset
   806
804
264d440a67a0 Fixes when useIOInterrupts == true.
Stefan Vogel <sv@exept.de>
parents: 786
diff changeset
   807
    "... when we arrive here, we are back on stage.
20810
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   808
         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
   809
    "
10
claus
parents: 3
diff changeset
   810
claus
parents: 3
diff changeset
   811
    millis notNil ifTrue:[
20810
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   812
        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
   813
    ].
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
   814
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
   815
    "/ 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
   816
    gotChildSignalInterrupt ifTrue:[
20810
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   817
        gotChildSignalInterrupt := false.
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   818
        self handleChildSignalInterrupt
804
264d440a67a0 Fixes when useIOInterrupts == true.
Stefan Vogel <sv@exept.de>
parents: 786
diff changeset
   819
    ].
264d440a67a0 Fixes when useIOInterrupts == true.
Stefan Vogel <sv@exept.de>
parents: 786
diff changeset
   820
264d440a67a0 Fixes when useIOInterrupts == true.
Stefan Vogel <sv@exept.de>
parents: 786
diff changeset
   821
    "/ check for new input
264d440a67a0 Fixes when useIOInterrupts == true.
Stefan Vogel <sv@exept.de>
parents: 786
diff changeset
   822
3745
3fd121f2e74e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3740
diff changeset
   823
    OperatingSystem unblockInterrupts.
3fd121f2e74e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3740
diff changeset
   824
804
264d440a67a0 Fixes when useIOInterrupts == true.
Stefan Vogel <sv@exept.de>
parents: 786
diff changeset
   825
    (gotIOInterrupt or:[useIOInterrupts not]) ifTrue:[
20810
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   826
        gotIOInterrupt := false.
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   827
        self checkForIOWithTimeout:0.
3745
3fd121f2e74e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3740
diff changeset
   828
    ].
3fd121f2e74e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3740
diff changeset
   829
3fd121f2e74e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3740
diff changeset
   830
    wasBlocked ifTrue:[OperatingSystem blockInterrupts].
768
20434b8239f3 stefans modalBox changes (no more polling)
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
   831
3722
1114c2014bea added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents: 3718
diff changeset
   832
    "Modified: / 12.4.1996 / 10:14:18 / stefan"
1114c2014bea added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents: 3718
diff changeset
   833
    "Modified: / 3.8.1998 / 21:54:01 / cg"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   834
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   835
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   836
dispatchLoop
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   837
    "central dispatch loop; the scheduler process is always staying in
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   838
     this method, looping forever."
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   839
806
409a8c189e01 also handle termination of the scheduler process
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
   840
    |dispatchAction handlerAction ignoredSignals|
786
789e2f20de44 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 780
diff changeset
   841
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   842
    "avoid confusion if entered twice"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   843
14230
4d97053eeff0 changed: #dispatchLoop
Claus Gittinger <cg@exept.de>
parents: 13813
diff changeset
   844
    dispatching == true ifTrue:[
20763
b1e9ec00e8af #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20760
diff changeset
   845
        'Processor [info]: already in dispatch' infoPrintCR.
b1e9ec00e8af #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20760
diff changeset
   846
        ^ self
14230
4d97053eeff0 changed: #dispatchLoop
Claus Gittinger <cg@exept.de>
parents: 13813
diff changeset
   847
    ].
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   848
    dispatching := true.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   849
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
   850
    "/ 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
   851
    "/ 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
   852
    "/ (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
   853
    "/  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
   854
20763
b1e9ec00e8af #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20760
diff changeset
   855
    dispatchAction := 
b1e9ec00e8af #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20760
diff changeset
   856
        [ 
b1e9ec00e8af #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20760
diff changeset
   857
            [dispatching] whileTrue:[ 
b1e9ec00e8af #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20760
diff changeset
   858
                self dispatch 
b1e9ec00e8af #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20760
diff changeset
   859
            ] 
b1e9ec00e8af #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20760
diff changeset
   860
        ].
b1e9ec00e8af #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20760
diff changeset
   861
b1e9ec00e8af #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20760
diff changeset
   862
    handlerAction := 
b1e9ec00e8af #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20760
diff changeset
   863
        [:ex |
b1e9ec00e8af #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20760
diff changeset
   864
            (HaltInterrupt accepts:ex creator) ifTrue:[
b1e9ec00e8af #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20760
diff changeset
   865
                "/ in a standalone application, we do not want those
20964
b31cd14f998e #BUGFIX by Maren
matilk
parents: 20888
diff changeset
   866
                (Smalltalk isStandAloneApp and:[Smalltalk isStandAloneDebug not]) ifTrue:[
b31cd14f998e #BUGFIX by Maren
matilk
parents: 20888
diff changeset
   867
                    ('Processor [info]: ignored (', ex creator printString, ')') infoPrintCR.
b31cd14f998e #BUGFIX by Maren
matilk
parents: 20888
diff changeset
   868
                    ex proceed.
20763
b1e9ec00e8af #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20760
diff changeset
   869
                ].
20964
b31cd14f998e #BUGFIX by Maren
matilk
parents: 20888
diff changeset
   870
                "/ MiniDebugger enter. -- should this be done when some --debug/--verbose was given?
b31cd14f998e #BUGFIX by Maren
matilk
parents: 20888
diff changeset
   871
                ex proceed.
20763
b1e9ec00e8af #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20760
diff changeset
   872
            ].
b1e9ec00e8af #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20760
diff changeset
   873
b1e9ec00e8af #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20760
diff changeset
   874
            ('Processor [info]: caught (and ignored) signal (', ex creator printString, ')') infoPrintCR.
b1e9ec00e8af #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20760
diff changeset
   875
            ex return
b1e9ec00e8af #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20760
diff changeset
   876
         ].
10747
e9ea71d01445 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10497
diff changeset
   877
e9ea71d01445 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10497
diff changeset
   878
    ignoredSignals := SignalSet
20763
b1e9ec00e8af #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20760
diff changeset
   879
                        with:HaltInterrupt
b1e9ec00e8af #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20760
diff changeset
   880
                        with:TerminateProcessRequest
b1e9ec00e8af #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20760
diff changeset
   881
                        with:RecursionError
b1e9ec00e8af #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20760
diff changeset
   882
                        with:AbortAllOperationRequest.
786
789e2f20de44 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 780
diff changeset
   883
789e2f20de44 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 780
diff changeset
   884
    "/
789e2f20de44 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 780
diff changeset
   885
    "/ I made this an extra call to dispatch; this allows recompilation
789e2f20de44 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 780
diff changeset
   886
    "/  of the dispatch-handling code in the running system.
789e2f20de44 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 780
diff changeset
   887
    "/
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
   888
    [dispatching] whileTrue:[
20763
b1e9ec00e8af #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20760
diff changeset
   889
        ignoredSignals 
b1e9ec00e8af #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20760
diff changeset
   890
            handle:handlerAction 
b1e9ec00e8af #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20760
diff changeset
   891
            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
   892
    ].
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
   893
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
   894
    "/ 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
   895
    "/ 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
   896
    "/ 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
   897
2137
3e210d26d0d8 *PrintNL eliminated
Claus Gittinger <cg@exept.de>
parents: 2129
diff changeset
   898
    'Processor [info]: finish dispatch (no more processes)' infoPrintCR.
964
6d87e84d86ac in standAloneMode: exit dispatch if last process dies and no more sema/timer waits are pending
Claus Gittinger <cg@exept.de>
parents: 840
diff changeset
   899
13556
51005e5e65cd changed: #dispatchLoop
Claus Gittinger <cg@exept.de>
parents: 13164
diff changeset
   900
    "Modified: / 23-09-1996 / 14:19:56 / stefan"
14230
4d97053eeff0 changed: #dispatchLoop
Claus Gittinger <cg@exept.de>
parents: 13813
diff changeset
   901
    "Modified: / 20-07-2012 / 18:34:48 / 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
   902
!
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
   903
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
   904
exitWhenNoMoreUserProcesses:aBoolean
2193
Claus Gittinger <cg@exept.de>
parents: 2191
diff changeset
   905
    "set/clear the flag, which controls if the scheduler should exit and return
10747
e9ea71d01445 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10497
diff changeset
   906
     when the last user process finishes (and therefore exit the smalltalk system).
2193
Claus Gittinger <cg@exept.de>
parents: 2191
diff changeset
   907
     A userProcess is defined as a process with a non-zero processGroup.
10747
e9ea71d01445 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10497
diff changeset
   908
     This flag is typically set for standAlone operation, to terminate the (Unix-)
2193
Claus Gittinger <cg@exept.de>
parents: 2191
diff changeset
   909
     process, when the last thread terminates."
Claus Gittinger <cg@exept.de>
parents: 2191
diff changeset
   910
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
   911
    exitWhenNoMoreUserProcesses := aBoolean
827
3eb3911cb63e Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents: 807
diff changeset
   912
! !
806
409a8c189e01 also handle termination of the scheduler process
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
   913
6434
f23d12900e18 category rename
Claus Gittinger <cg@exept.de>
parents: 6421
diff changeset
   914
!ProcessorScheduler methodsFor:'initialization'!
3522
291ec553ac33 restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents: 3312
diff changeset
   915
291ec553ac33 restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents: 3312
diff changeset
   916
initialize
291ec553ac33 restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents: 3312
diff changeset
   917
    "initialize the one-and-only ProcessorScheduler"
291ec553ac33 restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents: 3312
diff changeset
   918
291ec553ac33 restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents: 3312
diff changeset
   919
    |nPrios "{ Class: SmallInteger }"
291ec553ac33 restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents: 3312
diff changeset
   920
     p l|
291ec553ac33 restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents: 3312
diff changeset
   921
291ec553ac33 restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents: 3312
diff changeset
   922
    KnownProcesses isNil ifTrue:[
19850
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
   923
	KnownProcesses := WeakArray new:30.
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
   924
	KnownProcesses addDependent:self class.
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
   925
	KnownProcessIds := OrderedCollection new:30.
3522
291ec553ac33 restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents: 3312
diff changeset
   926
    ].
291ec553ac33 restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents: 3312
diff changeset
   927
291ec553ac33 restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents: 3312
diff changeset
   928
    "
291ec553ac33 restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents: 3312
diff changeset
   929
     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
   930
    "
291ec553ac33 restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents: 3312
diff changeset
   931
    nPrios := SchedulingPriority.
291ec553ac33 restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents: 3312
diff changeset
   932
    quiescentProcessLists := Array new:nPrios.
3967
5e0053fdbf52 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3917
diff changeset
   933
5e0053fdbf52 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3917
diff changeset
   934
    readFdArray := Array new:5.
5e0053fdbf52 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3917
diff changeset
   935
    readCheckArray := Array new:5.
5e0053fdbf52 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3917
diff changeset
   936
    readSemaphoreArray := Array new:5.
5e0053fdbf52 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3917
diff changeset
   937
    writeFdArray := Array new:3.
5101
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
   938
    writeCheckArray := Array new:3.
3967
5e0053fdbf52 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3917
diff changeset
   939
    writeSemaphoreArray := Array new:3.
18957
e0bb91eae748 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18941
diff changeset
   940
    exceptFdArray := Array new:3.
e0bb91eae748 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18941
diff changeset
   941
    exceptSemaphoreArray := Array new:3.
e0bb91eae748 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18941
diff changeset
   942
3967
5e0053fdbf52 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3917
diff changeset
   943
    timeoutArray := Array new:5.
5e0053fdbf52 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3917
diff changeset
   944
    timeoutSemaphoreArray := Array new:5.
5e0053fdbf52 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3917
diff changeset
   945
    timeoutActionArray := Array new:5.
5e0053fdbf52 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3917
diff changeset
   946
    timeoutProcessArray := Array new:5.
5e0053fdbf52 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3917
diff changeset
   947
3522
291ec553ac33 restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents: 3312
diff changeset
   948
    anyTimeouts := false.
291ec553ac33 restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents: 3312
diff changeset
   949
    dispatching := false.
291ec553ac33 restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents: 3312
diff changeset
   950
    useIOInterrupts := OperatingSystem supportsIOInterrupts.
291ec553ac33 restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents: 3312
diff changeset
   951
    gotIOInterrupt := false.
291ec553ac33 restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents: 3312
diff changeset
   952
    osChildExitActions := Dictionary new.
291ec553ac33 restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents: 3312
diff changeset
   953
    gotChildSignalInterrupt := false.
19850
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
   954
    interruptCounter := timedActionCounter := 0.
3522
291ec553ac33 restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents: 3312
diff changeset
   955
17412
ef9b82b8ce77 class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 17341
diff changeset
   956
    supportDynamicPriorities := false.
ef9b82b8ce77 class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 17341
diff changeset
   957
    exitWhenNoMoreUserProcesses isNil ifTrue:[
19850
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
   958
	exitWhenNoMoreUserProcesses := false. "/ mhmh - how about true ?
17412
ef9b82b8ce77 class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 17341
diff changeset
   959
    ].
ef9b82b8ce77 class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 17341
diff changeset
   960
3522
291ec553ac33 restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents: 3312
diff changeset
   961
    "
291ec553ac33 restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents: 3312
diff changeset
   962
     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
   963
     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
   964
     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
   965
     for a runnable process.
291ec553ac33 restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents: 3312
diff changeset
   966
    "
291ec553ac33 restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents: 3312
diff changeset
   967
    currentPriority := SchedulingPriority.
291ec553ac33 restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents: 3312
diff changeset
   968
    p := Process basicNew.
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
   969
    p
19850
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
   970
	setId:0 state:#run;
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
   971
	setPriority:currentPriority;
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
   972
	name:'scheduler';
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
   973
	beSystemProcess.
3522
291ec553ac33 restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents: 3312
diff changeset
   974
291ec553ac33 restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents: 3312
diff changeset
   975
    scheduler := activeProcess := p.
291ec553ac33 restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents: 3312
diff changeset
   976
    activeProcessId := 0.
291ec553ac33 restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents: 3312
diff changeset
   977
291ec553ac33 restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents: 3312
diff changeset
   978
    quiescentProcessLists at:currentPriority put:(l := LinkedList new).
291ec553ac33 restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents: 3312
diff changeset
   979
    l add:p.
291ec553ac33 restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents: 3312
diff changeset
   980
291ec553ac33 restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents: 3312
diff changeset
   981
    "
291ec553ac33 restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents: 3312
diff changeset
   982
     let me handle IO and timer interrupts
291ec553ac33 restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents: 3312
diff changeset
   983
    "
5406
4a6995b61c0e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5396
diff changeset
   984
    useIOInterrupts ifTrue:[ObjectMemory ioInterruptHandler:self].
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
   985
    ObjectMemory
19850
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
   986
	timerInterruptHandler:self;
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
   987
	childSignalInterruptHandler:self.
3522
291ec553ac33 restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents: 3312
diff changeset
   988
3967
5e0053fdbf52 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3917
diff changeset
   989
    "Modified: / 7.1.1997 / 16:48:26 / stefan"
5e0053fdbf52 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3917
diff changeset
   990
    "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
   991
!
291ec553ac33 restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents: 3312
diff changeset
   992
291ec553ac33 restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents: 3312
diff changeset
   993
reinitialize
10747
e9ea71d01445 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10497
diff changeset
   994
    "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
   995
     - 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
   996
     especially, windowgroups have to.
291ec553ac33 restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents: 3312
diff changeset
   997
     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
   998
     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
   999
     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
  1000
     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
  1001
     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
  1002
     In praxis, this is not much of a problem, since in almost every case,
10747
e9ea71d01445 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10497
diff changeset
  1003
     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
  1004
     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
  1005
3525
26fe903e0250 oops - no need for last change
Claus Gittinger <cg@exept.de>
parents: 3522
diff changeset
  1006
    |processesToRestart|
26fe903e0250 oops - no need for last change
Claus Gittinger <cg@exept.de>
parents: 3522
diff changeset
  1007
3522
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
     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
  1010
    "
291ec553ac33 restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents: 3312
diff changeset
  1011
    processesToRestart := OrderedCollection new.
291ec553ac33 restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents: 3312
diff changeset
  1012
    KnownProcesses do:[:p |
18620
b4e9f25d6ce6 preparations for lined index list in WeakArray
Claus Gittinger <cg@exept.de>
parents: 18295
diff changeset
  1013
	(p notNil and:[p class ~~ SmallInteger]) ifTrue:[
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1014
	    "how, exactly should this be done ?"
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1015
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1016
	    p isRestartable == true ifTrue:[
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1017
		p nextLink:nil.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1018
		processesToRestart add:p
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1019
	    ] ifFalse:[
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1020
		p setId:nil state:#dead
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1021
	    ]
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1022
	].
3522
291ec553ac33 restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents: 3312
diff changeset
  1023
    ].
10747
e9ea71d01445 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10497
diff changeset
  1024
    scheduler setId:nil state:#dead.
3522
291ec553ac33 restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents: 3312
diff changeset
  1025
291ec553ac33 restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents: 3312
diff changeset
  1026
    "
291ec553ac33 restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents: 3312
diff changeset
  1027
     now, start from scratch
291ec553ac33 restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents: 3312
diff changeset
  1028
    "
291ec553ac33 restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents: 3312
diff changeset
  1029
    KnownProcesses := nil.
291ec553ac33 restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents: 3312
diff changeset
  1030
    self initialize.
291ec553ac33 restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents: 3312
diff changeset
  1031
3525
26fe903e0250 oops - no need for last change
Claus Gittinger <cg@exept.de>
parents: 3522
diff changeset
  1032
    processesToRestart do:[:p |
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1033
	p imageRestart
3522
291ec553ac33 restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents: 3312
diff changeset
  1034
    ]
291ec553ac33 restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents: 3312
diff changeset
  1035
3525
26fe903e0250 oops - no need for last change
Claus Gittinger <cg@exept.de>
parents: 3522
diff changeset
  1036
    "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
  1037
! !
291ec553ac33 restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents: 3312
diff changeset
  1038
3777
f351744c575f fix terminate/interrupt/reschedule while in osWait (win32)
Claus Gittinger <cg@exept.de>
parents: 3745
diff changeset
  1039
!ProcessorScheduler methodsFor:'native thread support'!
f351744c575f fix terminate/interrupt/reschedule while in osWait (win32)
Claus Gittinger <cg@exept.de>
parents: 3745
diff changeset
  1040
7842
c6ce40656157 preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents: 7761
diff changeset
  1041
vmResumeInterrupt:id
10747
e9ea71d01445 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10497
diff changeset
  1042
    "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
  1043
     MUST be invoked with interrupts blocked.
c6ce40656157 preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents: 7761
diff changeset
  1044
     This is only used with native threads."
c6ce40656157 preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents: 7761
diff changeset
  1045
8504
93b46834c68f #unblockInterrupts returns the prvious blocking state
Stefan Vogel <sv@exept.de>
parents: 8494
diff changeset
  1046
    <context: #return>
93b46834c68f #unblockInterrupts returns the prvious blocking state
Stefan Vogel <sv@exept.de>
parents: 8494
diff changeset
  1047
7842
c6ce40656157 preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents: 7761
diff changeset
  1048
    |index pri aProcess l|
c6ce40656157 preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents: 7761
diff changeset
  1049
c6ce40656157 preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents: 7761
diff changeset
  1050
    OperatingSystem interruptsBlocked ifFalse:[
19850
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  1051
	MiniDebugger
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  1052
	    enterWithMessage:'vmResumeInterrupt with no interruptsBlocked'
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  1053
	    mayProceed:true.
7842
c6ce40656157 preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents: 7761
diff changeset
  1054
    ].
c6ce40656157 preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents: 7761
diff changeset
  1055
c6ce40656157 preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents: 7761
diff changeset
  1056
    index := KnownProcessIds identityIndexOf:id.
c6ce40656157 preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents: 7761
diff changeset
  1057
    index ~~ 0 ifTrue:[
19850
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  1058
	aProcess := KnownProcesses at:index.
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  1059
	pri := aProcess priority.
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  1060
	l := quiescentProcessLists at:pri.
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  1061
	l notNil ifTrue:[
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  1062
	    (l includesIdentical:aProcess) ifTrue:[
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  1063
		"/ aProcess is on a run queue.
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  1064
		"/ CG: this situation may happen, if the wrapCall
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  1065
		"/ finishes before the process was layed to sleep
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  1066
		"/ (i.e. schedulerIRQ arrives before the threadSwitch was finished).
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  1067
		"/ In that case, simply resume it and everything is OK.
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  1068
		"/ If the process is state running, ignore.
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  1069
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  1070
		|state|
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  1071
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  1072
		state := aProcess state.
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  1073
		(state == #wrapWait or:[(state == #osWait) or:[state == #stopped]]) ifTrue:[
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  1074
		    aProcess state:#run.
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  1075
		].
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  1076
		'ProcSched [info]: resumeIRQ ignored for process: ' infoPrint.
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  1077
		aProcess id infoPrint. ' in state: ' infoPrint. state infoPrintCR.
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  1078
		^ self
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  1079
	    ]
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  1080
	] ifFalse:[
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  1081
	    l := LinkedList new.
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  1082
	    quiescentProcessLists at:pri put:l.
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  1083
	].
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  1084
	l addLast:aProcess.
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  1085
	aProcess state:#run.
7842
c6ce40656157 preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents: 7761
diff changeset
  1086
    ] ifFalse:[
19850
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  1087
	'ProcSched [info]: resumeIRQ for unknown process: ' infoPrint.
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  1088
	id infoPrintCR.
7842
c6ce40656157 preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents: 7761
diff changeset
  1089
    ]
c6ce40656157 preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents: 7761
diff changeset
  1090
c6ce40656157 preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents: 7761
diff changeset
  1091
    "Modified: / 28.9.1998 / 11:36:53 / cg"
c6ce40656157 preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents: 7761
diff changeset
  1092
!
c6ce40656157 preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents: 7761
diff changeset
  1093
7844
906062102891 preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents: 7843
diff changeset
  1094
vmSuspendInterrupt:whyCode
7842
c6ce40656157 preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents: 7761
diff changeset
  1095
    "signal from VM to suspend a thread into a certain state.
10747
e9ea71d01445 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10497
diff changeset
  1096
     Invoked before the VM switches to the scheduler process.
7842
c6ce40656157 preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents: 7761
diff changeset
  1097
     MUST be invoked with interrupts blocked.
c6ce40656157 preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents: 7761
diff changeset
  1098
     This is only used with native threads."
c6ce40656157 preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents: 7761
diff changeset
  1099
8504
93b46834c68f #unblockInterrupts returns the prvious blocking state
Stefan Vogel <sv@exept.de>
parents: 8494
diff changeset
  1100
    <context: #return>
93b46834c68f #unblockInterrupts returns the prvious blocking state
Stefan Vogel <sv@exept.de>
parents: 8494
diff changeset
  1101
7843
922a4285375a preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents: 7842
diff changeset
  1102
    |pri l newState|
7842
c6ce40656157 preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents: 7761
diff changeset
  1103
c6ce40656157 preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents: 7761
diff changeset
  1104
    OperatingSystem interruptsBlocked ifFalse:[
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1105
	MiniDebugger
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1106
	    enterWithMessage:'immediateInterrupt with no interruptsBlocked'
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1107
	    mayProceed:true.
7842
c6ce40656157 preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents: 7761
diff changeset
  1108
    ].
c6ce40656157 preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents: 7761
diff changeset
  1109
7844
906062102891 preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents: 7843
diff changeset
  1110
    (whyCode == 2) ifTrue:[
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1111
	 newState := #wrapWait.
7843
922a4285375a preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents: 7842
diff changeset
  1112
    ] ifFalse:[
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1113
	(whyCode == 3) ifTrue:[
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1114
	    newState := #osWait.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1115
	] ifFalse:[
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1116
	    newState := #stopped.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1117
	].
7843
922a4285375a preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents: 7842
diff changeset
  1118
    ].
7842
c6ce40656157 preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents: 7761
diff changeset
  1119
    activeProcess setStateTo:newState if:#active.
c6ce40656157 preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents: 7761
diff changeset
  1120
c6ce40656157 preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents: 7761
diff changeset
  1121
    pri := activeProcess priority.
c6ce40656157 preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents: 7761
diff changeset
  1122
    l := quiescentProcessLists at:pri.
c6ce40656157 preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents: 7761
diff changeset
  1123
c6ce40656157 preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents: 7761
diff changeset
  1124
    "notice: this is slightly faster than putting the if-code into
c6ce40656157 preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents: 7761
diff changeset
  1125
     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
  1126
    "
13164
b09c736a2e9b changed:
Stefan Vogel <sv@exept.de>
parents: 13149
diff changeset
  1127
    (l isNil or:[(l removeIdentical:activeProcess ifAbsent:nil) isNil]) ifTrue:[
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1128
	"/ 'Processor [warning]: bad vmSuspendInterrupt: not on run list' errorPrintCR.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1129
	MiniDebugger enterWithMessage:'bad vmSuspendInterrupt: not on run list' mayProceed:true.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1130
	^ self
7842
c6ce40656157 preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents: 7761
diff changeset
  1131
    ].
3777
f351744c575f fix terminate/interrupt/reschedule while in osWait (win32)
Claus Gittinger <cg@exept.de>
parents: 3745
diff changeset
  1132
! !
f351744c575f fix terminate/interrupt/reschedule while in osWait (win32)
Claus Gittinger <cg@exept.de>
parents: 3745
diff changeset
  1133
827
3eb3911cb63e Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents: 807
diff changeset
  1134
!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
  1135
3eb3911cb63e Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents: 807
diff changeset
  1136
childSignalInterrupt
2116
1bcb6ee86fca fixed pending sigChild problem;
Claus Gittinger <cg@exept.de>
parents: 2111
diff changeset
  1137
    "{ Pragma: +returnable }"
1bcb6ee86fca fixed pending sigChild problem;
Claus Gittinger <cg@exept.de>
parents: 2111
diff changeset
  1138
10747
e9ea71d01445 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10497
diff changeset
  1139
    "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
  1140
     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
  1141
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
  1142
    gotChildSignalInterrupt := true.
20052
4bd27ae52593 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19859
diff changeset
  1143
    interruptCounter := interruptCounter + 1 bitAnd:SmallInteger maxVal.
2966
856dfc8a294a lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2962
diff changeset
  1144
    activeProcess ~~ scheduler ifTrue:[
20706
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  1145
	interruptCounter := interruptCounter + 1 bitAnd:SmallInteger maxVal.
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  1146
	interruptedProcess := activeProcess.
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  1147
	self threadSwitch:scheduler
2966
856dfc8a294a lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2962
diff changeset
  1148
    ]
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
  1149
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
  1150
    "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
  1151
!
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
  1152
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
  1153
handleChildSignalInterrupt
827
3eb3911cb63e Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents: 807
diff changeset
  1154
    "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
  1155
     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
  1156
523533898acd Reset sigCHLD interrupt handler, when no more processes are being waited for.
Stefan Vogel <sv@exept.de>
parents: 829
diff changeset
  1157
    |osProcessStatus blocking wasBlocked|
827
3eb3911cb63e Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents: 807
diff changeset
  1158
18673
5bc94bc1ebbb isBlocking query renamed (name was misleading as to be a blocking wait)
Claus Gittinger <cg@exept.de>
parents: 18670
diff changeset
  1159
    blocking := OperatingSystem isChildProcessWaitBlocking.
827
3eb3911cb63e Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents: 807
diff changeset
  1160
840
523533898acd Reset sigCHLD interrupt handler, when no more processes are being waited for.
Stefan Vogel <sv@exept.de>
parents: 829
diff changeset
  1161
    "/ 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
  1162
    wasBlocked := OperatingSystem blockInterrupts.
827
3eb3911cb63e Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents: 807
diff changeset
  1163
    [
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1164
	[
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1165
	    osProcessStatus := OperatingSystem childProcessWait:blocking pid:nil.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1166
	    osProcessStatus notNil ifTrue:[
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1167
		|pid action|
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1168
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1169
		pid := osProcessStatus pid.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1170
		osProcessStatus stillAlive ifTrue:[
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1171
		    action := osChildExitActions at:pid ifAbsent:nil.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1172
		] ifFalse:[
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1173
		    action := osChildExitActions removeKey:pid ifAbsent:nil.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1174
		].
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1175
		action notNil ifTrue:[
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1176
		    action value:osProcessStatus
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1177
		].
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1178
	    ].
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1179
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1180
	    "/ if pollChildProcesses does block, poll only one status change.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1181
	    "/ we will get another SIGCHLD for other status changes.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1182
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1183
	    osProcessStatus notNil and:[blocking not]
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1184
	] whileTrue.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1185
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1186
	"/ if there are no more waiters, disable SIGCHILD handler.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1187
	"/ this helps us with synchronous waiters (e.g. pclose),
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1188
	"/ But they should block SIGCHLD anyway.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1189
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1190
	osChildExitActions isEmpty ifTrue:[
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1191
	    OperatingSystem disableChildSignalInterrupts.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1192
	].
6421
58dca33cf0fc #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 6376
diff changeset
  1193
    ] ensure:[
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1194
	wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
1032
924c177085f8 care to reenable interrupts
Claus Gittinger <cg@exept.de>
parents: 1001
diff changeset
  1195
    ]
827
3eb3911cb63e Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents: 807
diff changeset
  1196
840
523533898acd Reset sigCHLD interrupt handler, when no more processes are being waited for.
Stefan Vogel <sv@exept.de>
parents: 829
diff changeset
  1197
    "Modified: 5.1.1996 / 16:56:11 / stefan"
1032
924c177085f8 care to reenable interrupts
Claus Gittinger <cg@exept.de>
parents: 1001
diff changeset
  1198
    "Modified: 28.2.1996 / 21:36:31 / cg"
1154
96bb8fce61cf Fix removeCorruptedFds to clear LastErrorNumber. Handle ChildSignalInterrupts in Scheduler's context, to avoid errno corruption.
Stefan Vogel <sv@exept.de>
parents: 1133
diff changeset
  1199
    "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
  1200
!
3eb3911cb63e Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents: 807
diff changeset
  1201
2499
95392696facc Fix race condition when waiting for SIGCHLD.
Stefan Vogel <sv@exept.de>
parents: 2468
diff changeset
  1202
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
  1203
    "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
  1204
     aBlockReturningPid is evaluated and supposed to return
95392696facc Fix race condition when waiting for SIGCHLD.
Stefan Vogel <sv@exept.de>
parents: 2468
diff changeset
  1205
     the process-id of an OS-process or nil.
10747
e9ea71d01445 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10497
diff changeset
  1206
     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
  1207
     within the block.
95392696facc Fix race condition when waiting for SIGCHLD.
Stefan Vogel <sv@exept.de>
parents: 2468
diff changeset
  1208
     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
  1209
     status of the OS process changes (e.g. the process terminates).
20053
b46edac25a4e #DOCUMENTATION by mawalch
mawalch
parents: 20052
diff changeset
  1210
     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
  1211
16338
b8defcce7efc class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16322
diff changeset
  1212
    |pid wasBlocked|
b8defcce7efc class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16322
diff changeset
  1213
b8defcce7efc class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16322
diff changeset
  1214
    "/ aBlock will be evaluated:
b8defcce7efc class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16322
diff changeset
  1215
    "/   on unix: as soon as a SIGCHLD interrupt for pid has been received.
b8defcce7efc class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16322
diff changeset
  1216
    "/   on win:  as soon as a select for the pid handle returns
b8defcce7efc class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16322
diff changeset
  1217
b8defcce7efc class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16322
diff changeset
  1218
    OperatingSystem enableChildSignalInterrupts.        "/ no-op in windows
b8defcce7efc class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16322
diff changeset
  1219
    wasBlocked := OperatingSystem blockInterrupts.
b8defcce7efc class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16322
diff changeset
  1220
    "/ start the OS-Process
b8defcce7efc class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16322
diff changeset
  1221
    pid := aBlockReturningPid value.
b8defcce7efc class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16322
diff changeset
  1222
    pid notNil ifTrue:[
20706
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  1223
	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
  1224
    ].
16338
b8defcce7efc class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16322
diff changeset
  1225
    wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
2499
95392696facc Fix race condition when waiting for SIGCHLD.
Stefan Vogel <sv@exept.de>
parents: 2468
diff changeset
  1226
    ^ pid
95392696facc Fix race condition when waiting for SIGCHLD.
Stefan Vogel <sv@exept.de>
parents: 2468
diff changeset
  1227
3270
fd52c625f87c fixed monitoring for non-sigChild systems (WIN32)
Claus Gittinger <cg@exept.de>
parents: 3246
diff changeset
  1228
    "Created: / 25.3.1997 / 10:54:56 / stefan"
fd52c625f87c fixed monitoring for non-sigChild systems (WIN32)
Claus Gittinger <cg@exept.de>
parents: 3246
diff changeset
  1229
    "Modified: / 25.3.1997 / 11:21:05 / stefan"
fd52c625f87c fixed monitoring for non-sigChild systems (WIN32)
Claus Gittinger <cg@exept.de>
parents: 3246
diff changeset
  1230
    "Modified: / 15.4.1997 / 11:55:57 / David"
4127
f3960fe6ec41 reuse the delay object in #monitor:action:
Claus Gittinger <cg@exept.de>
parents: 4042
diff changeset
  1231
    "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
  1232
!
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
  1233
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
  1234
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
  1235
    "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
  1236
2966
856dfc8a294a lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2962
diff changeset
  1237
    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
  1238
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
  1239
    "Created: 12.4.1996 / 19:01:59 / cg"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1240
! !
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1241
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1242
!ProcessorScheduler methodsFor:'primitive process primitives'!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1243
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1244
scheduleForInterrupt:aProcess
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1245
    "make aProcess evaluate its pushed interrupt block(s)"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1246
1092
2a8acc60f5b5 added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents: 1086
diff changeset
  1247
    self scheduleInterruptActionsOf:aProcess.
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1248
    aProcess state ~~ #stopped ifTrue:[
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1249
	"
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1250
	 make the process runnable
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1251
	"
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1252
	self resume:aProcess
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1253
    ]
1092
2a8acc60f5b5 added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents: 1086
diff changeset
  1254
3777
f351744c575f fix terminate/interrupt/reschedule while in osWait (win32)
Claus Gittinger <cg@exept.de>
parents: 3745
diff changeset
  1255
    "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
  1256
!
2a8acc60f5b5 added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents: 1086
diff changeset
  1257
2a8acc60f5b5 added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents: 1086
diff changeset
  1258
scheduleInterruptActionsOf:aProcess
2a8acc60f5b5 added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents: 1086
diff changeset
  1259
    "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
  1260
     when resumed."
2a8acc60f5b5 added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents: 1086
diff changeset
  1261
2a8acc60f5b5 added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents: 1086
diff changeset
  1262
    |id|
2a8acc60f5b5 added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents: 1086
diff changeset
  1263
2a8acc60f5b5 added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents: 1086
diff changeset
  1264
    aProcess isNil ifTrue:[^ self].
2a8acc60f5b5 added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents: 1086
diff changeset
  1265
    aProcess == activeProcess ifTrue:[^ self].
2a8acc60f5b5 added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents: 1086
diff changeset
  1266
2a8acc60f5b5 added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents: 1086
diff changeset
  1267
    id := aProcess id.
2a8acc60f5b5 added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents: 1086
diff changeset
  1268
    self class threadInterrupt:id.
2a8acc60f5b5 added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents: 1086
diff changeset
  1269
2a8acc60f5b5 added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents: 1086
diff changeset
  1270
    "Created: 5.3.1996 / 17:25:55 / cg"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1271
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1272
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1273
threadSwitch:aProcess
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1274
    "continue execution in aProcess.
1783
be7402f74d94 hide timerInterrupt & ioInterrupt contexts when switching
Claus Gittinger <cg@exept.de>
parents: 1780
diff changeset
  1275
     WARNING: this is a low level entry, no process administration is done here"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1276
3644
dacb2b9d4867 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3566
diff changeset
  1277
    |id pri ok oldProcess oldPri oldId p nm singleStep wasBlocked|
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1278
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1279
    (aProcess isNil or:[aProcess == activeProcess]) ifTrue:[^ self].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1280
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1281
    wasBlocked := OperatingSystem blockInterrupts.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1282
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1283
    oldProcess := activeProcess.
2262
4c4d810f006f semaphore names
Claus Gittinger <cg@exept.de>
parents: 2258
diff changeset
  1284
    oldId := activeProcessId.
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1285
    oldPri := currentPriority.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1286
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1287
    id := aProcess id.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1288
    pri := aProcess priority.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1289
    singleStep := aProcess isSingleStepping.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1290
    aProcess state:#active.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1291
    oldProcess setStateTo:#run if:#active.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1292
5449
bf1de72fd2bb preps for rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5406
diff changeset
  1293
    currentPriority := pri.
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1294
    activeProcess := aProcess.
2262
4c4d810f006f semaphore names
Claus Gittinger <cg@exept.de>
parents: 2258
diff changeset
  1295
    activeProcessId := id.
12958
fc084b295df6 changed: #threadSwitch:
Claus Gittinger <cg@exept.de>
parents: 12717
diff changeset
  1296
fc084b295df6 changed: #threadSwitch:
Claus Gittinger <cg@exept.de>
parents: 12717
diff changeset
  1297
    "
fc084b295df6 changed: #threadSwitch:
Claus Gittinger <cg@exept.de>
parents: 12717
diff changeset
  1298
     no interrupts now - activeProcess has already been changed
20810
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
  1299
     (don't add any message sends here)
12958
fc084b295df6 changed: #threadSwitch:
Claus Gittinger <cg@exept.de>
parents: 12717
diff changeset
  1300
    "
fc084b295df6 changed: #threadSwitch:
Claus Gittinger <cg@exept.de>
parents: 12717
diff changeset
  1301
"/    ok := self threadSwitchFrom:oldProcess to:aProcess id:id singleStep:singleStep.
fc084b295df6 changed: #threadSwitch:
Claus Gittinger <cg@exept.de>
parents: 12717
diff changeset
  1302
%{
fc084b295df6 changed: #threadSwitch:
Claus Gittinger <cg@exept.de>
parents: 12717
diff changeset
  1303
    extern OBJ ___threadSwitch();
fc084b295df6 changed: #threadSwitch:
Claus Gittinger <cg@exept.de>
parents: 12717
diff changeset
  1304
fc084b295df6 changed: #threadSwitch:
Claus Gittinger <cg@exept.de>
parents: 12717
diff changeset
  1305
    if (__isSmallInteger(id)) {
20810
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
  1306
        ok = ___threadSwitch(__context, __intVal(id), (singleStep == true) ? 1 : 0, 0);
12958
fc084b295df6 changed: #threadSwitch:
Claus Gittinger <cg@exept.de>
parents: 12717
diff changeset
  1307
    } else {
20810
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
  1308
        ok = false;
12958
fc084b295df6 changed: #threadSwitch:
Claus Gittinger <cg@exept.de>
parents: 12717
diff changeset
  1309
    }
fc084b295df6 changed: #threadSwitch:
Claus Gittinger <cg@exept.de>
parents: 12717
diff changeset
  1310
%}.
5449
bf1de72fd2bb preps for rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5406
diff changeset
  1311
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1312
    "time passes spent in some other process ...
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1313
     ... here again"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1314
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1315
    p := activeProcess.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1316
    activeProcess := oldProcess.
2262
4c4d810f006f semaphore names
Claus Gittinger <cg@exept.de>
parents: 2258
diff changeset
  1317
    activeProcessId := oldId.
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1318
    currentPriority := oldProcess priority.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1319
21009
d4035978c3c7 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20964
diff changeset
  1320
    ok ~~ true ifTrue:[
20810
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
  1321
        "
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
  1322
         switch failed for some reason -
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
  1323
         destroy (hard-terminate) the bad process.
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
  1324
         This happens when:
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
  1325
         - the stack went above the absolute limit
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
  1326
           (VM switches back to scheduler)
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
  1327
         - a halted process cannot execute its interrupt
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
  1328
           actions (win32 only)
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
  1329
        "
21009
d4035978c3c7 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20964
diff changeset
  1330
        id := p id.
d4035978c3c7 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20964
diff changeset
  1331
        (id ~~ 0 and:[id notNil]) ifTrue:[
d4035978c3c7 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20964
diff changeset
  1332
            'Processor [warning]: problem with process ' errorPrint.
d4035978c3c7 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20964
diff changeset
  1333
            id errorPrint.
d4035978c3c7 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20964
diff changeset
  1334
            (nm := p name) notNil ifTrue:[
d4035978c3c7 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20964
diff changeset
  1335
                ' (' errorPrint. nm errorPrint. ')' errorPrint.
d4035978c3c7 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20964
diff changeset
  1336
            ].
d4035978c3c7 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20964
diff changeset
  1337
d4035978c3c7 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20964
diff changeset
  1338
            ok == #halted ifTrue:[
d4035978c3c7 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20964
diff changeset
  1339
                "/ that process was halted (win32 only)
d4035978c3c7 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20964
diff changeset
  1340
                p state:#halted.
d4035978c3c7 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20964
diff changeset
  1341
               '; stopped it.' errorPrintCR.
d4035978c3c7 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20964
diff changeset
  1342
               self suspend:p.
d4035978c3c7 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20964
diff changeset
  1343
            ] ifFalse:[
d4035978c3c7 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20964
diff changeset
  1344
               '; hard-terminate it.' errorPrintCR.
d4035978c3c7 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20964
diff changeset
  1345
               'Processor [info]: cleanup may take a while if stack is huge' infoPrintCR.
d4035978c3c7 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20964
diff changeset
  1346
               p state:#cleanup.
d4035978c3c7 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20964
diff changeset
  1347
               self terminateNoSignal:p.
20810
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
  1348
            ]
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
  1349
        ]
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1350
    ].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1351
    zombie notNil ifTrue:[
20810
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
  1352
        self class threadDestroy:zombie.
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
  1353
        zombie := nil
1783
be7402f74d94 hide timerInterrupt & ioInterrupt contexts when switching
Claus Gittinger <cg@exept.de>
parents: 1780
diff changeset
  1354
    ].
be7402f74d94 hide timerInterrupt & ioInterrupt contexts when switching
Claus Gittinger <cg@exept.de>
parents: 1780
diff changeset
  1355
    wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
12958
fc084b295df6 changed: #threadSwitch:
Claus Gittinger <cg@exept.de>
parents: 12717
diff changeset
  1356
fc084b295df6 changed: #threadSwitch:
Claus Gittinger <cg@exept.de>
parents: 12717
diff changeset
  1357
    "Modified: / 23-07-2010 / 10:32:11 / cg"
1787
32632b6f969d remember threadSwitch:from: idea for later implementation;
Claus Gittinger <cg@exept.de>
parents: 1783
diff changeset
  1358
! !
32632b6f969d remember threadSwitch:from: idea for later implementation;
Claus Gittinger <cg@exept.de>
parents: 1783
diff changeset
  1359
1981
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1360
!ProcessorScheduler methodsFor:'priority constants'!
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1361
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1362
highIOPriority
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1363
    "not currently used - for ST80 compatibility only"
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1364
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1365
    ^ 16 "claus: is this ok ?"
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1366
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1367
    "Created: 15.11.1996 / 11:42:39 / cg"
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1368
!
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1369
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1370
highestPriority
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1371
    "return the highest priority value (normal) processes can have."
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1372
10747
e9ea71d01445 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10497
diff changeset
  1373
    "must be below schedulingPriority -
1981
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1374
     otherwise scheduler could be blocked ...
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1375
    "
10747
e9ea71d01445 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10497
diff changeset
  1376
    ^ HighestPriority
1981
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1377
!
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1378
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1379
lowIOPriority
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1380
    "not currently used - for ST80 compatibility only"
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1381
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1382
    ^ 2 "claus: is this ok ?"
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1383
!
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1384
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1385
lowestPriority
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1386
    "return the lowest priority value"
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1387
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1388
    ^ 1   "do not change this - its not variable"
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1389
!
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1390
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1391
schedulingPriority
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1392
    "return the priority at which the scheduler runs."
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1393
10747
e9ea71d01445 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10497
diff changeset
  1394
    "must be above highestPriority -
1981
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1395
     otherwise scheduler could be blocked ...
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1396
    "
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1397
    ^ SchedulingPriority
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1398
!
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
systemBackgroundPriority
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1401
    "return the priority, at which background system processing
7076
738bbff659e8 comments
Claus Gittinger <cg@exept.de>
parents: 7046
diff changeset
  1402
     should take place."
1981
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1403
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1404
    ^ 4
7076
738bbff659e8 comments
Claus Gittinger <cg@exept.de>
parents: 7046
diff changeset
  1405
738bbff659e8 comments
Claus Gittinger <cg@exept.de>
parents: 7046
diff changeset
  1406
    "
738bbff659e8 comments
Claus Gittinger <cg@exept.de>
parents: 7046
diff changeset
  1407
     Processor systemBackgroundPriority
738bbff659e8 comments
Claus Gittinger <cg@exept.de>
parents: 7046
diff changeset
  1408
    "
1981
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1409
!
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1410
2190
8afa4709d8a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2188
diff changeset
  1411
timeSlicingPriorityLimit
8afa4709d8a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2188
diff changeset
  1412
    "return the priority, above which no timeslicing takes place
8afa4709d8a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2188
diff changeset
  1413
     (i.e. processes running at a higher priority are not preempted).
8afa4709d8a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2188
diff changeset
  1414
     This is only effective, if preemption is enabled."
8afa4709d8a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2188
diff changeset
  1415
8afa4709d8a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2188
diff changeset
  1416
    ^ TimeSlicingPriorityLimit
8afa4709d8a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2188
diff changeset
  1417
!
8afa4709d8a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2188
diff changeset
  1418
2191
6c641780265d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2190
diff changeset
  1419
timingPriority
6c641780265d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2190
diff changeset
  1420
    "return the priority, at which all timing takes place (messageTally,
6c641780265d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2190
diff changeset
  1421
     delay etc.)"
6c641780265d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2190
diff changeset
  1422
6c641780265d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2190
diff changeset
  1423
    ^ TimingPriority
6c641780265d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2190
diff changeset
  1424
!
6c641780265d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2190
diff changeset
  1425
1981
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1426
userBackgroundPriority
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1427
    "return the priority, at which background user (non-interactive) processing
7076
738bbff659e8 comments
Claus Gittinger <cg@exept.de>
parents: 7046
diff changeset
  1428
     should take place."
1981
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
    ^ 6
7076
738bbff659e8 comments
Claus Gittinger <cg@exept.de>
parents: 7046
diff changeset
  1431
738bbff659e8 comments
Claus Gittinger <cg@exept.de>
parents: 7046
diff changeset
  1432
    "
738bbff659e8 comments
Claus Gittinger <cg@exept.de>
parents: 7046
diff changeset
  1433
     Processor userBackgroundPriority
738bbff659e8 comments
Claus Gittinger <cg@exept.de>
parents: 7046
diff changeset
  1434
    "
1981
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1435
!
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
userInterruptPriority
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1438
    "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
  1439
     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
  1440
     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
  1441
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1442
    ^ UserInterruptPriority
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1443
!
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1444
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1445
userSchedulingPriority
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1446
    "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
  1447
     takes place"
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1448
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1449
    ^ UserSchedulingPriority
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1450
! !
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1451
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1452
!ProcessorScheduler methodsFor:'private'!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1453
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1454
remember:aProcess
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1455
    "remember aProcess for later disposal (where the underlying
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1456
     system resources have to be freed)."
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1457
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1458
    |newShadow oldId wasBlocked
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1459
     oldSize "{ Class: SmallInteger }"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1460
     index   "{ Class: SmallInteger }"
1787
32632b6f969d remember threadSwitch:from: idea for later implementation;
Claus Gittinger <cg@exept.de>
parents: 1783
diff changeset
  1461
     sz      "{ Class: SmallInteger }" |
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1462
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1463
    wasBlocked := OperatingSystem blockInterrupts.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1464
    index := 1.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1465
    sz := KnownProcessIds size.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1466
    [index <= sz] whileTrue:[
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1467
	(KnownProcesses at:index) isNil ifTrue:[
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1468
	    oldId := KnownProcessIds at:index.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1469
	    oldId notNil ifTrue:[
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1470
		self class threadDestroy:oldId.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1471
	    ].
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1472
	    KnownProcesses at:index put:aProcess.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1473
	    KnownProcessIds at:index put:aProcess id.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1474
	    wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1475
	    ^ self
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1476
	].
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1477
	index := index + 1
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1478
    ].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1479
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1480
    KnownProcessIds grow:index.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1481
    KnownProcessIds at:index put:aProcess id.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1482
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1483
    oldSize := KnownProcesses size.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1484
    (index > oldSize) ifTrue:[
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1485
	newShadow := WeakArray new:(oldSize * 2).
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1486
	newShadow addDependent:self class.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1487
	newShadow replaceFrom:1 with:KnownProcesses.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1488
	KnownProcesses := newShadow
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1489
    ].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1490
    KnownProcesses at:index put:aProcess.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1491
    wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
2091
c11bb3e29a1b Use dependent mechamism of WeakArray instead of #watcher.
Stefan Vogel <sv@exept.de>
parents: 1981
diff changeset
  1492
c11bb3e29a1b Use dependent mechamism of WeakArray instead of #watcher.
Stefan Vogel <sv@exept.de>
parents: 1981
diff changeset
  1493
    "Modified: 7.1.1997 / 16:48:39 / stefan"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1494
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1495
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1496
unRemember:aProcess
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1497
    "forget aProcess - dispose processing will not consider this one"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1498
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1499
    |index wasBlocked|
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1500
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1501
    wasBlocked := OperatingSystem blockInterrupts.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1502
    index := KnownProcesses identityIndexOf:aProcess.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1503
    index ~~ 0 ifTrue:[
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1504
	KnownProcessIds at:index put:nil.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1505
	KnownProcesses at:index put:nil.
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1506
    ].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1507
    wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1508
! !
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1509
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1510
!ProcessorScheduler methodsFor:'process creation'!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1511
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1512
newProcessFor:aProcess
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1513
    "create a physical (VM-) process for aProcess.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1514
     Return true if ok, false if something went wrong.
10747
e9ea71d01445 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10497
diff changeset
  1515
     The process is not scheduled; to start it running,
e9ea71d01445 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10497
diff changeset
  1516
     it needs a Process>>resume. Once resumed, the process will later
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1517
     get control in its #start method."
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1518
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1519
    |id|
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1520
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1521
    id := self class threadCreate:aProcess withId:nil.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1522
    aProcess setId:id state:#light.   "meaning: has no stack yet"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1523
    self remember:aProcess.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1524
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1525
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1526
newProcessFor:aProcess withId:idWant
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1527
    "private entry for Process restart - do not use in your program"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1528
1836
08a200835cc8 process restart is different if done at image restart time.
Claus Gittinger <cg@exept.de>
parents: 1793
diff changeset
  1529
    idWant isNil ifTrue:[
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1530
	self newProcessFor:aProcess.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1531
	^ true.
1836
08a200835cc8 process restart is different if done at image restart time.
Claus Gittinger <cg@exept.de>
parents: 1793
diff changeset
  1532
    ].
08a200835cc8 process restart is different if done at image restart time.
Claus Gittinger <cg@exept.de>
parents: 1793
diff changeset
  1533
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1534
    (self class threadCreate:aProcess withId:idWant) ~~ idWant ifTrue:[
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1535
	^ false
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1536
    ].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1537
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1538
    aProcess state:#light.   "meaning: has no stack yet"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1539
    self remember:aProcess.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1540
    ^ true
1836
08a200835cc8 process restart is different if done at image restart time.
Claus Gittinger <cg@exept.de>
parents: 1793
diff changeset
  1541
08a200835cc8 process restart is different if done at image restart time.
Claus Gittinger <cg@exept.de>
parents: 1793
diff changeset
  1542
    "Modified: 28.10.1996 / 19:14:28 / cg"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1543
! !
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1544
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1545
!ProcessorScheduler methodsFor:'queries'!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1546
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1547
activeProcessIsSystemProcess
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1548
    "return true if the active process is a system process,
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1549
     which should not be suspended."
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1550
2637
0d8508bedf06 Move #isSystemProcess from ProcessorScheduler to Process.
Stefan Vogel <sv@exept.de>
parents: 2626
diff changeset
  1551
    ^ activeProcess isSystemProcess
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1552
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1553
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1554
     Processor activeProcessIsSystemProcess
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1555
    "
2637
0d8508bedf06 Move #isSystemProcess from ProcessorScheduler to Process.
Stefan Vogel <sv@exept.de>
parents: 2626
diff changeset
  1556
0d8508bedf06 Move #isSystemProcess from ProcessorScheduler to Process.
Stefan Vogel <sv@exept.de>
parents: 2626
diff changeset
  1557
    "Modified: 17.4.1997 / 12:59:33 / stefan"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1558
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1559
20754
6d076c61a915 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20753
diff changeset
  1560
anyScheduledWindowGroupAtAll
6d076c61a915 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20753
diff changeset
  1561
    "return true, if there is any window group with active topviews.
6d076c61a915 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20753
diff changeset
  1562
     This is used to determine if we should stop scheduling
6d076c61a915 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20753
diff changeset
  1563
     in standAlone applications."
6d076c61a915 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20753
diff changeset
  1564
6d076c61a915 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20753
diff changeset
  1565
    Screen notNil ifTrue:[
6d076c61a915 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20753
diff changeset
  1566
        Screen allScreens notEmptyOrNil ifTrue:[
6d076c61a915 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20753
diff changeset
  1567
            WindowGroup scheduledWindowGroups notEmptyOrNil ifTrue:[^ true]. 
6d076c61a915 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20753
diff changeset
  1568
        ].
6d076c61a915 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20753
diff changeset
  1569
    ].
6d076c61a915 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20753
diff changeset
  1570
    ^ false
6d076c61a915 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20753
diff changeset
  1571
6d076c61a915 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20753
diff changeset
  1572
    "
6d076c61a915 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20753
diff changeset
  1573
     Processor anyScheduledWindowGroupAtAll
6d076c61a915 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20753
diff changeset
  1574
    "
6d076c61a915 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20753
diff changeset
  1575
!
6d076c61a915 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20753
diff changeset
  1576
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
  1577
anyUserProcessAtAll
18940
dc91734b9496 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18776
diff changeset
  1578
    "return true, if there is any user process still running,
dc91734b9496 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18776
diff changeset
  1579
     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
  1580
     This is used to determine if we should stop scheduling
2193
Claus Gittinger <cg@exept.de>
parents: 2191
diff changeset
  1581
     in standAlone applications.
20736
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  1582
     A user process has a non-zero processGroup.
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  1583
     Should be called with interrupts blocked."
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  1584
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  1585
    |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
  1586
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
  1587
    prio := HighestPriority.
3745
3fd121f2e74e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3740
diff changeset
  1588
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
  1589
    listArray := quiescentProcessLists.
1571
8d00e6b97ca7 changed #anyUserProcessAtAll,
Claus Gittinger <cg@exept.de>
parents: 1473
diff changeset
  1590
8d00e6b97ca7 changed #anyUserProcessAtAll,
Claus Gittinger <cg@exept.de>
parents: 1473
diff changeset
  1591
    [prio >= 1] whileTrue:[
20736
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  1592
        l := listArray at:prio.
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  1593
        l notNil ifTrue:[
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  1594
            l linksDo:[:aProcess |
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  1595
                aProcess isUserProcess ifTrue:[
20883
1de8290ae4d8 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20882
diff changeset
  1596
                    "/ 'anyUserProcess: found quiescent ' _errorPrint. aProcess asString _errorPrintCR.
20736
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  1597
                    ^ true.
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  1598
                ]
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  1599
            ]
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  1600
        ].
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  1601
        prio := prio - 1
18940
dc91734b9496 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18776
diff changeset
  1602
    ].
dc91734b9496 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18776
diff changeset
  1603
20760
dcfd225589c4 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20756
diff changeset
  1604
    (scheduledProcesses notNil 
20883
1de8290ae4d8 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20882
diff changeset
  1605
    and:[scheduledProcesses contains:[:p | p notNil and:[p isUserProcess and:[p state ~~ #dead]] ]]) ifTrue:[
1de8290ae4d8 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20882
diff changeset
  1606
       "/ 'anyUserProcess: found scheduled ' _errorPrint. 
1de8290ae4d8 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20882
diff changeset
  1607
       "/ (scheduledProcesses detect:[:p | p notNil and:[p isUserProcess and:[p state ~~ #dead]] ]) asString _errorPrintCR.
20751
e46f74b65b46 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20749
diff changeset
  1608
        ^ true.
e46f74b65b46 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20749
diff changeset
  1609
    ].    
e46f74b65b46 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20749
diff changeset
  1610
        
18940
dc91734b9496 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18776
diff changeset
  1611
    "/ any user process waiting on a sema?
19850
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  1612
    (readSemaphoreArray contains:[:sema |
20883
1de8290ae4d8 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20882
diff changeset
  1613
        sema notNil and:[sema waitingProcesses contains:[:p | p notNil and:[p isUserProcess and:[p state ~~ #dead]] ]]]
18940
dc91734b9496 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18776
diff changeset
  1614
    ) ifTrue:[
20883
1de8290ae4d8 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20882
diff changeset
  1615
       "/ 'anyUserProcess: found on read sema' _errorPrintCR.
20736
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  1616
        ^ 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
  1617
    ].
19850
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  1618
    (writeSemaphoreArray contains:[:sema |
20883
1de8290ae4d8 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20882
diff changeset
  1619
        sema notNil and:[sema waitingProcesses contains:[:p | p notNil and:[p isUserProcess and:[p state ~~ #dead]] ]]]
18940
dc91734b9496 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18776
diff changeset
  1620
    ) ifTrue:[
20883
1de8290ae4d8 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20882
diff changeset
  1621
       "/ 'anyUserProcess: found on write sema' _errorPrintCR.
20736
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  1622
        ^ true.
18940
dc91734b9496 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18776
diff changeset
  1623
    ].
19850
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  1624
    (timeoutSemaphoreArray contains:[:sema |
20883
1de8290ae4d8 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20882
diff changeset
  1625
        sema notNil and:[sema waitingProcesses contains:[:p | p notNil and:[p isUserProcess and:[p state ~~ #dead]] ]]]
18940
dc91734b9496 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18776
diff changeset
  1626
    ) ifTrue:[
20883
1de8290ae4d8 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20882
diff changeset
  1627
       "/ 'anyUserProcess: found on timeout sema' _errorPrintCR.
20736
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  1628
        ^ true.
18940
dc91734b9496 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18776
diff changeset
  1629
    ].
dc91734b9496 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18776
diff changeset
  1630
    (timeoutProcessArray contains:[:p | p notNil and:[p isUserProcess] ]
dc91734b9496 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18776
diff changeset
  1631
    ) ifTrue:[
20736
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  1632
        ^ true.
18940
dc91734b9496 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18776
diff changeset
  1633
    ].
dc91734b9496 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18776
diff changeset
  1634
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
  1635
    ^ false
1571
8d00e6b97ca7 changed #anyUserProcessAtAll,
Claus Gittinger <cg@exept.de>
parents: 1473
diff changeset
  1636
8d00e6b97ca7 changed #anyUserProcessAtAll,
Claus Gittinger <cg@exept.de>
parents: 1473
diff changeset
  1637
    "
10747
e9ea71d01445 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10497
diff changeset
  1638
     Processor anyUserProcessAtAll
1571
8d00e6b97ca7 changed #anyUserProcessAtAll,
Claus Gittinger <cg@exept.de>
parents: 1473
diff changeset
  1639
    "
8d00e6b97ca7 changed #anyUserProcessAtAll,
Claus Gittinger <cg@exept.de>
parents: 1473
diff changeset
  1640
1618
9fb4ee952e89 use nil for empty lists
Claus Gittinger <cg@exept.de>
parents: 1606
diff changeset
  1641
    "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
  1642
!
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
  1643
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1644
highestPriorityRunnableProcess
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1645
    "return the highest prio runnable process"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1646
10747
e9ea71d01445 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10497
diff changeset
  1647
    |listArray l p prio "{ Class: SmallInteger }"
3745
3fd121f2e74e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3740
diff changeset
  1648
     wasBlocked|
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1649
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1650
    prio := HighestPriority.
3745
3fd121f2e74e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3740
diff changeset
  1651
    wasBlocked := OperatingSystem blockInterrupts.
3fd121f2e74e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3740
diff changeset
  1652
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1653
    listArray := quiescentProcessLists.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1654
    [prio >= 1] whileTrue:[
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1655
	l := listArray at:prio.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1656
	l notNil ifTrue:[
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1657
	    l notEmpty ifTrue:[
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1658
		p := l firstLink.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1659
		"
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1660
		 if it got corrupted somehow ...
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1661
		"
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1662
		p isDead ifTrue:[
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1663
		    'Processor [warning]: dead process removed' errorPrintCR.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1664
		    l removeFirst.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1665
		    p := nil.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1666
		].
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1667
		wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1668
		^ p
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1669
	    ]
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1670
	].
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1671
	prio := prio - 1
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1672
    ].
3745
3fd121f2e74e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3740
diff changeset
  1673
    wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1674
    ^ nil
1086
7b0641a2e1ef nicer message
Claus Gittinger <cg@exept.de>
parents: 1061
diff changeset
  1675
2385
9b6e06112b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2353
diff changeset
  1676
    "Modified: 12.2.1997 / 12:41:49 / cg"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1677
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1678
5389
509d4228751b added query: #isDispatching
ca
parents: 5107
diff changeset
  1679
isDispatching
509d4228751b added query: #isDispatching
ca
parents: 5107
diff changeset
  1680
    ^ dispatching
509d4228751b added query: #isDispatching
ca
parents: 5107
diff changeset
  1681
!
509d4228751b added query: #isDispatching
ca
parents: 5107
diff changeset
  1682
1177
05f4917ccc4f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1166
diff changeset
  1683
isPureEventDriven
05f4917ccc4f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1166
diff changeset
  1684
    "this is temporary - (maybe not :-).
05f4917ccc4f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1166
diff changeset
  1685
     you can run ST/X either with or without processes.
05f4917ccc4f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1166
diff changeset
  1686
     Without, there is conceptionally a single process handling all
05f4917ccc4f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1166
diff changeset
  1687
     outside events and timeouts. This has some negative implications
05f4917ccc4f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1166
diff changeset
  1688
     (Debugger is ugly), but allows a fully portable ST/X without any
05f4917ccc4f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1166
diff changeset
  1689
     assembler support - i.e. quick portability.
05f4917ccc4f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1166
diff changeset
  1690
     The PureEvent flag will automatically be set if the runtime system
05f4917ccc4f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1166
diff changeset
  1691
     does not support threads - otherwise, it can be set manually
05f4917ccc4f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1166
diff changeset
  1692
     (from rc-file).
05f4917ccc4f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1166
diff changeset
  1693
    "
05f4917ccc4f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1166
diff changeset
  1694
05f4917ccc4f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1166
diff changeset
  1695
    ^ PureEventDriven
05f4917ccc4f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1166
diff changeset
  1696
05f4917ccc4f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1166
diff changeset
  1697
    "Created: 13.4.1996 / 20:31:31 / cg"
05f4917ccc4f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1166
diff changeset
  1698
!
05f4917ccc4f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1166
diff changeset
  1699
2191
6c641780265d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2190
diff changeset
  1700
isTimeSlicing
6c641780265d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2190
diff changeset
  1701
    "return true, if in timeslicing mode"
6c641780265d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2190
diff changeset
  1702
6c641780265d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2190
diff changeset
  1703
    ^ timeSliceProcess notNil
6c641780265d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2190
diff changeset
  1704
6c641780265d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2190
diff changeset
  1705
    "
6c641780265d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2190
diff changeset
  1706
     Processor isTimeSlicing
6c641780265d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2190
diff changeset
  1707
    "
6c641780265d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2190
diff changeset
  1708
6c641780265d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2190
diff changeset
  1709
    "Modified: 17.1.1997 / 17:48:41 / cg"
16623
d6fb73207eca class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16538
diff changeset
  1710
!
d6fb73207eca class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16538
diff changeset
  1711
d6fb73207eca class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16538
diff changeset
  1712
processWithId:anInteger
d6fb73207eca class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16538
diff changeset
  1713
    "answer the process with id anInteger, or nil if there is none"
d6fb73207eca class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16538
diff changeset
  1714
16624
ec0aed640724 class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16623
diff changeset
  1715
    |wasBlocked slot process|
ec0aed640724 class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16623
diff changeset
  1716
ec0aed640724 class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16623
diff changeset
  1717
    wasBlocked := OperatingSystem blockInterrupts.
16623
d6fb73207eca class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16538
diff changeset
  1718
d6fb73207eca class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16538
diff changeset
  1719
    slot := KnownProcessIds indexOf:anInteger.
16624
ec0aed640724 class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16623
diff changeset
  1720
    slot ~~ 0 ifTrue:[
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1721
	process := KnownProcesses at:slot ifAbsent:[].
16624
ec0aed640724 class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16623
diff changeset
  1722
    ].
ec0aed640724 class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16623
diff changeset
  1723
ec0aed640724 class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16623
diff changeset
  1724
    wasBlocked ifFalse:[
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1725
	OperatingSystem unblockInterrupts.
16624
ec0aed640724 class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16623
diff changeset
  1726
    ].
ec0aed640724 class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16623
diff changeset
  1727
ec0aed640724 class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16623
diff changeset
  1728
    "Take care, the process may already have been collected"
ec0aed640724 class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16623
diff changeset
  1729
    process == 0 ifTrue:[
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1730
	^ nil.
16623
d6fb73207eca class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16538
diff changeset
  1731
    ].
16624
ec0aed640724 class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16623
diff changeset
  1732
    ^ process.
16623
d6fb73207eca class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16538
diff changeset
  1733
d6fb73207eca class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16538
diff changeset
  1734
    "
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1735
	Processor processWithId:4
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1736
	Processor processWithId:4711
16623
d6fb73207eca class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16538
diff changeset
  1737
    "
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1738
! !
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1739
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1740
!ProcessorScheduler methodsFor:'scheduling'!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1741
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1742
changePriority:prio for:aProcess
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1743
    "change the priority of aProcess"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1744
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1745
    |oldList newList oldPrio newPrio wasBlocked|
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1746
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1747
    oldPrio := aProcess priority.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1748
    oldPrio == prio ifTrue:[^ self].
1042
cc49fd1e3c7e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1032
diff changeset
  1749
    aProcess == scheduler ifTrue:[^ self].
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1750
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1751
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1752
     check for valid argument
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1753
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1754
    newPrio := prio.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1755
    newPrio < 1 ifTrue:[
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1756
	newPrio := 1.
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1757
    ] ifFalse:[
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1758
	newPrio > HighestPriority ifTrue:[
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1759
	    newPrio := HighestPriority
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1760
	]
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1761
    ].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1762
1042
cc49fd1e3c7e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1032
diff changeset
  1763
    [
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1764
	wasBlocked := OperatingSystem blockInterrupts.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1765
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1766
	aProcess setPriority:newPrio.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1767
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1768
	oldList := quiescentProcessLists at:oldPrio.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1769
	oldList notNil ifTrue:[
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1770
	    (oldList removeIdentical:aProcess ifAbsent:nil) notNil ifTrue:[
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1771
		newList := quiescentProcessLists at:newPrio.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1772
		newList isNil ifTrue:[
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1773
		    quiescentProcessLists at:newPrio put:(newList := LinkedList new).
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1774
		].
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1775
		newList addLast:aProcess.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1776
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1777
		"if its the current process lowering its prio
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1778
		 or another one raising, we have to reschedule"
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1779
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1780
		aProcess == activeProcess ifTrue:[
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1781
		    currentPriority := newPrio.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1782
		    newPrio < oldPrio ifTrue:[
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1783
			self threadSwitch:scheduler.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1784
		    ]
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1785
		] ifFalse:[
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1786
		    newPrio > currentPriority ifTrue:[
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1787
			self threadSwitch:aProcess.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1788
		    ]
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1789
		].
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1790
		timeSliceNeededSemaphore notNil ifTrue:[
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1791
		    "/ tell timeslicer, that some work might be needed...
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1792
		    timeSliceNeededSemaphore signalIf.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1793
		]
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1794
	    ]
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1795
	]
6421
58dca33cf0fc #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 6376
diff changeset
  1796
    ] ensure:[
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1797
	wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
1042
cc49fd1e3c7e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1032
diff changeset
  1798
    ]
1032
924c177085f8 care to reenable interrupts
Claus Gittinger <cg@exept.de>
parents: 1001
diff changeset
  1799
3724
49c043d9c0b3 dynamic priorities
Claus Gittinger <cg@exept.de>
parents: 3722
diff changeset
  1800
    "Modified: / 4.8.1998 / 00:08:54 / cg"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1801
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1802
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1803
interruptActive
10747
e9ea71d01445 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10497
diff changeset
  1804
    "interrupt the current process
1783
be7402f74d94 hide timerInterrupt & ioInterrupt contexts when switching
Claus Gittinger <cg@exept.de>
parents: 1780
diff changeset
  1805
     - 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
  1806
     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
  1807
     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
  1808
9991
a03847e11498 make #interruptActive returnable for better debugging
Stefan Vogel <sv@exept.de>
parents: 9452
diff changeset
  1809
    <context: #return>
a03847e11498 make #interruptActive returnable for better debugging
Stefan Vogel <sv@exept.de>
parents: 9452
diff changeset
  1810
1791
9278f0b8a7e1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1787
diff changeset
  1811
    |s|
9278f0b8a7e1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1787
diff changeset
  1812
9278f0b8a7e1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1787
diff changeset
  1813
    "/ hide those intermediate scheduler contexts;
10747
e9ea71d01445 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10497
diff changeset
  1814
    "/ the interrupt block should think it was called right
1791
9278f0b8a7e1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1787
diff changeset
  1815
    "/ from the originally interrupted context
9278f0b8a7e1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1787
diff changeset
  1816
9278f0b8a7e1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1787
diff changeset
  1817
    s := thisContext sender.
9991
a03847e11498 make #interruptActive returnable for better debugging
Stefan Vogel <sv@exept.de>
parents: 9452
diff changeset
  1818
    s selector == #threadSwitchFrom:to:id:singleStep: ifTrue:[
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1819
	s := s sender.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1820
	s selector == #threadSwitch: ifTrue:[
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1821
	    s := s sender.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1822
	    s selector == #timerInterrupt ifTrue:[
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1823
		s := s sender
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1824
	    ]
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1825
	]
1791
9278f0b8a7e1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1787
diff changeset
  1826
    ].
9278f0b8a7e1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1787
diff changeset
  1827
2727
853b7910cff2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2724
diff changeset
  1828
    "/ the returned value here has a subtle effect:
853b7910cff2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2724
diff changeset
  1829
    "/ if false, the interrupt is assumed to be not taken,
853b7910cff2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2724
diff changeset
  1830
    "/ and will be redelivered.
2724
9fb9ea4bf858 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2637
diff changeset
  1831
    ^ activeProcess interruptedIn:s
1783
be7402f74d94 hide timerInterrupt & ioInterrupt contexts when switching
Claus Gittinger <cg@exept.de>
parents: 1780
diff changeset
  1832
1793
537207488596 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1791
diff changeset
  1833
    "Modified: 20.10.1996 / 17:06:48 / cg"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1834
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1835
3273
343ecdba9817 added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents: 3271
diff changeset
  1836
makeRunnable:aProcess
14771
c85f3f394aae class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 14442
diff changeset
  1837
    "set aProcess runnable - but do not reschedule.
c85f3f394aae class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 14442
diff changeset
  1838
     Answer true, if a reschedule is required, false if not."
c85f3f394aae class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 14442
diff changeset
  1839
c85f3f394aae class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 14442
diff changeset
  1840
    |l s pri wasBlocked|
3273
343ecdba9817 added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents: 3271
diff changeset
  1841
343ecdba9817 added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents: 3271
diff changeset
  1842
    "ignore, if process is already dead"
15634
9ace007bd248 class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 15581
diff changeset
  1843
    (aProcess isNil or:[aProcess isDead]) ifTrue:[^ false].
14771
c85f3f394aae class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 14442
diff changeset
  1844
c85f3f394aae class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 14442
diff changeset
  1845
    s := aProcess state.
c85f3f394aae class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 14442
diff changeset
  1846
    s == #osWait ifTrue:[
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1847
	'Processor [warning]: bad resume: #osWait' errorPrintCR.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1848
	"/ MiniDebugger enterWithMessage:'bad resume: state osWait'.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1849
	^ false.
14771
c85f3f394aae class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 14442
diff changeset
  1850
    ].
c85f3f394aae class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 14442
diff changeset
  1851
    s == #stopped ifTrue:[
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1852
	"by definition, stopped processes cannot be resumed"
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1853
	^ false.
14771
c85f3f394aae class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 14442
diff changeset
  1854
    ].
3273
343ecdba9817 added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents: 3271
diff changeset
  1855
343ecdba9817 added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents: 3271
diff changeset
  1856
    aProcess == activeProcess ifTrue:[
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1857
	"special handling for waiting schedulers"
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1858
	aProcess == scheduler ifTrue:[
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1859
	    suspendScheduler := false.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1860
	].
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1861
	^ false
3273
343ecdba9817 added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents: 3271
diff changeset
  1862
    ].
343ecdba9817 added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents: 3271
diff changeset
  1863
343ecdba9817 added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents: 3271
diff changeset
  1864
    wasBlocked := OperatingSystem blockInterrupts.
343ecdba9817 added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents: 3271
diff changeset
  1865
343ecdba9817 added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents: 3271
diff changeset
  1866
    pri := aProcess priority.
343ecdba9817 added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents: 3271
diff changeset
  1867
343ecdba9817 added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents: 3271
diff changeset
  1868
    l := quiescentProcessLists at:pri.
343ecdba9817 added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents: 3271
diff changeset
  1869
    "if already running, ignore"
343ecdba9817 added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents: 3271
diff changeset
  1870
    l notNil ifTrue:[
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1871
	(l identityIndexOf:aProcess) ~~ 0 ifTrue:[
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1872
	    wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1873
	    ^ false
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1874
	]
3273
343ecdba9817 added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents: 3271
diff changeset
  1875
    ] ifFalse:[
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1876
	l := LinkedList new.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1877
	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
  1878
    ].
343ecdba9817 added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents: 3271
diff changeset
  1879
    l addLast:aProcess.
13149
b8fbf6126cc9 changed:
Stefan Vogel <sv@exept.de>
parents: 12981
diff changeset
  1880
    aProcess state:#run.
3273
343ecdba9817 added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents: 3271
diff changeset
  1881
    wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
343ecdba9817 added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents: 3271
diff changeset
  1882
14771
c85f3f394aae class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 14442
diff changeset
  1883
    pri > currentPriority ifTrue:[
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1884
	"must reschedule"
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1885
	^ true.
14771
c85f3f394aae class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 14442
diff changeset
  1886
    ].
11590
f98b955212c2 timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents: 11585
diff changeset
  1887
f98b955212c2 timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents: 11585
diff changeset
  1888
    timeSliceNeededSemaphore notNil ifTrue:[
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1889
	"/ tell timeslicer, that some work might be needed...
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1890
	timeSliceNeededSemaphore signalIf.
14771
c85f3f394aae class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 14442
diff changeset
  1891
    ].
c85f3f394aae class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 14442
diff changeset
  1892
    ^ false.
3273
343ecdba9817 added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents: 3271
diff changeset
  1893
343ecdba9817 added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents: 3271
diff changeset
  1894
    "Modified: / 29.7.1996 / 12:07:37 / cg"
343ecdba9817 added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents: 3271
diff changeset
  1895
    "Created: / 4.2.1998 / 20:58:28 / cg"
343ecdba9817 added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents: 3271
diff changeset
  1896
!
343ecdba9817 added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents: 3271
diff changeset
  1897
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1898
processTermination
10747
e9ea71d01445 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10497
diff changeset
  1899
    "sent by VM if the current process finished its startup block
e9ea71d01445 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10497
diff changeset
  1900
     without proper process termination. Lay him to rest now.
e9ea71d01445 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10497
diff changeset
  1901
     This can only happen, if something went wrong in Block>>newProcess,
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1902
     since the block defined there always terminates itself."
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1903
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1904
    self terminateNoSignal:activeProcess.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1905
    self threadSwitch:scheduler
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1906
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1907
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1908
reschedule
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1909
    "switch to the highest prio runnable process.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1910
     The scheduler itself is always runnable, so we can do an unconditional switch
2622
62acc925dfc5 comment
Claus Gittinger <cg@exept.de>
parents: 2618
diff changeset
  1911
     to that one. This method is provided as a hook for primitive C code,
62acc925dfc5 comment
Claus Gittinger <cg@exept.de>
parents: 2618
diff changeset
  1912
     to allow giving up the CPU."
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1913
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1914
    ^ self threadSwitch:scheduler
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1915
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1916
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1917
resume:aProcess
10747
e9ea71d01445 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10497
diff changeset
  1918
    "set aProcess runnable -
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1919
     if its prio is higher than the currently running prio, switch to it."
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1920
14771
c85f3f394aae class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 14442
diff changeset
  1921
    (self makeRunnable:aProcess) ifTrue:[
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1922
	"aProcess prio is higher; immediately transfer control to it"
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1923
	self threadSwitch:aProcess.
1679
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  1924
    ].
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1925
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1926
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1927
resumeForSingleSend:aProcess
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1928
    "like resume, but let the process execute a single send only.
3271
f9b081667d3e Fix comment.
Stefan Vogel <sv@exept.de>
parents: 3270
diff changeset
  1929
     This will be used by the debugger for single stepping."
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1930
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1931
    (aProcess isNil or:[aProcess == activeProcess]) ifTrue:[^ self].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1932
    aProcess singleStep:true.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1933
    self resume:aProcess
3271
f9b081667d3e Fix comment.
Stefan Vogel <sv@exept.de>
parents: 3270
diff changeset
  1934
f9b081667d3e Fix comment.
Stefan Vogel <sv@exept.de>
parents: 3270
diff changeset
  1935
    "Modified: / 3.2.1998 / 01:08:08 / stefan"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1936
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1937
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1938
suspend:aProcess
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1939
    "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
  1940
     If the process is the current one, reschedule.
2155
0cf80e958130 comment
Claus Gittinger <cg@exept.de>
parents: 2149
diff changeset
  1941
0cf80e958130 comment
Claus Gittinger <cg@exept.de>
parents: 2149
diff changeset
  1942
     Notice:
21009
d4035978c3c7 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20964
diff changeset
  1943
         This method should only be called by Process>>suspend or
d4035978c3c7 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20964
diff changeset
  1944
         Process>>suspendWithState:"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1945
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1946
    |pri l p wasBlocked|
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1947
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1948
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1949
     some debugging stuff
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1950
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1951
    aProcess isNil ifTrue:[
21009
d4035978c3c7 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20964
diff changeset
  1952
        InvalidProcessSignal raiseRequestWith:aProcess errorString:'nil suspend'.
d4035978c3c7 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20964
diff changeset
  1953
        ^ self
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1954
    ].
15658
f886d275e0fc class: ProcessorScheduler
Claus Gittinger <cg@exept.de>
parents: 15657
diff changeset
  1955
    aProcess isDead ifTrue:[
21009
d4035978c3c7 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20964
diff changeset
  1956
        InvalidProcessSignal raiseRequestWith:aProcess errorString:'bad suspend: already dead'.
d4035978c3c7 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20964
diff changeset
  1957
        self threadSwitch:scheduler.
d4035978c3c7 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20964
diff changeset
  1958
        ^ self
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1959
    ].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1960
    aProcess == scheduler ifTrue:[
21009
d4035978c3c7 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20964
diff changeset
  1961
        "only the scheduler may suspend itself"
d4035978c3c7 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20964
diff changeset
  1962
        activeProcess == scheduler ifTrue:[
d4035978c3c7 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20964
diff changeset
  1963
            suspendScheduler := true.
d4035978c3c7 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20964
diff changeset
  1964
            [suspendScheduler] whileTrue:[
d4035978c3c7 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20964
diff changeset
  1965
                self dispatch.
d4035978c3c7 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20964
diff changeset
  1966
            ].
d4035978c3c7 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20964
diff changeset
  1967
            ^ self
d4035978c3c7 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20964
diff changeset
  1968
        ].
d4035978c3c7 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20964
diff changeset
  1969
d4035978c3c7 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20964
diff changeset
  1970
        InvalidProcessSignal raiseRequestWith:aProcess errorString:'attempt to suspend scheduler'.
d4035978c3c7 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20964
diff changeset
  1971
        ^ self
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1972
    ].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1973
21009
d4035978c3c7 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20964
diff changeset
  1974
    (aProcess == activeProcess) ifTrue:[
d4035978c3c7 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20964
diff changeset
  1975
        "this is a no-op if the process has no interrupt actions"
d4035978c3c7 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20964
diff changeset
  1976
        aProcess interrupt.
7863
516fa101129e care for interrupt action before suspending a process
ca
parents: 7848
diff changeset
  1977
    ].
516fa101129e care for interrupt action before suspending a process
ca
parents: 7848
diff changeset
  1978
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1979
    wasBlocked := OperatingSystem blockInterrupts.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1980
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1981
    pri := aProcess priority.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1982
    l := quiescentProcessLists at:pri.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1983
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1984
    "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
  1985
     the ifAbsent block, because [] is a shared cheap block, created at compile time
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1986
    "
13164
b09c736a2e9b changed:
Stefan Vogel <sv@exept.de>
parents: 13149
diff changeset
  1987
    (l isNil or:[(l removeIdentical:aProcess ifAbsent:nil) isNil]) ifTrue:[
21009
d4035978c3c7 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20964
diff changeset
  1988
        "/ 'Processor [warning]: bad suspend: process is not running' errorPrintCR.
d4035978c3c7 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20964
diff changeset
  1989
        "/ MiniDebugger enterWithMessage:'bad suspend: process is not running'.
d4035978c3c7 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20964
diff changeset
  1990
        aProcess == activeProcess ifTrue:[
d4035978c3c7 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20964
diff changeset
  1991
            self threadSwitch:scheduler.
d4035978c3c7 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20964
diff changeset
  1992
        ].
d4035978c3c7 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20964
diff changeset
  1993
        wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
d4035978c3c7 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20964
diff changeset
  1994
        ^ self
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1995
    ].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1996
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1997
    (aProcess == activeProcess) ifTrue:[
21009
d4035978c3c7 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20964
diff changeset
  1998
        "we can immediately switch sometimes"
d4035978c3c7 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20964
diff changeset
  1999
        l isEmpty ifTrue:[
d4035978c3c7 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20964
diff changeset
  2000
            p := scheduler
d4035978c3c7 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20964
diff changeset
  2001
        ] ifFalse:[
d4035978c3c7 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20964
diff changeset
  2002
            p := l firstLink
d4035978c3c7 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20964
diff changeset
  2003
        ].
d4035978c3c7 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20964
diff changeset
  2004
        self threadSwitch:p
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2005
    ].
752
0259dd855289 new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents: 750
diff changeset
  2006
3745
3fd121f2e74e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3740
diff changeset
  2007
    wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
3fd121f2e74e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3740
diff changeset
  2008
3680
9dfecf84ff93 no need for threadSwitch in bad suspend.
Claus Gittinger <cg@exept.de>
parents: 3650
diff changeset
  2009
    "Modified: / 23.9.1996 / 13:49:24 / stefan"
9dfecf84ff93 no need for threadSwitch in bad suspend.
Claus Gittinger <cg@exept.de>
parents: 3650
diff changeset
  2010
    "Modified: / 27.7.1998 / 23:34:59 / cg"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2011
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2012
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2013
terminate:aProcess
20055
04ca6d9e3268 #DOCUMENTATION by mawalch
mawalch
parents: 20054
diff changeset
  2014
    "terminate aProcess. This is done by sending aProcess the terminateSignal,
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2015
     which will evaluate any unwind blocks and finally do a hard terminate."
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2016
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2017
    aProcess terminate
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2018
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2019
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2020
terminateActive
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2021
    "terminate the current process (i.e. the running process kills itself).
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2022
     The active process is sent the terminateSignal so it will evaluate any
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2023
     unwind blocks and finally do a hard terminate.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2024
     This is sent for regular termination and by the VM, if the hard-stack limit
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2025
     is reached. (i.e. a process did not repair things in a recursionInterrupt and
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2026
     continued to grow its stack)"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2027
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2028
    activeProcess terminate
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2029
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2030
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2031
terminateActiveNoSignal
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2032
    "hard terminate the active process, without sending any
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2033
     terminate signal thus no unwind blocks are evaluated."
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2034
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2035
    self terminateNoSignal:activeProcess
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2036
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2037
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2038
terminateNoSignal:aProcess
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2039
    "hard terminate aProcess without sending the terminate signal, thus
10747
e9ea71d01445 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10497
diff changeset
  2040
     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
  2041
     If it's not the current process, it is simply removed from its list
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2042
     and physically destroyed. Otherwise (since we can't take away the chair
10747
e9ea71d01445 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10497
diff changeset
  2043
     we are sitting on), a switch is forced and the process
e9ea71d01445 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10497
diff changeset
  2044
     will be physically destroyed by the next running process.
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2045
     (see zombie handling)"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2046
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2047
    |pri id l wasBlocked|
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2048
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2049
    aProcess isNil ifTrue:[^ self].
20723
510279fb2401 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20722
diff changeset
  2050
807
e51ce11ca948 and dont allow quickTerminate as well.
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
  2051
    aProcess == scheduler ifTrue:[
20722
0eeb9a61979f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20713
diff changeset
  2052
        InvalidProcessSignal raiseWith:aProcess errorString:'attempt to terminate scheduler'.
0eeb9a61979f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20713
diff changeset
  2053
        ^ self
807
e51ce11ca948 and dont allow quickTerminate as well.
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
  2054
    ].
e51ce11ca948 and dont allow quickTerminate as well.
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
  2055
6990
a6bda971619f race with threadDestroy (leftOver process-structures in VM);
ca
parents: 6940
diff changeset
  2056
    wasBlocked := OperatingSystem blockInterrupts.
a6bda971619f race with threadDestroy (leftOver process-structures in VM);
ca
parents: 6940
diff changeset
  2057
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2058
    id := aProcess id.
6990
a6bda971619f race with threadDestroy (leftOver process-structures in VM);
ca
parents: 6940
diff changeset
  2059
    id isNil ifTrue:[   "already dead"
20736
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  2060
        self checkForEndOfDispatch.
20722
0eeb9a61979f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20713
diff changeset
  2061
        wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
0eeb9a61979f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20713
diff changeset
  2062
        ^ self
10747
e9ea71d01445 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10497
diff changeset
  2063
    ].
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2064
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2065
    aProcess setId:nil state:#dead.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2066
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2067
    "remove the process from the runnable list"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2068
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2069
    pri := aProcess priority.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2070
    l := quiescentProcessLists at:pri.
5840
430a17e002c4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5702
diff changeset
  2071
    l notNil ifTrue:[
20722
0eeb9a61979f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20713
diff changeset
  2072
        (l removeIdentical:aProcess ifAbsent:nil) "notNil ifTrue:[
0eeb9a61979f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20713
diff changeset
  2073
            l isEmpty ifTrue:[
0eeb9a61979f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20713
diff changeset
  2074
                quiescentProcessLists at:pri put:nil
0eeb9a61979f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20713
diff changeset
  2075
            ]
0eeb9a61979f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20713
diff changeset
  2076
        ]."
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2077
    ].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2078
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2079
    aProcess == activeProcess ifTrue:[
20722
0eeb9a61979f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20713
diff changeset
  2080
        "
0eeb9a61979f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20713
diff changeset
  2081
         hard case - it's the currently running process
0eeb9a61979f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20713
diff changeset
  2082
         we must have the next active process destroy this one
0eeb9a61979f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20713
diff changeset
  2083
         (we cannot destroy the chair we are sitting on ... :-)
0eeb9a61979f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20713
diff changeset
  2084
        "
0eeb9a61979f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20713
diff changeset
  2085
        zombie notNil ifTrue:[
0eeb9a61979f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20713
diff changeset
  2086
            self error:'active process is zombie' mayProceed:true.
0eeb9a61979f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20713
diff changeset
  2087
            self class threadDestroy:zombie.
0eeb9a61979f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20713
diff changeset
  2088
        ].
0eeb9a61979f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20713
diff changeset
  2089
0eeb9a61979f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20713
diff changeset
  2090
        self unRemember:aProcess.
0eeb9a61979f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20713
diff changeset
  2091
        zombie := id.
0eeb9a61979f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20713
diff changeset
  2092
20736
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  2093
        self checkForEndOfDispatch.
20722
0eeb9a61979f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20713
diff changeset
  2094
        wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
0eeb9a61979f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20713
diff changeset
  2095
        self threadSwitch:scheduler.
0eeb9a61979f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20713
diff changeset
  2096
        "not reached"
0eeb9a61979f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20713
diff changeset
  2097
        ^ self
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2098
    ].
6990
a6bda971619f race with threadDestroy (leftOver process-structures in VM);
ca
parents: 6940
diff changeset
  2099
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2100
    self unRemember:aProcess.
6990
a6bda971619f race with threadDestroy (leftOver process-structures in VM);
ca
parents: 6940
diff changeset
  2101
    self class threadDestroy:id.
a6bda971619f race with threadDestroy (leftOver process-structures in VM);
ca
parents: 6940
diff changeset
  2102
20736
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  2103
    self checkForEndOfDispatch.
6990
a6bda971619f race with threadDestroy (leftOver process-structures in VM);
ca
parents: 6940
diff changeset
  2104
    wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
1618
9fb4ee952e89 use nil for empty lists
Claus Gittinger <cg@exept.de>
parents: 1606
diff changeset
  2105
13577
5caa91ac2963 comment/format in: #terminateNoSignal:
Claus Gittinger <cg@exept.de>
parents: 13556
diff changeset
  2106
    "Modified: / 23-09-1996 / 13:50:24 / stefan"
5caa91ac2963 comment/format in: #terminateNoSignal:
Claus Gittinger <cg@exept.de>
parents: 13556
diff changeset
  2107
    "Modified: / 20-03-1997 / 16:03:39 / cg"
5caa91ac2963 comment/format in: #terminateNoSignal:
Claus Gittinger <cg@exept.de>
parents: 13556
diff changeset
  2108
    "Modified (comment): / 10-08-2011 / 19:57:08 / cg"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2109
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2110
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2111
yield
17271
47341245c458 class: ProcessorScheduler
Claus Gittinger <cg@exept.de>
parents: 16858
diff changeset
  2112
    "move the currently running process to the end of the current list
10747
e9ea71d01445 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10497
diff changeset
  2113
     and reschedule to the first in the list, thus switching to the
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2114
     next same-prio-process."
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2115
1618
9fb4ee952e89 use nil for empty lists
Claus Gittinger <cg@exept.de>
parents: 1606
diff changeset
  2116
    |l sz wasBlocked|
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2117
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2118
    wasBlocked := OperatingSystem blockInterrupts.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2119
12981
454712945c0b changed: #yield
Claus Gittinger <cg@exept.de>
parents: 12958
diff changeset
  2120
    activeProcess == scheduler ifTrue:[
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2121
	'Processor [warning]: scheduler tries to yield' errorPrintCR.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2122
	^ self
12981
454712945c0b changed: #yield
Claus Gittinger <cg@exept.de>
parents: 12958
diff changeset
  2123
    ].
454712945c0b changed: #yield
Claus Gittinger <cg@exept.de>
parents: 12958
diff changeset
  2124
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2125
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2126
     debugging consistency check - will be removed later
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2127
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2128
    activeProcess priority ~~ currentPriority ifTrue:[
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2129
	'Processor [warning]: process changed its priority' errorPrintCR.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2130
	currentPriority := activeProcess priority.
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2131
    ].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2132
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2133
    l := quiescentProcessLists at:currentPriority.
1618
9fb4ee952e89 use nil for empty lists
Claus Gittinger <cg@exept.de>
parents: 1606
diff changeset
  2134
    sz := l size.
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2135
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2136
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2137
     debugging consistency checks - will be removed later
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2138
    "
1618
9fb4ee952e89 use nil for empty lists
Claus Gittinger <cg@exept.de>
parents: 1606
diff changeset
  2139
    sz == 0 ifTrue:[
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2140
	wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2141
	'Processor [warning]: empty runnable list' errorPrintCR.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2142
	^ self
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2143
    ].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2144
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2145
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2146
     check if the running process is not the only one
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2147
    "
1618
9fb4ee952e89 use nil for empty lists
Claus Gittinger <cg@exept.de>
parents: 1606
diff changeset
  2148
    sz ~~ 1 ifTrue:[
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2149
	"
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2150
	 bring running process to the end
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2151
	"
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2152
	l removeFirst.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2153
	l addLast:activeProcess.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2154
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2155
	"
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2156
	 and switch to first in the list
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2157
	"
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2158
	self threadSwitch:(l firstLink).
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2159
    ].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2160
    wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
1086
7b0641a2e1ef nicer message
Claus Gittinger <cg@exept.de>
parents: 1061
diff changeset
  2161
12981
454712945c0b changed: #yield
Claus Gittinger <cg@exept.de>
parents: 12958
diff changeset
  2162
    "Modified: / 02-08-2010 / 13:36:25 / cg"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2163
! !
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2164
7264
cf619b9f31b6 method category rename
Claus Gittinger <cg@exept.de>
parents: 7097
diff changeset
  2165
!ProcessorScheduler methodsFor:'scheduling-preemptive'!
2188
3814c1d74d2b integrated the timeSlicer
Claus Gittinger <cg@exept.de>
parents: 2155
diff changeset
  2166
3722
1114c2014bea added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents: 3718
diff changeset
  2167
recomputeDynamicPriorities
1114c2014bea added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents: 3718
diff changeset
  2168
    "recompute dynamic priorities."
1114c2014bea added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents: 3718
diff changeset
  2169
15402
a40ba0a33cab class: ProcessorScheduler
Claus Gittinger <cg@exept.de>
parents: 15118
diff changeset
  2170
    |processesToDecrease processesToIncrease|
3728
970b2b4c9118 try to avoid object allocations in timeSlicers #recomputeDynamicPriorities.
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
  2171
970b2b4c9118 try to avoid object allocations in timeSlicers #recomputeDynamicPriorities.
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
  2172
    scheduledProcesses notNil ifTrue:[
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2173
	"/ this is written a bit cryptic - to avoid creation
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2174
	"/ of garbage objects (Id'sets) if possible.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2175
	"/ since this runs 50 times a second and most of the
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2176
	"/ time, no rescheduling is req'd
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2177
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2178
	scheduledProcesses do:[:aProcess |
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2179
	    |range|
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2180
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2181
	    "/ decrease priority of processes that did run
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2182
	    (range := aProcess priorityRange) notNil ifTrue:[
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2183
		aProcess priority > range start ifTrue:[
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2184
		    processesToDecrease isNil ifTrue:[
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2185
			processesToDecrease := IdentitySet new.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2186
		    ].
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2187
		    processesToDecrease add:aProcess.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2188
		]
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2189
	    ]
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2190
	].
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2191
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2192
	processesToDecrease notNil ifTrue:[
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2193
	    processesToDecrease do:[:aProcess |
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2194
		|newPri|
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2195
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2196
		"/ newPri := aProcess priority - 1.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2197
		newPri := aProcess priorityRange start.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2198
		self changePriority:newPri for:aProcess.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2199
	    ].
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2200
	].
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2201
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2202
	"/ and increase all prios of those that did not run, but are runnable
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2203
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2204
	TimeSlicingPriorityLimit to:1 by:-1 do:[:i |
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2205
	    |list|
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2206
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2207
	    (list := quiescentProcessLists at:i) size > 0 ifTrue:[
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2208
		list linksDo:[:aProcess |
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2209
		    |range prio|
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2210
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2211
		    (range := aProcess priorityRange) notNil ifTrue:[
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2212
			(processesToDecrease isNil
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2213
			or:[(processesToDecrease includes:aProcess) not]) ifTrue:[
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2214
			    aProcess priority < range stop ifTrue:[
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2215
				processesToIncrease isNil ifTrue:[
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2216
				    processesToIncrease := OrderedCollection new.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2217
				].
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2218
				processesToIncrease add:aProcess
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2219
			    ]
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2220
			]
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2221
		    ]
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2222
		]
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2223
	    ]
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2224
	].
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2225
	processesToIncrease notNil ifTrue:[
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2226
	    processesToIncrease do:[:aProcess |
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2227
		self changePriority:(aProcess priority + 1) for:aProcess.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2228
	    ].
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2229
	].
3722
1114c2014bea added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents: 3718
diff changeset
  2230
    ].
1114c2014bea added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents: 3718
diff changeset
  2231
15581
6332a960dbcd class: ProcessorScheduler
Claus Gittinger <cg@exept.de>
parents: 15510
diff changeset
  2232
    "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
  2233
!
629791828694 also keep track of scheduler processes, if
Claus Gittinger <cg@exept.de>
parents: 3787
diff changeset
  2234
629791828694 also keep track of scheduler processes, if
Claus Gittinger <cg@exept.de>
parents: 3787
diff changeset
  2235
scheduledProcesses
629791828694 also keep track of scheduler processes, if
Claus Gittinger <cg@exept.de>
parents: 3787
diff changeset
  2236
    "return a collection of recently scheduled processes.
629791828694 also keep track of scheduler processes, if
Claus Gittinger <cg@exept.de>
parents: 3787
diff changeset
  2237
     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
  2238
     scheduler is running"
629791828694 also keep track of scheduler processes, if
Claus Gittinger <cg@exept.de>
parents: 3787
diff changeset
  2239
629791828694 also keep track of scheduler processes, if
Claus Gittinger <cg@exept.de>
parents: 3787
diff changeset
  2240
    ^ scheduledProcesses ? #()
629791828694 also keep track of scheduler processes, if
Claus Gittinger <cg@exept.de>
parents: 3787
diff changeset
  2241
629791828694 also keep track of scheduler processes, if
Claus Gittinger <cg@exept.de>
parents: 3787
diff changeset
  2242
    "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
  2243
    "Modified: / 27.8.1998 / 12:56:35 / cg"
3722
1114c2014bea added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents: 3718
diff changeset
  2244
!
1114c2014bea added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents: 3718
diff changeset
  2245
2188
3814c1d74d2b integrated the timeSlicer
Claus Gittinger <cg@exept.de>
parents: 2155
diff changeset
  2246
slice
3814c1d74d2b integrated the timeSlicer
Claus Gittinger <cg@exept.de>
parents: 2155
diff changeset
  2247
    "Give other Processes at the current priority a chance to run."
3814c1d74d2b integrated the timeSlicer
Claus Gittinger <cg@exept.de>
parents: 2155
diff changeset
  2248
3814c1d74d2b integrated the timeSlicer
Claus Gittinger <cg@exept.de>
parents: 2155
diff changeset
  2249
    |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
  2250
     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
  2251
f98b955212c2 timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents: 11585
diff changeset
  2252
    anyShuffle := false.
3745
3fd121f2e74e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3740
diff changeset
  2253
    wasBlocked := OperatingSystem blockInterrupts.
2188
3814c1d74d2b integrated the timeSlicer
Claus Gittinger <cg@exept.de>
parents: 2155
diff changeset
  2254
2190
8afa4709d8a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2188
diff changeset
  2255
    i := TimeSlicingPriorityLimit.
2333
776bb9cb7b27 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2292
diff changeset
  2256
    [(i > 0) and:[(list := quiescentProcessLists at:i) size <= 1]] whileTrue: [i := i - 1].
3745
3fd121f2e74e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3740
diff changeset
  2257
    i ~~ 0 ifTrue: [
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2258
	"/ shuffle that list
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2259
	list addLast:(list removeFirst).
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2260
	anyShuffle := true.
3745
3fd121f2e74e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3740
diff changeset
  2261
    ].
3fd121f2e74e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3740
diff changeset
  2262
    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
  2263
    anyShuffle ifFalse:[
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2264
	"/ wait for the scheduler to make some process runnable...
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2265
	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
  2266
    ].
2188
3814c1d74d2b integrated the timeSlicer
Claus Gittinger <cg@exept.de>
parents: 2155
diff changeset
  2267
3724
49c043d9c0b3 dynamic priorities
Claus Gittinger <cg@exept.de>
parents: 3722
diff changeset
  2268
    "Modified: / 4.8.1998 / 00:13:32 / cg"
2188
3814c1d74d2b integrated the timeSlicer
Claus Gittinger <cg@exept.de>
parents: 2155
diff changeset
  2269
!
3814c1d74d2b integrated the timeSlicer
Claus Gittinger <cg@exept.de>
parents: 2155
diff changeset
  2270
3814c1d74d2b integrated the timeSlicer
Claus Gittinger <cg@exept.de>
parents: 2155
diff changeset
  2271
startTimeSlicing
2190
8afa4709d8a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2188
diff changeset
  2272
    "start preemptive scheduling (timeSlicing)"
8afa4709d8a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2188
diff changeset
  2273
8afa4709d8a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2188
diff changeset
  2274
    timeSliceProcess notNil ifTrue: [^ self].
8afa4709d8a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2188
diff changeset
  2275
14775
fa2e7d4afdef class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 14771
diff changeset
  2276
    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
  2277
2188
3814c1d74d2b integrated the timeSlicer
Claus Gittinger <cg@exept.de>
parents: 2155
diff changeset
  2278
    timeSliceProcess := [
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2279
	[
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2280
	    self timeSlicingLoop.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2281
	] ifCurtailed:[
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2282
	    timeSliceProcess := nil.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2283
	    'Processor [info]: timeslicer finished' infoPrintCR.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2284
	]
2188
3814c1d74d2b integrated the timeSlicer
Claus Gittinger <cg@exept.de>
parents: 2155
diff changeset
  2285
    ] newProcess.
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2286
    timeSliceProcess
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2287
	priority:HighestPriority;
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2288
	name:'time slicer';
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2289
	restartable:true;
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2290
	beSystemProcess;
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2291
	resume.
2188
3814c1d74d2b integrated the timeSlicer
Claus Gittinger <cg@exept.de>
parents: 2155
diff changeset
  2292
3814c1d74d2b integrated the timeSlicer
Claus Gittinger <cg@exept.de>
parents: 2155
diff changeset
  2293
    "
2258
8894d33af5f6 reuse delays
Claus Gittinger <cg@exept.de>
parents: 2198
diff changeset
  2294
     Processor stopTimeSlicing.
8894d33af5f6 reuse delays
Claus Gittinger <cg@exept.de>
parents: 2198
diff changeset
  2295
     Processor startTimeSlicing.
2188
3814c1d74d2b integrated the timeSlicer
Claus Gittinger <cg@exept.de>
parents: 2155
diff changeset
  2296
    "
3814c1d74d2b integrated the timeSlicer
Claus Gittinger <cg@exept.de>
parents: 2155
diff changeset
  2297
13813
1194409a73dd changed: #startTimeSlicing
Claus Gittinger <cg@exept.de>
parents: 13577
diff changeset
  2298
    "Created: / 17-01-1997 / 16:42:02 / cg"
1194409a73dd changed: #startTimeSlicing
Claus Gittinger <cg@exept.de>
parents: 13577
diff changeset
  2299
    "Modified: / 03-11-2011 / 21:21:10 / cg"
2188
3814c1d74d2b integrated the timeSlicer
Claus Gittinger <cg@exept.de>
parents: 2155
diff changeset
  2300
!
3814c1d74d2b integrated the timeSlicer
Claus Gittinger <cg@exept.de>
parents: 2155
diff changeset
  2301
3814c1d74d2b integrated the timeSlicer
Claus Gittinger <cg@exept.de>
parents: 2155
diff changeset
  2302
stopTimeSlicing
2190
8afa4709d8a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2188
diff changeset
  2303
    "stop preemptive scheduling (timeSlicing)"
2188
3814c1d74d2b integrated the timeSlicer
Claus Gittinger <cg@exept.de>
parents: 2155
diff changeset
  2304
3814c1d74d2b integrated the timeSlicer
Claus Gittinger <cg@exept.de>
parents: 2155
diff changeset
  2305
    timeSliceProcess notNil ifTrue: [
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2306
	timeSliceProcess terminate.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2307
	timeSliceProcess := nil.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2308
	scheduledProcesses := nil.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2309
	timeSliceNeededSemaphore := nil.
2188
3814c1d74d2b integrated the timeSlicer
Claus Gittinger <cg@exept.de>
parents: 2155
diff changeset
  2310
    ]
3814c1d74d2b integrated the timeSlicer
Claus Gittinger <cg@exept.de>
parents: 2155
diff changeset
  2311
3814c1d74d2b integrated the timeSlicer
Claus Gittinger <cg@exept.de>
parents: 2155
diff changeset
  2312
    "
3814c1d74d2b integrated the timeSlicer
Claus Gittinger <cg@exept.de>
parents: 2155
diff changeset
  2313
     Processor stopTimeSlicing
3814c1d74d2b integrated the timeSlicer
Claus Gittinger <cg@exept.de>
parents: 2155
diff changeset
  2314
    "
3814c1d74d2b integrated the timeSlicer
Claus Gittinger <cg@exept.de>
parents: 2155
diff changeset
  2315
3790
629791828694 also keep track of scheduler processes, if
Claus Gittinger <cg@exept.de>
parents: 3787
diff changeset
  2316
    "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
  2317
    "Modified: / 27.8.1998 / 13:00:37 / cg"
3722
1114c2014bea added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents: 3718
diff changeset
  2318
!
1114c2014bea added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents: 3718
diff changeset
  2319
1114c2014bea added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents: 3718
diff changeset
  2320
supportDynamicPriorities
1114c2014bea added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents: 3718
diff changeset
  2321
    "return true, if dynamic priorities are enabled"
1114c2014bea added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents: 3718
diff changeset
  2322
1114c2014bea added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents: 3718
diff changeset
  2323
    ^ supportDynamicPriorities
1114c2014bea added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents: 3718
diff changeset
  2324
1114c2014bea added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents: 3718
diff changeset
  2325
    "Created: / 3.8.1998 / 22:05:15 / cg"
1114c2014bea added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents: 3718
diff changeset
  2326
    "Modified: / 3.8.1998 / 22:55:08 / cg"
1114c2014bea added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents: 3718
diff changeset
  2327
!
1114c2014bea added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents: 3718
diff changeset
  2328
1114c2014bea added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents: 3718
diff changeset
  2329
supportDynamicPriorities:aBoolean
1114c2014bea added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents: 3718
diff changeset
  2330
    "enable/disable dynamic priorities"
1114c2014bea added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents: 3718
diff changeset
  2331
1114c2014bea added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents: 3718
diff changeset
  2332
    supportDynamicPriorities := aBoolean.
1114c2014bea added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents: 3718
diff changeset
  2333
1114c2014bea added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents: 3718
diff changeset
  2334
    "
1114c2014bea added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents: 3718
diff changeset
  2335
     Processor supportDynamicPriorities:true
1114c2014bea added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents: 3718
diff changeset
  2336
     Processor supportDynamicPriorities:false
1114c2014bea added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents: 3718
diff changeset
  2337
    "
1114c2014bea added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents: 3718
diff changeset
  2338
1114c2014bea added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents: 3718
diff changeset
  2339
    "Modified: / 3.8.1998 / 22:54:52 / cg"
15687
7679c998f5ac class: ProcessorScheduler
Claus Gittinger <cg@exept.de>
parents: 15658
diff changeset
  2340
!
7679c998f5ac class: ProcessorScheduler
Claus Gittinger <cg@exept.de>
parents: 15658
diff changeset
  2341
7679c998f5ac class: ProcessorScheduler
Claus Gittinger <cg@exept.de>
parents: 15658
diff changeset
  2342
timeSlicingLoop
7679c998f5ac class: ProcessorScheduler
Claus Gittinger <cg@exept.de>
parents: 15658
diff changeset
  2343
    |myDelay t flipFlop|
7679c998f5ac class: ProcessorScheduler
Claus Gittinger <cg@exept.de>
parents: 15658
diff changeset
  2344
7679c998f5ac class: ProcessorScheduler
Claus Gittinger <cg@exept.de>
parents: 15658
diff changeset
  2345
    myDelay := Delay forMilliseconds:(t := TimeSliceInterval).
7679c998f5ac class: ProcessorScheduler
Claus Gittinger <cg@exept.de>
parents: 15658
diff changeset
  2346
    flipFlop := true.
7679c998f5ac class: ProcessorScheduler
Claus Gittinger <cg@exept.de>
parents: 15658
diff changeset
  2347
20713
59384e8fa3f7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20706
diff changeset
  2348
    Smalltalk verbose ifTrue:[ 'Processor [info]: timeslicer started' infoPrintCR ].
17412
ef9b82b8ce77 class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 17341
diff changeset
  2349
    [
20713
59384e8fa3f7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20706
diff changeset
  2350
        t ~~ TimeSliceInterval ifTrue:[
59384e8fa3f7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20706
diff changeset
  2351
            "/ interval changed -> need a new delay
59384e8fa3f7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20706
diff changeset
  2352
            myDelay delay:(t := TimeSliceInterval).
59384e8fa3f7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20706
diff changeset
  2353
        ].
59384e8fa3f7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20706
diff changeset
  2354
        myDelay wait.
59384e8fa3f7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20706
diff changeset
  2355
        self slice.
59384e8fa3f7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20706
diff changeset
  2356
59384e8fa3f7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20706
diff changeset
  2357
        "/ every other tick, recompute priorities.
59384e8fa3f7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20706
diff changeset
  2358
        flipFlop := flipFlop not.
59384e8fa3f7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20706
diff changeset
  2359
        flipFlop ifTrue:[
59384e8fa3f7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20706
diff changeset
  2360
            scheduledProcesses notNil ifTrue:[
59384e8fa3f7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20706
diff changeset
  2361
                supportDynamicPriorities ifTrue:[
59384e8fa3f7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20706
diff changeset
  2362
                    self recomputeDynamicPriorities.
59384e8fa3f7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20706
diff changeset
  2363
                ].
59384e8fa3f7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20706
diff changeset
  2364
                scheduledProcesses clearContents.
59384e8fa3f7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20706
diff changeset
  2365
            ] ifFalse:[
59384e8fa3f7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20706
diff changeset
  2366
                scheduledProcesses := IdentitySet new.
59384e8fa3f7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20706
diff changeset
  2367
            ].
59384e8fa3f7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20706
diff changeset
  2368
        ].
17412
ef9b82b8ce77 class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 17341
diff changeset
  2369
    ] loop.
2188
3814c1d74d2b integrated the timeSlicer
Claus Gittinger <cg@exept.de>
parents: 2155
diff changeset
  2370
! !
3814c1d74d2b integrated the timeSlicer
Claus Gittinger <cg@exept.de>
parents: 2155
diff changeset
  2371
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2372
!ProcessorScheduler methodsFor:'semaphore signalling'!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2373
19063
35bf380262d6 #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 19007
diff changeset
  2374
disableFd:aFileDescriptor doSignal:doSignal
35bf380262d6 #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 19007
diff changeset
  2375
    "disable triggering of a semaphore for aFileDescriptor..
20643
cdc2a4259d4d #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20612
diff changeset
  2376
     If doSignal is true, the associated semaphore is signaled.
cdc2a4259d4d #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20612
diff changeset
  2377
     Answer a collection of semaphores that haven't been signaled."
19063
35bf380262d6 #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 19007
diff changeset
  2378
35bf380262d6 #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 19007
diff changeset
  2379
    |idx "{ Class: SmallInteger }"
20643
cdc2a4259d4d #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20612
diff changeset
  2380
     wasBlocked sema semaCollection|
19063
35bf380262d6 #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 19007
diff changeset
  2381
35bf380262d6 #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 19007
diff changeset
  2382
    wasBlocked := OperatingSystem blockInterrupts.
35bf380262d6 #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 19007
diff changeset
  2383
    useIOInterrupts ifTrue:[
20706
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  2384
	OperatingSystem disableIOInterruptsOn:aFileDescriptor.
19063
35bf380262d6 #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 19007
diff changeset
  2385
    ].
35bf380262d6 #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 19007
diff changeset
  2386
20643
cdc2a4259d4d #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20612
diff changeset
  2387
    idx := readFdArray indexOf:aFileDescriptor startingAt:1.
19063
35bf380262d6 #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 19007
diff changeset
  2388
    [idx ~~ 0] whileTrue:[
20706
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  2389
	readFdArray at:idx put:nil.
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  2390
	readCheckArray at:idx put:nil.
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  2391
	(sema := readSemaphoreArray at:idx) notNil ifTrue:[
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  2392
	    readSemaphoreArray at:idx put:nil.
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  2393
	    semaCollection isNil ifTrue:[semaCollection := Set new].
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  2394
	    semaCollection add:sema.
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  2395
	].
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  2396
	idx := readFdArray indexOf:aFileDescriptor startingAt:idx+1.
19063
35bf380262d6 #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 19007
diff changeset
  2397
    ].
20643
cdc2a4259d4d #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20612
diff changeset
  2398
    idx := writeFdArray indexOf:aFileDescriptor startingAt:1.
19063
35bf380262d6 #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 19007
diff changeset
  2399
    [idx ~~ 0] whileTrue:[
20706
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  2400
	writeFdArray at:idx put:nil.
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  2401
	writeCheckArray at:idx put:nil.
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  2402
	(sema := writeSemaphoreArray at:idx) notNil ifTrue:[
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  2403
	    writeSemaphoreArray at:idx put:nil.
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  2404
	    semaCollection isNil ifTrue:[semaCollection := Set new].
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  2405
	    semaCollection add:sema.
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  2406
	].
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  2407
	idx := writeFdArray indexOf:aFileDescriptor startingAt:idx+1.
19063
35bf380262d6 #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 19007
diff changeset
  2408
    ].
20643
cdc2a4259d4d #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20612
diff changeset
  2409
    idx := exceptFdArray indexOf:aFileDescriptor startingAt:1.
19063
35bf380262d6 #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 19007
diff changeset
  2410
    [idx ~~ 0] whileTrue:[
20706
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  2411
	exceptFdArray at:idx put:nil.
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  2412
	(sema := exceptSemaphoreArray at:idx) notNil ifTrue:[
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  2413
	    exceptSemaphoreArray at:idx put:nil.
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  2414
	    semaCollection isNil ifTrue:[semaCollection := Set new].
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  2415
	    semaCollection add:sema.
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  2416
	].
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  2417
	idx := exceptFdArray indexOf:aFileDescriptor startingAt:idx+1.
20643
cdc2a4259d4d #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20612
diff changeset
  2418
    ].
cdc2a4259d4d #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20612
diff changeset
  2419
cdc2a4259d4d #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20612
diff changeset
  2420
    semaCollection isNil ifTrue:[
20706
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  2421
	semaCollection := #().
20643
cdc2a4259d4d #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20612
diff changeset
  2422
    ] ifFalse:[
20706
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  2423
	doSignal ifTrue:[
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  2424
	    semaCollection do:[:eachSema|
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  2425
		eachSema signalForAll.
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  2426
		semaCollection := #().
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  2427
	    ].
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  2428
	].
19063
35bf380262d6 #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 19007
diff changeset
  2429
    ].
35bf380262d6 #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 19007
diff changeset
  2430
    wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
20643
cdc2a4259d4d #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20612
diff changeset
  2431
    ^ semaCollection
19063
35bf380262d6 #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 19007
diff changeset
  2432
!
35bf380262d6 #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 19007
diff changeset
  2433
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2434
disableSemaphore:aSemaphore
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2435
    "disable triggering of a semaphore"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2436
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2437
    |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
  2438
     wasBlocked fd|
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2439
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2440
    wasBlocked := OperatingSystem blockInterrupts.
20052
4bd27ae52593 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19859
diff changeset
  2441
    idx := 0.
4bd27ae52593 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19859
diff changeset
  2442
    [idx := readSemaphoreArray identityIndexOf:aSemaphore startingAt:idx+1.
4bd27ae52593 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19859
diff changeset
  2443
     idx ~~ 0] whileTrue:[
20706
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  2444
	useIOInterrupts ifTrue:[
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  2445
	    fd := readFdArray at:idx.
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  2446
	    fd notNil ifTrue:[
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  2447
		OperatingSystem disableIOInterruptsOn:fd
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  2448
	    ].
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  2449
	].
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  2450
	readFdArray at:idx put:nil.
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  2451
	readSemaphoreArray at:idx put:nil.
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  2452
	readCheckArray at:idx put:nil.
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2453
    ].
20052
4bd27ae52593 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19859
diff changeset
  2454
    idx := 0.
4bd27ae52593 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19859
diff changeset
  2455
    [idx := writeSemaphoreArray identityIndexOf:aSemaphore startingAt:idx+1.
4bd27ae52593 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19859
diff changeset
  2456
     idx ~~ 0] whileTrue:[
20706
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  2457
	useIOInterrupts ifTrue:[
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  2458
	    fd := writeFdArray at:idx.
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  2459
	    fd notNil ifTrue:[
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  2460
		OperatingSystem disableIOInterruptsOn:fd
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  2461
	    ].
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  2462
	].
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  2463
	writeFdArray at:idx put:nil.
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  2464
	writeSemaphoreArray at:idx put:nil.
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  2465
	writeCheckArray at:idx put:nil.
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2466
    ].
20052
4bd27ae52593 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19859
diff changeset
  2467
    idx := 0.
4bd27ae52593 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19859
diff changeset
  2468
    [idx := exceptSemaphoreArray identityIndexOf:aSemaphore startingAt:idx+1.
4bd27ae52593 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19859
diff changeset
  2469
     idx ~~ 0] whileTrue:[
20706
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  2470
	exceptFdArray at:idx put:nil.
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  2471
	exceptSemaphoreArray at:idx put:nil.
18957
e0bb91eae748 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18941
diff changeset
  2472
    ].
20052
4bd27ae52593 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19859
diff changeset
  2473
    self removeTimeoutForSemaphore:aSemaphore.
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2474
    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
  2475
02f9aa61f71b ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
  2476
    "Modified: 4.8.1997 / 15:19:33 / cg"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2477
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2478
1683
f7fed00976ab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1681
diff changeset
  2479
signal:aSemaphore
f7fed00976ab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1681
diff changeset
  2480
    "arrange for a semaphore to be triggered as soon as possible.
f7fed00976ab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1681
diff changeset
  2481
     The actual signalling is performed slightly delayed, when the dispatcher
2618
6d314138ab88 commentary
Claus Gittinger <cg@exept.de>
parents: 2614
diff changeset
  2482
     looks for a process to resume the next time. I.e. here, the current
6d314138ab88 commentary
Claus Gittinger <cg@exept.de>
parents: 2614
diff changeset
  2483
     process continues to execute, even if the semaphore signalling would
6d314138ab88 commentary
Claus Gittinger <cg@exept.de>
parents: 2614
diff changeset
  2484
     make a higher prio process runnable.
6d314138ab88 commentary
Claus Gittinger <cg@exept.de>
parents: 2614
diff changeset
  2485
     This is provided as entry for primitive-code (external functions)
6d314138ab88 commentary
Claus Gittinger <cg@exept.de>
parents: 2614
diff changeset
  2486
     which want to signal a semaphore AND make certain that they do not get
6d314138ab88 commentary
Claus Gittinger <cg@exept.de>
parents: 2614
diff changeset
  2487
     suspended (i.e. it is called by __STX_SignalSemaphore()).
6d314138ab88 commentary
Claus Gittinger <cg@exept.de>
parents: 2614
diff changeset
  2488
     Normal smalltalk code should always send an appropriate message directly
6d314138ab88 commentary
Claus Gittinger <cg@exept.de>
parents: 2614
diff changeset
  2489
     to the semaphore (i.e. aSemaphore signal)."
1683
f7fed00976ab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1681
diff changeset
  2490
3917
fd02c3beb3d1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3916
diff changeset
  2491
    self signal:aSemaphore atMilliseconds:OperatingSystem getMillisecondTime.
fd02c3beb3d1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3916
diff changeset
  2492
fd02c3beb3d1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3916
diff changeset
  2493
    "Modified: / 9.11.1998 / 20:39:06 / cg"
1683
f7fed00976ab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1681
diff changeset
  2494
!
f7fed00976ab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1681
diff changeset
  2495
16461
11b1345b869b class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16370
diff changeset
  2496
signal:aSemaphore after:aTimeDuration
11b1345b869b class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16370
diff changeset
  2497
    "arrange for a semaphore to be triggered after aTimeDuration"
11b1345b869b class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16370
diff changeset
  2498
11b1345b869b class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16370
diff changeset
  2499
    self signal:aSemaphore afterMilliseconds:aTimeDuration getMilliseconds
11b1345b869b class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16370
diff changeset
  2500
!
11b1345b869b class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16370
diff changeset
  2501
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2502
signal:aSemaphore afterMilliseconds:millis
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2503
    "arrange for a semaphore to be triggered after some milliseconds"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2504
3917
fd02c3beb3d1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3916
diff changeset
  2505
    |now then|
fd02c3beb3d1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3916
diff changeset
  2506
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2507
    now := OperatingSystem getMillisecondTime.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2508
    then := OperatingSystem millisecondTimeAdd:now and:millis rounded.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2509
    self signal:aSemaphore atMilliseconds:then.
3917
fd02c3beb3d1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3916
diff changeset
  2510
fd02c3beb3d1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3916
diff changeset
  2511
    "Modified: / 9.11.1998 / 20:39:27 / cg"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2512
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2513
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2514
signal:aSemaphore afterSeconds:seconds
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2515
    "arrange for a semaphore to be triggered after some seconds"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2516
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2517
    self signal:aSemaphore afterMilliseconds:(seconds * 1000)
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2518
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2519
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2520
signal:aSemaphore atMilliseconds:aMillisecondTime
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2521
    "arrange for a semaphore to be triggered at a specific millisecond time.
2618
6d314138ab88 commentary
Claus Gittinger <cg@exept.de>
parents: 2614
diff changeset
  2522
     If there is already a pending trigger time installed for that semaphore,
6d314138ab88 commentary
Claus Gittinger <cg@exept.de>
parents: 2614
diff changeset
  2523
     the time of the pending trigger is changed."
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2524
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2525
    |index "{ Class: SmallInteger }"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2526
     wasBlocked|
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2527
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2528
    wasBlocked := OperatingSystem blockInterrupts.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2529
    index := timeoutSemaphoreArray identityIndexOf:aSemaphore startingAt:1.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2530
    index ~~ 0 ifTrue:[
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2531
	timeoutArray at:index put:aMillisecondTime
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2532
    ] ifFalse:[
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2533
	index := timeoutArray identityIndexOf:nil startingAt:1.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2534
	index ~~ 0 ifTrue:[
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2535
	    timeoutSemaphoreArray at:index put:aSemaphore.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2536
	    timeoutArray at:index put:aMillisecondTime.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2537
	    timeoutActionArray at:index put:nil.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2538
	    timeoutProcessArray at:index put:nil
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2539
	] ifFalse:[
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2540
	    timeoutSemaphoreArray := timeoutSemaphoreArray copyWith:aSemaphore.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2541
	    timeoutArray := timeoutArray copyWith:aMillisecondTime.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2542
	    timeoutActionArray := timeoutActionArray copyWith:nil.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2543
	    timeoutProcessArray := timeoutProcessArray copyWith:nil
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2544
	].
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2545
    ].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2546
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2547
    anyTimeouts := true.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2548
    wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2549
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2550
18957
e0bb91eae748 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18941
diff changeset
  2551
signal:aSemaphore onException:aFileDescriptor
e0bb91eae748 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18941
diff changeset
  2552
    "arrange for a semaphore to be triggered when output on aFileDescriptor
e0bb91eae748 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18941
diff changeset
  2553
     is possible (i.e. can be written without blocking) or aBlock returns true.
e0bb91eae748 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18941
diff changeset
  2554
     The checkBlock will be evaluated by the scheduler from time to time
e0bb91eae748 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18941
diff changeset
  2555
     (i.e. every few milliseconds).
e0bb91eae748 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18941
diff changeset
  2556
     This checkBlock is required for poor windows, where a WaitForObject does
e0bb91eae748 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18941
diff changeset
  2557
     not know about sockets.
e0bb91eae748 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18941
diff changeset
  2558
     If aBlock is nil, the semaphore is removed from the set of semaphores, after being signaled."
e0bb91eae748 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18941
diff changeset
  2559
e0bb91eae748 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18941
diff changeset
  2560
    |idx "{ Class: SmallInteger }"
e0bb91eae748 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18941
diff changeset
  2561
     wasBlocked slot|
e0bb91eae748 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18941
diff changeset
  2562
e0bb91eae748 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18941
diff changeset
  2563
    wasBlocked := OperatingSystem blockInterrupts.
e0bb91eae748 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18941
diff changeset
  2564
e0bb91eae748 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18941
diff changeset
  2565
    "Here we assume, that for every triple (aSemaphore, aFileDescriptor, aBlock)
e0bb91eae748 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18941
diff changeset
  2566
     aSemphore is never nil, but one of aFileDescriptor, aBlock may be nil"
e0bb91eae748 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18941
diff changeset
  2567
e0bb91eae748 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18941
diff changeset
  2568
    aFileDescriptor isNil ifTrue:[
19850
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  2569
	idx := exceptSemaphoreArray identityIndexOf:aSemaphore or:nil.
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  2570
	idx == 0 ifTrue:[
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  2571
	    "aSemaphore is not registered yet, have to create a new slot"
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  2572
	    exceptFdArray := exceptFdArray copyWith:nil.
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  2573
	    exceptSemaphoreArray := exceptSemaphoreArray copyWith:aSemaphore.
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  2574
	] ifFalse:[
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  2575
	    slot := exceptSemaphoreArray at:idx.
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  2576
	    slot isNil ifTrue:[
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  2577
		exceptSemaphoreArray at:idx put:aSemaphore.
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  2578
	    ]
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  2579
	]
18957
e0bb91eae748 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18941
diff changeset
  2580
    ] ifFalse:[
19850
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  2581
	idx := exceptFdArray identityIndexOf:aFileDescriptor or:nil.
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  2582
	idx == 0 ifTrue:[
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  2583
	    "aFileDescriptor is not registered yet, have to create a new slot"
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  2584
	    exceptFdArray := exceptFdArray copyWith:aFileDescriptor.
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  2585
	    exceptSemaphoreArray := exceptSemaphoreArray copyWith:aSemaphore.
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  2586
	] ifFalse:[
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  2587
	    slot := exceptFdArray at:idx.
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  2588
	    slot isNil ifTrue:[
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  2589
		exceptFdArray at:idx put:aFileDescriptor.
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  2590
		exceptSemaphoreArray at:idx put:aSemaphore.
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  2591
	    ].
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  2592
	].
18957
e0bb91eae748 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18941
diff changeset
  2593
"/        (useIOInterrupts and:[slot isNil]) ifTrue:[
e0bb91eae748 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18941
diff changeset
  2594
"/            OperatingSystem enableIOInterruptsOn:aFileDescriptor
e0bb91eae748 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18941
diff changeset
  2595
"/        ].
e0bb91eae748 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18941
diff changeset
  2596
    ].
e0bb91eae748 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18941
diff changeset
  2597
    wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
e0bb91eae748 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18941
diff changeset
  2598
e0bb91eae748 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18941
diff changeset
  2599
    "Modified: 4.8.1997 / 15:21:49 / cg"
e0bb91eae748 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18941
diff changeset
  2600
!
e0bb91eae748 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18941
diff changeset
  2601
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2602
signal:aSemaphore onInput:aFileDescriptor
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2603
    "arrange for a semaphore to be triggered when input on aFileDescriptor
16461
11b1345b869b class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16370
diff changeset
  2604
     arrives. This will only happen, if the OS supports selecting on fileDescriptors.
11b1345b869b class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16370
diff changeset
  2605
     The semaphore is removed from the set of semaphores, after being signaled."
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2606
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2607
    self signal:aSemaphore onInput:aFileDescriptor orCheck:nil
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2608
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2609
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2610
signal:aSemaphore onInput:aFileDescriptor orCheck:aBlock
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2611
    "arrange for a semaphore to be triggered when input on aFileDescriptor
10747
e9ea71d01445 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10497
diff changeset
  2612
     arrives OR checkblock evaluates to true.
e9ea71d01445 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10497
diff changeset
  2613
     The checkBlock will be evaluated by the scheduler from time to time
5101
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2614
     (i.e. every few milliseconds).
10747
e9ea71d01445 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10497
diff changeset
  2615
     (This is req'd for buffered input, where a select may not detect
2618
6d314138ab88 commentary
Claus Gittinger <cg@exept.de>
parents: 2614
diff changeset
  2616
      data which has already been read into a buffer - as in Xlib.
16461
11b1345b869b class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16370
diff changeset
  2617
      Or on systems, where we cannot select on a displays eventQ, such as windows).
11b1345b869b class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16370
diff changeset
  2618
     If aBlock is nil, the semaphore is removed from the set of semaphores, after being signaled."
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2619
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2620
    |idx "{ Class: SmallInteger }"
16319
d38c34400bd0 class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16317
diff changeset
  2621
     wasBlocked slot|
1627
f95285226059 infoPrint for NT (no select)
Claus Gittinger <cg@exept.de>
parents: 1618
diff changeset
  2622
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2623
    wasBlocked := OperatingSystem blockInterrupts.
3116
e535e4e266dd more error handling;
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
  2624
16319
d38c34400bd0 class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16317
diff changeset
  2625
    "Here we assume, that for every triple (aSemaphore, aFileDescriptor, aBlock)
d38c34400bd0 class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16317
diff changeset
  2626
     aSemphore is never nil, but one of aFileDescriptor, aBlock may be nil"
d38c34400bd0 class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16317
diff changeset
  2627
6807
ba04d2e1a416 oops - hps lexer is not 8-bit clean
Claus Gittinger <cg@exept.de>
parents: 6619
diff changeset
  2628
    aFileDescriptor isNil ifTrue:[
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2629
	idx := readSemaphoreArray identityIndexOf:aSemaphore or:nil.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2630
	idx == 0 ifTrue:[
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2631
	    "aSemaphore is not registered yet, have to create a new slot"
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2632
	    readFdArray := readFdArray copyWith:nil.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2633
	    readSemaphoreArray := readSemaphoreArray copyWith:aSemaphore.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2634
	    readCheckArray := readCheckArray copyWith:aBlock.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2635
	] ifFalse:[
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2636
	    slot := readSemaphoreArray at:idx.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2637
	    slot isNil ifTrue:[
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2638
		readSemaphoreArray at:idx put:aSemaphore.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2639
		readCheckArray at:idx put:aBlock
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2640
	    ] ifFalse:[
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2641
		"/ someone has already registered aSemaphore.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2642
		"/ Check if it is the block changes...
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2643
		(readCheckArray at:idx) notNil ifTrue:[
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2644
		    (readCheckArray at:idx) ~~ aBlock ifTrue:[
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2645
			'Processor [info]: checkblock changed for read-check' infoPrintCR.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2646
			readCheckArray at:idx put:aBlock.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2647
		    ].
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2648
		].
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2649
	    ].
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2650
	]
16319
d38c34400bd0 class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16317
diff changeset
  2651
    ] ifFalse:[
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2652
	idx := readFdArray identityIndexOf:aFileDescriptor or:nil.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2653
	idx == 0 ifTrue:[
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2654
	    "aFileDescriptor is not registered yet, have to create a new slot"
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2655
	    readFdArray := readFdArray copyWith:aFileDescriptor.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2656
	    readSemaphoreArray := readSemaphoreArray copyWith:aSemaphore.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2657
	    readCheckArray := readCheckArray copyWith:aBlock.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2658
	] ifFalse:[
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2659
	    slot := readFdArray at:idx.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2660
	    slot isNil ifTrue:[
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2661
		readFdArray at:idx put:aFileDescriptor.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2662
		readSemaphoreArray at:idx put:aSemaphore.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2663
		readCheckArray at:idx put:aBlock
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2664
	    ] ifFalse:[
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2665
		"/ someone has already registered aFileDescriptor.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2666
		"/ Check if it is the semaphore or block changes...
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2667
		(readSemaphoreArray at:idx) ~~ aSemaphore ifTrue:[
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2668
		    'Processor [info]: sema changed for read-check' infoPrintCR.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2669
		    readSemaphoreArray at:idx put:aSemaphore.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2670
		].
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2671
		(readCheckArray at:idx) ~~ aBlock ifTrue:[
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2672
		    'Processor [info]: checkblock changed for read-check' infoPrintCR.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2673
		    readCheckArray at:idx put:aBlock.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2674
		].
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2675
	    ].
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2676
	].
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2677
	(useIOInterrupts and:[slot isNil]) ifTrue:[
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2678
	    OperatingSystem enableIOInterruptsOn:aFileDescriptor
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2679
	].
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2680
    ].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2681
    wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
2123
6f9cb1ed9db5 new infoMessage scheme
Claus Gittinger <cg@exept.de>
parents: 2116
diff changeset
  2682
2831
02f9aa61f71b ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
  2683
    "Modified: 4.8.1997 / 15:20:45 / cg"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2684
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2685
5103
7b1f6c93b3aa checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5101
diff changeset
  2686
signal:aSemaphore onInputStream:aStream
10747
e9ea71d01445 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10497
diff changeset
  2687
    "arrange for a semaphore to be triggered when input on aStream arrives.
5101
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2688
     This will do a select, if the OS supports selecting on that filedescriptor,
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2689
     otherwise, it will be polled every few milliseconds (MSDOS)."
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2690
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2691
    aStream canBeSelected ifTrue:[
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2692
	"/ can this stream be selected on ?
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2693
	self signal:aSemaphore onInput:aStream fileDescriptor orCheck:nil
5101
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2694
    ] ifFalse:[
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2695
	"/ nope - must poll ...
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2696
	self signal:aSemaphore onInput:nil orCheck:[aStream canReadWithoutBlocking]
5101
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2697
    ]
5107
1dc3079e8eaf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5103
diff changeset
  2698
1dc3079e8eaf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5103
diff changeset
  2699
    "Modified: / 14.12.1999 / 23:58:50 / cg"
5101
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2700
!
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2701
5103
7b1f6c93b3aa checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5101
diff changeset
  2702
signal:aSemaphore onOutput:aFileDescriptor
7b1f6c93b3aa checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5101
diff changeset
  2703
    "arrange for a semaphore to be triggered when output on aFileDescriptor
16461
11b1345b869b class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16370
diff changeset
  2704
     is possible without blocking.
11b1345b869b class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16370
diff changeset
  2705
     The semaphore is removed from the set of semaphores, after being signaled."
5103
7b1f6c93b3aa checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5101
diff changeset
  2706
7b1f6c93b3aa checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5101
diff changeset
  2707
    self signal:aSemaphore onOutput:aFileDescriptor orCheck:nil
7b1f6c93b3aa checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5101
diff changeset
  2708
7b1f6c93b3aa checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5101
diff changeset
  2709
    "Created: / 14.12.1999 / 19:54:12 / cg"
7b1f6c93b3aa checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5101
diff changeset
  2710
!
7b1f6c93b3aa checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5101
diff changeset
  2711
5101
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2712
signal:aSemaphore onOutput:aFileDescriptor orCheck:aBlock
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2713
    "arrange for a semaphore to be triggered when output on aFileDescriptor
5101
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2714
     is possible (i.e. can be written without blocking) or aBlock returns true.
10747
e9ea71d01445 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10497
diff changeset
  2715
     The checkBlock will be evaluated by the scheduler from time to time
5101
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2716
     (i.e. every few milliseconds).
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2717
     This checkBlock is required for poor windows, where a WaitForObject does
16461
11b1345b869b class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16370
diff changeset
  2718
     not know about sockets.
11b1345b869b class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16370
diff changeset
  2719
     If aBlock is nil, the semaphore is removed from the set of semaphores, after being signaled."
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2720
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2721
    |idx "{ Class: SmallInteger }"
16319
d38c34400bd0 class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16317
diff changeset
  2722
     wasBlocked slot|
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2723
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2724
    wasBlocked := OperatingSystem blockInterrupts.
5101
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2725
16319
d38c34400bd0 class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16317
diff changeset
  2726
    "Here we assume, that for every triple (aSemaphore, aFileDescriptor, aBlock)
d38c34400bd0 class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16317
diff changeset
  2727
     aSemphore is never nil, but one of aFileDescriptor, aBlock may be nil"
d38c34400bd0 class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16317
diff changeset
  2728
5101
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2729
    aFileDescriptor isNil ifTrue:[
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2730
	idx := writeSemaphoreArray identityIndexOf:aSemaphore or:nil.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2731
	idx == 0 ifTrue:[
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2732
	    "aSemaphore is not registered yet, have to create a new slot"
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2733
	    writeFdArray := writeFdArray copyWith:nil.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2734
	    writeSemaphoreArray := writeSemaphoreArray copyWith:aSemaphore.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2735
	    writeCheckArray := writeCheckArray copyWith:aBlock.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2736
	] ifFalse:[
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2737
	    slot := writeSemaphoreArray at:idx.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2738
	    slot isNil ifTrue:[
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2739
		writeSemaphoreArray at:idx put:aSemaphore.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2740
		writeCheckArray at:idx put:aBlock
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2741
	    ] ifFalse:[
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2742
		"/ someone has already registered aSemaphore.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2743
		"/ Check if it is the block changes...
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2744
		(writeCheckArray at:idx) notNil ifTrue:[
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2745
		    (writeCheckArray at:idx) ~~ aBlock ifTrue:[
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2746
			'Processor [info]: checkblock changed for write-check' infoPrintCR.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2747
			writeCheckArray at:idx put:aBlock.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2748
		    ].
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2749
		].
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2750
	    ].
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2751
	]
16319
d38c34400bd0 class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16317
diff changeset
  2752
    ] ifFalse:[
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2753
	idx := writeFdArray identityIndexOf:aFileDescriptor or:nil.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2754
	idx == 0 ifTrue:[
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2755
	    "aFileDescriptor is not registered yet, have to create a new slot"
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2756
	    writeFdArray := writeFdArray copyWith:aFileDescriptor.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2757
	    writeSemaphoreArray := writeSemaphoreArray copyWith:aSemaphore.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2758
	    writeCheckArray := writeCheckArray copyWith:aBlock.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2759
	] ifFalse:[
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2760
	    slot := writeFdArray at:idx.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2761
	    slot isNil ifTrue:[
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2762
		writeFdArray at:idx put:aFileDescriptor.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2763
		writeSemaphoreArray at:idx put:aSemaphore.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2764
		writeCheckArray at:idx put:aBlock
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2765
	    ] ifFalse:[
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2766
		"/ someone has already registered aFileDescriptor.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2767
		"/ Check if it is the semaphore or block changes...
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2768
		(writeSemaphoreArray at:idx) ~~ aSemaphore ifTrue:[
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2769
		    'Processor [info]: sema changed for write-check' infoPrintCR.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2770
		    writeSemaphoreArray at:idx put:aSemaphore.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2771
		].
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2772
		(writeCheckArray at:idx) ~~ aBlock ifTrue:[
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2773
		    'Processor [info]: checkblock changed for write-check' infoPrintCR.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2774
		    writeCheckArray at:idx put:aBlock.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2775
		].
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2776
	    ].
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2777
	].
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2778
	(useIOInterrupts and:[slot isNil]) ifTrue:[
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2779
	    OperatingSystem enableIOInterruptsOn:aFileDescriptor
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2780
	].
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2781
    ].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2782
    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
  2783
02f9aa61f71b ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
  2784
    "Modified: 4.8.1997 / 15:21:49 / cg"
5103
7b1f6c93b3aa checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5101
diff changeset
  2785
!
7b1f6c93b3aa checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5101
diff changeset
  2786
7b1f6c93b3aa checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5101
diff changeset
  2787
signal:aSemaphore onOutputStream:aStream
10747
e9ea71d01445 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10497
diff changeset
  2788
    "arrange for a semaphore to be triggered when output on aStream is possible.
5103
7b1f6c93b3aa checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5101
diff changeset
  2789
     This will do a select, if the OS supports selecting on that filedescriptor,
7b1f6c93b3aa checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5101
diff changeset
  2790
     otherwise, it will be polled every few milliseconds (MSDOS)."
7b1f6c93b3aa checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5101
diff changeset
  2791
7b1f6c93b3aa checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5101
diff changeset
  2792
    aStream canBeSelected ifTrue:[
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2793
	"/ can this stream be selected on ?
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2794
	self signal:aSemaphore onOutput:aStream fileDescriptor orCheck:nil
5103
7b1f6c93b3aa checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5101
diff changeset
  2795
    ] ifFalse:[
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2796
	"/ nope - must poll ...
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2797
	self signal:aSemaphore onOutput:nil orCheck:[aStream canWriteWithoutBlocking]
5103
7b1f6c93b3aa checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5101
diff changeset
  2798
    ]
5107
1dc3079e8eaf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5103
diff changeset
  2799
1dc3079e8eaf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5103
diff changeset
  2800
    "Modified: / 14.12.1999 / 23:59:19 / cg"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2801
! !
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2802
3650
523781600982 added #useIOInterrupts: to allow disabling this feature
Claus Gittinger <cg@exept.de>
parents: 3644
diff changeset
  2803
!ProcessorScheduler methodsFor:'special configuration'!
523781600982 added #useIOInterrupts: to allow disabling this feature
Claus Gittinger <cg@exept.de>
parents: 3644
diff changeset
  2804
523781600982 added #useIOInterrupts: to allow disabling this feature
Claus Gittinger <cg@exept.de>
parents: 3644
diff changeset
  2805
useIOInterrupts:aBoolean
523781600982 added #useIOInterrupts: to allow disabling this feature
Claus Gittinger <cg@exept.de>
parents: 3644
diff changeset
  2806
    "enable/disable the use of IO-interrupts.
523781600982 added #useIOInterrupts: to allow disabling this feature
Claus Gittinger <cg@exept.de>
parents: 3644
diff changeset
  2807
     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
  2808
     are polled in regular intervals.
523781600982 added #useIOInterrupts: to allow disabling this feature
Claus Gittinger <cg@exept.de>
parents: 3644
diff changeset
  2809
     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
  2810
     interrupt.
523781600982 added #useIOInterrupts: to allow disabling this feature
Claus Gittinger <cg@exept.de>
parents: 3644
diff changeset
  2811
     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
  2812
     (typically 2-7%).
10747
e9ea71d01445 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10497
diff changeset
  2813
     Notice:
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2814
	some systems do not support IO-interrupts (or have a broken stdio-lib),
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2815
	and this feature is always disabled;
3650
523781600982 added #useIOInterrupts: to allow disabling this feature
Claus Gittinger <cg@exept.de>
parents: 3644
diff changeset
  2816
     Also notice:
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2817
	we found that in some Xlib-implementations, interrupted reads are not
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2818
	handled correctly (especially in multi-headed applications), and this
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2819
	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
  2820
10747
e9ea71d01445 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10497
diff changeset
  2821
     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
  2822
     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
  2823
523781600982 added #useIOInterrupts: to allow disabling this feature
Claus Gittinger <cg@exept.de>
parents: 3644
diff changeset
  2824
    OperatingSystem supportsIOInterrupts ifTrue:[
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2825
	useIOInterrupts := aBoolean
3650
523781600982 added #useIOInterrupts: to allow disabling this feature
Claus Gittinger <cg@exept.de>
parents: 3644
diff changeset
  2826
    ].
523781600982 added #useIOInterrupts: to allow disabling this feature
Claus Gittinger <cg@exept.de>
parents: 3644
diff changeset
  2827
523781600982 added #useIOInterrupts: to allow disabling this feature
Claus Gittinger <cg@exept.de>
parents: 3644
diff changeset
  2828
    "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
  2829
! !
523781600982 added #useIOInterrupts: to allow disabling this feature
Claus Gittinger <cg@exept.de>
parents: 3644
diff changeset
  2830
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2831
!ProcessorScheduler methodsFor:'timeout handling'!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2832
16496
8b9c1ca54d42 class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16461
diff changeset
  2833
addTimedBlock:aBlock after:timeDuration
8b9c1ca54d42 class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16461
diff changeset
  2834
    "add the argument, aBlock to the list of time-scheduled-blocks; to be
8b9c1ca54d42 class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16461
diff changeset
  2835
     evaluated after timeDuration. The process which installs this timed
8b9c1ca54d42 class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16461
diff changeset
  2836
     block will be interrupted for execution of the block.
8b9c1ca54d42 class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16461
diff changeset
  2837
     (if it is running, the interrupt will occur in whatever method it is
8b9c1ca54d42 class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16461
diff changeset
  2838
      executing; if it is suspended, it will be resumed).
8b9c1ca54d42 class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16461
diff changeset
  2839
     The block will be removed from the timed-block list after evaluation
8b9c1ca54d42 class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16461
diff changeset
  2840
     (i.e. it will trigger only once).
8b9c1ca54d42 class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16461
diff changeset
  2841
     Returns an ID, which can be used in #removeTimeoutWidthID:"
8b9c1ca54d42 class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16461
diff changeset
  2842
8b9c1ca54d42 class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16461
diff changeset
  2843
    ^ self addTimedBlock:aBlock for:activeProcess afterMilliseconds:timeDuration getMilliseconds
8b9c1ca54d42 class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16461
diff changeset
  2844
!
8b9c1ca54d42 class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16461
diff changeset
  2845
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2846
addTimedBlock:aBlock afterMilliseconds:delta
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2847
    "add the argument, aBlock to the list of time-scheduled-blocks; to be
10747
e9ea71d01445 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10497
diff changeset
  2848
     evaluated after delta milliseconds. The process which installs this timed
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2849
     block will be interrupted for execution of the block.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2850
     (if it is running, the interrupt will occur in whatever method it is
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2851
      executing; if it is suspended, it will be resumed).
10747
e9ea71d01445 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10497
diff changeset
  2852
     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
  2853
     (i.e. it will trigger only once).
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  2854
     Returns an ID, which can be used in #removeTimeoutWidthID:"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2855
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2856
    ^ self addTimedBlock:aBlock for:activeProcess afterMilliseconds:delta
1676
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  2857
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  2858
    "Modified: 23.9.1996 / 14:33:59 / cg"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2859
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2860
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2861
addTimedBlock:aBlock afterSeconds:delta
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2862
    "add the argument, aBlock to the list of time-scheduled-blocks.
10747
e9ea71d01445 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10497
diff changeset
  2863
     to be evaluated after delta seconds. The process which installs this timed
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2864
     block will be interrupted for execution of the block.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2865
     (if it is running, the interrupt will occur in whatever method it is
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2866
      executing; if it is suspended, it will be resumed).
10747
e9ea71d01445 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10497
diff changeset
  2867
     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
  2868
     (i.e. it will trigger only once).
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  2869
     Returns an ID, which can be used in #removeTimeoutWidthID:"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2870
1676
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  2871
    ^ self addTimedBlock:aBlock for:activeProcess afterMilliseconds:(delta * 1000) rounded
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  2872
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  2873
    "Modified: 23.9.1996 / 14:34:04 / cg"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2874
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2875
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2876
addTimedBlock:aBlock atMilliseconds:aMillisecondTime
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2877
    "add the argument, aBlock to the list of time-scheduled-blocks; to be
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2878
     evaluated when the millisecondClock value passes aMillisecondTime.
10747
e9ea71d01445 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10497
diff changeset
  2879
     The process which installs this timed block will be interrupted for
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2880
     execution of the block.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2881
     (if it is running, the interrupt will occur in whatever method it is
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2882
      executing; if it is suspended, it will be resumed).
10747
e9ea71d01445 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10497
diff changeset
  2883
     The block will be removed from the timed-block list after evaluation
e9ea71d01445 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10497
diff changeset
  2884
     (i.e. it will trigger only once).
1676
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  2885
     Returns an ID, which can be used in #removeTimeoutWidthID:"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2886
1676
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  2887
    ^ self addTimedBlock:aBlock for:activeProcess atMilliseconds:aMillisecondTime
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  2888
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  2889
    "Modified: 23.9.1996 / 14:34:09 / cg"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2890
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2891
16496
8b9c1ca54d42 class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16461
diff changeset
  2892
addTimedBlock:aBlock for:aProcess after:timeDuration
8b9c1ca54d42 class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16461
diff changeset
  2893
    "add the argument, aBlock to the list of time-scheduled-blocks.
8b9c1ca54d42 class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16461
diff changeset
  2894
     to be evaluated after timeDuration. aProcess will be interrupted for
8b9c1ca54d42 class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16461
diff changeset
  2895
     execution of the block.
8b9c1ca54d42 class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16461
diff changeset
  2896
     (if it is running, the interrupt will occur in whatever method it is
8b9c1ca54d42 class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16461
diff changeset
  2897
      executing; if it is suspended, it will be resumed).
8b9c1ca54d42 class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16461
diff changeset
  2898
     If aProcess is nil, the block will be evaluated by the scheduler itself
8b9c1ca54d42 class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16461
diff changeset
  2899
     (which is dangerous - the block should not raise any error conditions).
8b9c1ca54d42 class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16461
diff changeset
  2900
     The block will be removed from the timed-block list after evaluation
8b9c1ca54d42 class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16461
diff changeset
  2901
     (i.e. it will trigger only once).
8b9c1ca54d42 class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16461
diff changeset
  2902
     Returns an ID, which can be used in #removeTimeoutWidthID:"
8b9c1ca54d42 class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16461
diff changeset
  2903
8b9c1ca54d42 class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16461
diff changeset
  2904
    ^ self addTimedBlock:aBlock for:aProcess afterMilliseconds:timeDuration getMilliseconds
8b9c1ca54d42 class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16461
diff changeset
  2905
8b9c1ca54d42 class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16461
diff changeset
  2906
    "Modified: 23.9.1996 / 14:34:18 / cg"
8b9c1ca54d42 class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16461
diff changeset
  2907
!
8b9c1ca54d42 class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16461
diff changeset
  2908
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2909
addTimedBlock:aBlock for:aProcess afterMilliseconds:delta
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2910
    "add the argument, aBlock to the list of time-scheduled-blocks; to be
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2911
     evaluated after delta milliseconds. The process specified by the argument,
10747
e9ea71d01445 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10497
diff changeset
  2912
     aProcess will be interrupted for execution of the block.
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2913
     (if it is running, the interrupt will occur in whatever method it is
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2914
      executing; if it is suspended, it will be resumed).
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2915
     If aProcess is nil, the block will be evaluated by the scheduler itself
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2916
     (which is dangerous - the block should not raise any error conditions).
10747
e9ea71d01445 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10497
diff changeset
  2917
     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
  2918
     (i.e. it will trigger only once).
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  2919
     Returns an ID, which can be used in #removeTimeoutWidthID:"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2920
1676
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  2921
    |now then wasBlocked id|
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2922
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2923
    wasBlocked := OperatingSystem blockInterrupts.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2924
    now := OperatingSystem getMillisecondTime.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2925
    then := OperatingSystem millisecondTimeAdd:now and:delta.
1676
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  2926
    id := self addTimedBlock:aBlock for:aProcess atMilliseconds:then.
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2927
    wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
1676
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  2928
    ^ id
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  2929
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  2930
    "Modified: 23.9.1996 / 14:34:13 / cg"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2931
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2932
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2933
addTimedBlock:aBlock for:aProcess afterSeconds:delta
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2934
    "add the argument, aBlock to the list of time-scheduled-blocks.
10747
e9ea71d01445 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10497
diff changeset
  2935
     to be evaluated after delta seconds. aProcess will be interrupted for
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2936
     execution of the block.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2937
     (if it is running, the interrupt will occur in whatever method it is
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2938
      executing; if it is suspended, it will be resumed).
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2939
     If aProcess is nil, the block will be evaluated by the scheduler itself
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2940
     (which is dangerous - the block should not raise any error conditions).
10747
e9ea71d01445 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10497
diff changeset
  2941
     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
  2942
     (i.e. it will trigger only once).
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  2943
     Returns an ID, which can be used in #removeTimeoutWidthID:"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2944
1676
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  2945
    ^ self addTimedBlock:aBlock for:aProcess afterMilliseconds:(delta * 1000) rounded
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  2946
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  2947
    "Modified: 23.9.1996 / 14:34:18 / cg"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2948
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2949
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2950
addTimedBlock:aBlock for:aProcess atMilliseconds:aMillisecondTime
20736
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  2951
    "add the argument, aBlock to the list of time-scheduled-blocks; 
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  2952
     to be evaluated by aProcess when the millisecondClock value passes
10747
e9ea71d01445 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10497
diff changeset
  2953
     aMillisecondTime.
20736
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  2954
     If that block is already in the timeout list, its trigger-time is changed.
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  2955
     The process specified by the argument, aProcess 
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  2956
     will be interrupted for execution of the block.
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2957
     If aProcess is nil, the block will be evaluated by the scheduler itself
20736
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  2958
     (which is dangerous: the block should not raise any error conditions).
10747
e9ea71d01445 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10497
diff changeset
  2959
     If the process is active at trigger time, the interrupt will occur in
20736
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  2960
     whatever method it is executing; 
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  2961
     if suspended at trigger time, it will be resumed.
10747
e9ea71d01445 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10497
diff changeset
  2962
     The block will be removed from the timed-block list after evaluation
e9ea71d01445 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10497
diff changeset
  2963
     (i.e. it will trigger only once).
1676
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  2964
     Returns an ID, which can be used in #removeTimeoutWidthID:"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2965
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2966
    |index "{ Class: SmallInteger }"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2967
     wasBlocked|
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2968
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2969
    wasBlocked := OperatingSystem blockInterrupts.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2970
    index := timeoutActionArray identityIndexOf:aBlock startingAt:1.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2971
    index ~~ 0 ifTrue:[
20736
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  2972
        timeoutArray at:index put:aMillisecondTime
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2973
    ] ifFalse:[
20736
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  2974
        index := timeoutArray indexOf:nil.
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  2975
        index ~~ 0 ifTrue:[
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  2976
            timeoutArray at:index put:aMillisecondTime.
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  2977
            timeoutActionArray at:index put:aBlock.
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  2978
            timeoutSemaphoreArray at:index put:nil.
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  2979
            timeoutProcessArray at:index put:aProcess
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  2980
        ] ifFalse:[
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  2981
            timeoutArray := timeoutArray copyWith:aMillisecondTime.
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  2982
            timeoutActionArray := timeoutActionArray copyWith:aBlock.
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  2983
            timeoutSemaphoreArray := timeoutSemaphoreArray copyWith:nil.
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  2984
            timeoutProcessArray := timeoutProcessArray copyWith:aProcess.
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  2985
            index := timeoutArray size.
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  2986
        ].
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2987
    ].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2988
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2989
    anyTimeouts := true.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2990
    wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
1676
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  2991
    ^ index
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  2992
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  2993
    "Modified: 23.9.1996 / 14:34:23 / cg"
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  2994
!
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  2995
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  2996
addTimeoutFunctionCall:anExternalFunction for:aProcess afterMilliseconds:delta with:argument
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  2997
    "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
  2998
     after some millisecond-Delay.
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  2999
     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
  3000
     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
  3001
     in this processes context.
10747
e9ea71d01445 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10497
diff changeset
  3002
     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
  3003
     (i.e. it will trigger only once).
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  3004
     Returns an ID, which can be used in #removeTimeoutWidthID:"
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  3005
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  3006
    |now then wasBlocked id|
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  3007
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  3008
    wasBlocked := OperatingSystem blockInterrupts.
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  3009
    now := OperatingSystem getMillisecondTime.
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  3010
    then := OperatingSystem millisecondTimeAdd:now and:delta.
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  3011
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  3012
    id := self
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  3013
	addTimeoutFunctionCall:anExternalFunction
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  3014
	for:aProcess
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  3015
	atMilliseconds:then
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  3016
	with:argument.
1676
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  3017
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  3018
    wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  3019
    ^ id
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  3020
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  3021
    "Created: 23.9.1996 / 14:28:27 / cg"
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  3022
    "Modified: 23.9.1996 / 14:34:42 / cg"
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  3023
!
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  3024
1681
56d8d1d96d95 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1680
diff changeset
  3025
addTimeoutFunctionCall:anExternalFunction for:aProcess atMilliseconds:milliTime with:argument
1676
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  3026
    "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
  3027
     at some millisecond-time.
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  3028
     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
  3029
     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
  3030
     in this processes context.
10747
e9ea71d01445 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10497
diff changeset
  3031
     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
  3032
     (i.e. it will trigger only once).
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  3033
     Returns an ID, which can be used in #removeTimeoutWidthID:"
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  3034
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  3035
    |action|
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  3036
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  3037
    action := [anExternalFunction callWith:argument].
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  3038
    ^ self
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  3039
	addTimedBlock:action
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  3040
	for:aProcess
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  3041
	atMilliseconds:milliTime.
1676
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  3042
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  3043
    "Created: 23.9.1996 / 14:29:30 / cg"
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  3044
    "Modified: 23.9.1996 / 14:34:57 / cg"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  3045
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  3046
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  3047
evaluateTimeouts
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  3048
    "walk through timeouts and evaluate blocks or signal semas that need to be .."
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  3049
16210
3f0d3162e40b class: ProcessorScheduler
Claus Gittinger <cg@exept.de>
parents: 16206
diff changeset
  3050
    |sema now aTime block blocksAndProcessesToEvaluate
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  3051
     firstBlockToEvaluate firstProcess
16231
88589c89be48 class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16210
diff changeset
  3052
     n "{ Class: SmallInteger }"
15657
ffad68df93ca class: ProcessorScheduler
Claus Gittinger <cg@exept.de>
parents: 15634
diff changeset
  3053
     indexOfLastTimeout "{ Class: SmallInteger }"
ffad68df93ca class: ProcessorScheduler
Claus Gittinger <cg@exept.de>
parents: 15634
diff changeset
  3054
     halfSize "{ Class: SmallInteger }"
16206
b718fbf5d43e class: ProcessorScheduler
Claus Gittinger <cg@exept.de>
parents: 15687
diff changeset
  3055
     wasBlocked p|
b718fbf5d43e class: ProcessorScheduler
Claus Gittinger <cg@exept.de>
parents: 15687
diff changeset
  3056
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  3057
    anyTimeouts ifFalse:[ ^ self].
11164
8cbff6ed574f #timeToNextTimeout - handling of negative time deltas
Stefan Vogel <sv@exept.de>
parents: 10748
diff changeset
  3058
    anyTimeouts := false.
19858
5146a1f4779f oops compilable
Claus Gittinger <cg@exept.de>
parents: 19853
diff changeset
  3059
    indexOfLastTimeout := 0.
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  3060
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  3061
    "have to collect the blocks first, then evaluate them.
16210
3f0d3162e40b class: ProcessorScheduler
Claus Gittinger <cg@exept.de>
parents: 16206
diff changeset
  3062
     This avoids problems due to newly inserted blocks."
3f0d3162e40b class: ProcessorScheduler
Claus Gittinger <cg@exept.de>
parents: 16206
diff changeset
  3063
3f0d3162e40b class: ProcessorScheduler
Claus Gittinger <cg@exept.de>
parents: 16206
diff changeset
  3064
    "/ notice: the code looks uglier than seems to be required;
3f0d3162e40b class: ProcessorScheduler
Claus Gittinger <cg@exept.de>
parents: 16206
diff changeset
  3065
    "/ the observation is that in almost all cases, only a single block (or no block at all)
3f0d3162e40b class: ProcessorScheduler
Claus Gittinger <cg@exept.de>
parents: 16206
diff changeset
  3066
    "/ is found in the loops below.
16231
88589c89be48 class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16210
diff changeset
  3067
    "/ To avoid idle memory allocation, we avoid the allocation of the OrderedCollection in this case,
88589c89be48 class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16210
diff changeset
  3068
    "/ by remembering the first block+process in a variable until another block is found.
16210
3f0d3162e40b class: ProcessorScheduler
Claus Gittinger <cg@exept.de>
parents: 16206
diff changeset
  3069
    "/ Thus firstBlockToEvaluate+firstProcess effectively cache the first slot of the lazy allocated collection.
3f0d3162e40b class: ProcessorScheduler
Claus Gittinger <cg@exept.de>
parents: 16206
diff changeset
  3070
    "/ looks ugly, but as this is called very often, reduces idle allocation by a lot.
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  3071
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  3072
    now := OperatingSystem getMillisecondTime.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  3073
    n := timeoutArray size.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  3074
    1 to:n do:[:index |
20736
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  3075
        aTime := timeoutArray at:index.
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  3076
        aTime notNil ifTrue:[
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  3077
            (OperatingSystem millisecondTime:now isAfter:aTime) ifTrue:[
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  3078
                "this one should be triggered"
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  3079
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  3080
                sema := timeoutSemaphoreArray at:index.
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  3081
                sema notNil ifTrue:[
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  3082
                    timeoutSemaphoreArray at:index put:nil.
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  3083
                    timedActionCounter := (timedActionCounter + 1 bitAnd:SmallInteger maxVal).
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  3084
                    sema signalOnce.
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  3085
                ] ifFalse:[
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  3086
                    "to support pure-events"
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  3087
                    block := timeoutActionArray at:index.
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  3088
                    block notNil ifTrue:[
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  3089
                        "/ usually (>99%), there is only one single timeout action to call;
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  3090
                        "/ avoid creation of an OrderedCollection
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  3091
                        firstBlockToEvaluate isNil ifTrue:[
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  3092
                            firstBlockToEvaluate := block.
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  3093
                            firstProcess := timeoutProcessArray at:index.
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  3094
                        ] ifFalse:[
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  3095
                            blocksAndProcessesToEvaluate isNil ifTrue:[
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  3096
                                blocksAndProcessesToEvaluate := OrderedCollection
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  3097
                                                                    with:firstBlockToEvaluate
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  3098
                                                                    with:firstProcess.
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  3099
                            ].
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  3100
                            blocksAndProcessesToEvaluate add:block.
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  3101
                            blocksAndProcessesToEvaluate add:(timeoutProcessArray at:index).
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  3102
                        ].
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  3103
                        timeoutActionArray at:index put:nil.
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  3104
                        timeoutProcessArray at:index put:nil.
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  3105
                    ]
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  3106
                ].
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  3107
                timeoutArray at:index put:nil.
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  3108
            ] ifFalse:[
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  3109
                "there are still pending timeouts"
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  3110
                anyTimeouts := true.
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  3111
                indexOfLastTimeout := index.
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  3112
            ]
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  3113
        ]
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  3114
    ].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  3115
16231
88589c89be48 class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16210
diff changeset
  3116
    "shrink the arrays, if they are 50% free"
15657
ffad68df93ca class: ProcessorScheduler
Claus Gittinger <cg@exept.de>
parents: 15634
diff changeset
  3117
    n > 20 ifTrue:[
20736
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  3118
        halfSize := n // 2.
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  3119
        (indexOfLastTimeout ~~ 0 and:[indexOfLastTimeout < halfSize]) ifTrue:[
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  3120
            wasBlocked := OperatingSystem blockInterrupts.
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  3121
            (timeoutArray at:indexOfLastTimeout+1) isNil ifTrue:[   "/ no new timeouts arrived
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  3122
                timeoutArray := timeoutArray copyTo:halfSize.
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  3123
                timeoutSemaphoreArray := timeoutSemaphoreArray copyTo:halfSize.
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  3124
                timeoutActionArray := timeoutActionArray copyTo:halfSize.
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  3125
                timeoutProcessArray := timeoutProcessArray copyTo:halfSize.
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  3126
            ].
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  3127
            wasBlocked ifFalse:[ OperatingSystem unblockInterrupts ].
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  3128
        ].
15657
ffad68df93ca class: ProcessorScheduler
Claus Gittinger <cg@exept.de>
parents: 15634
diff changeset
  3129
    ].
ffad68df93ca class: ProcessorScheduler
Claus Gittinger <cg@exept.de>
parents: 15634
diff changeset
  3130
19850
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  3131
    "/ 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
  3132
    "/ above code avoided the creation of an OrderedCollection
16210
3f0d3162e40b class: ProcessorScheduler
Claus Gittinger <cg@exept.de>
parents: 16206
diff changeset
  3133
    blocksAndProcessesToEvaluate isNil ifTrue:[
20736
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  3134
        firstBlockToEvaluate notNil ifTrue:[
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  3135
            timedActionCounter := (timedActionCounter + 1 bitAnd:SmallInteger maxVal).
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  3136
            (firstProcess isNil or:[firstProcess == scheduler or:[PureEventDriven]]) ifTrue:[
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  3137
                firstBlockToEvaluate value
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  3138
            ] ifFalse:[
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  3139
                firstProcess isDead ifTrue:[
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  3140
                    "/ a timedBlock for a process which has already terminated
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  3141
                    "/ issue a warning and do not execute it.
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  3142
                    "/ (executing here may be dangerous, since it would run at scheduler priority here,
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  3143
                    "/  and thereby could block the whole smalltalk system.
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  3144
                    "/  For this reason is it IGNORED here.)
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  3145
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  3146
                    "/ Could handle it in timeoutProcess, but we don't,
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  3147
                    "/ because otherwise timeouts might be reissued forever...
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  3148
                    "/      (timeoutHandlerProcess notNil and:[timeoutHandlerProcess isDead not]) ifTrue:[
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  3149
                    "/          timeoutHandlerProcess interruptWith:block.
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  3150
                    "/      ] ifFalse:[
20888
a08539e8ab7e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 20887
diff changeset
  3151
                        ('ProcessorScheduler [warning]: cannot evaluate timedBlock (', firstBlockToEvaluate displayString, ') for dead process: ''' , firstProcess name , '''') errorPrintCR.
20736
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  3152
                    "/      ].
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  3153
                ] ifFalse:[
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  3154
                    firstProcess interruptWith:firstBlockToEvaluate
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  3155
                ]
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  3156
            ]
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  3157
        ].
16210
3f0d3162e40b class: ProcessorScheduler
Claus Gittinger <cg@exept.de>
parents: 16206
diff changeset
  3158
    ] ifFalse:[
20736
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  3159
        n := blocksAndProcessesToEvaluate size.
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  3160
        1 to:n by:2 do:[:index |
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  3161
            block := blocksAndProcessesToEvaluate at:index.
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  3162
            p := blocksAndProcessesToEvaluate at:index+1.
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  3163
            (p isNil or:[p == scheduler or:[PureEventDriven]]) ifTrue:[
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  3164
                block value.
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  3165
                timedActionCounter := (timedActionCounter + 1 bitAnd:SmallInteger maxVal).
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  3166
            ] ifFalse:[
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  3167
                p isDead ifTrue:[
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  3168
                    "/ a timedBlock for a process which has already terminated
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  3169
                    "/ issue a warning and do not execute it.
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  3170
                    "/ (executing here may be dangerous, since it would run at scheduler priority here,
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  3171
                    "/  and thereby could block the whole smalltalk system.
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  3172
                    "/  For this reason is it IGNORED here.)
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  3173
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  3174
                    "/ Could handle it in timeoutProcess, but we don't,
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  3175
                    "/ because otherwise timeouts might be reissued forever...
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  3176
                    "/      (timeoutHandlerProcess notNil and:[timeoutHandlerProcess isDead not]) ifTrue:[
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  3177
                    "/          timeoutHandlerProcess interruptWith:block.
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  3178
                    "/      ] ifFalse:[
20888
a08539e8ab7e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 20887
diff changeset
  3179
                        ('ProcessorScheduler [warning]: cannot evaluate timedBlock (', block displayString, ') for dead process: ''' , p name , '''') errorPrintCR.
20736
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  3180
                    "/      ].
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  3181
                ] ifFalse:[
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  3182
                    timedActionCounter := (timedActionCounter + 1 bitAnd:SmallInteger maxVal).
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  3183
                    p interruptWith:block
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  3184
                ]
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  3185
            ]
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  3186
        ]
16210
3f0d3162e40b class: ProcessorScheduler
Claus Gittinger <cg@exept.de>
parents: 16206
diff changeset
  3187
    ].
3245
863c0a09f5a2 issue a warning if a timedBlock is to be evaluated for a dead thread
Claus Gittinger <cg@exept.de>
parents: 3116
diff changeset
  3188
15581
6332a960dbcd class: ProcessorScheduler
Claus Gittinger <cg@exept.de>
parents: 15510
diff changeset
  3189
    "Modified: / 30-07-2013 / 19:33:24 / cg"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  3190
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  3191
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  3192
removeTimedBlock:aBlock
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  3193
    "remove the argument, aBlock from the list of time-sceduled-blocks."
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  3194
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  3195
    |index "{ Class: SmallInteger }"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  3196
     wasBlocked|
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  3197
3916
cec84c84864c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3862
diff changeset
  3198
    aBlock isNil ifTrue:[^ self].
cec84c84864c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3862
diff changeset
  3199
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  3200
    wasBlocked := OperatingSystem blockInterrupts.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  3201
    index := timeoutActionArray identityIndexOf:aBlock startingAt:1.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  3202
    (index ~~ 0) ifTrue:[
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  3203
	timeoutArray at:index put:nil.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  3204
	timeoutActionArray at:index put:nil.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  3205
	timeoutSemaphoreArray at:index put:nil.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  3206
	timeoutProcessArray at:index put:nil.
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  3207
    ].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  3208
    wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
1676
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  3209
!
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  3210
20052
4bd27ae52593 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19859
diff changeset
  3211
removeTimeoutForSemaphore:aSemaphore
4bd27ae52593 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19859
diff changeset
  3212
    "remove the timeOut that signals aSemaphore
4bd27ae52593 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19859
diff changeset
  3213
     from the list of time-scheduled-blocks."
4bd27ae52593 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19859
diff changeset
  3214
4bd27ae52593 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19859
diff changeset
  3215
    |index "{ Class: SmallInteger }"
4bd27ae52593 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19859
diff changeset
  3216
     wasBlocked|
4bd27ae52593 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19859
diff changeset
  3217
4bd27ae52593 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19859
diff changeset
  3218
    wasBlocked := OperatingSystem blockInterrupts.
4bd27ae52593 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19859
diff changeset
  3219
4bd27ae52593 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19859
diff changeset
  3220
    index := 0.
20736
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  3221
    [
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  3222
        index := timeoutSemaphoreArray identityIndexOf:aSemaphore startingAt:index+1.
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  3223
        index ~~ 0
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  3224
    ] whileTrue:[
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  3225
        timeoutArray at:index put:nil.
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  3226
        timeoutSemaphoreArray at:index put:nil.
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  3227
        timeoutActionArray at:index put:nil.
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  3228
        timeoutProcessArray at:index put:nil.
20052
4bd27ae52593 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19859
diff changeset
  3229
    ].
4bd27ae52593 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19859
diff changeset
  3230
4bd27ae52593 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19859
diff changeset
  3231
    wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
4bd27ae52593 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19859
diff changeset
  3232
!
4bd27ae52593 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19859
diff changeset
  3233
1680
b90690d9d6c5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1679
diff changeset
  3234
removeTimeoutWithID:anID
1676
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  3235
    "remove the timeOut with anID (as returned by #addTimedBlock)
16231
88589c89be48 class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16210
diff changeset
  3236
     from the list of time-scheduled-blocks."
1676
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  3237
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  3238
    |index "{ Class: SmallInteger }"
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  3239
     wasBlocked|
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  3240
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  3241
    index := anID.
1680
b90690d9d6c5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1679
diff changeset
  3242
    (index > 0) ifTrue:[
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  3243
	wasBlocked := OperatingSystem blockInterrupts.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  3244
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  3245
	timeoutArray at:index put:nil.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  3246
	timeoutActionArray at:index put:nil.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  3247
	timeoutSemaphoreArray at:index put:nil.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  3248
	timeoutProcessArray at:index put:nil.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  3249
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  3250
	wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
1680
b90690d9d6c5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1679
diff changeset
  3251
    ]
1676
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  3252
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  3253
    "Created: 23.9.1996 / 14:32:33 / cg"
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  3254
    "Modified: 23.9.1996 / 14:35:09 / cg"
9437
432a4a06934f + timeoutHandlerProcess
ca
parents: 9295
diff changeset
  3255
!
432a4a06934f + timeoutHandlerProcess
ca
parents: 9295
diff changeset
  3256
18774
a262834431c7 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18673
diff changeset
  3257
removeTimeoutWithID:anID object:aBlockOrSemaphore
a262834431c7 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18673
diff changeset
  3258
    "remove the timeOut with anID (as returned by #addTimedBlock)
a262834431c7 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18673
diff changeset
  3259
     from the list of time-scheduled-blocks.
a262834431c7 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18673
diff changeset
  3260
     If aBlockOrSempahore is not nil, check if the id is really for the block
a262834431c7 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18673
diff changeset
  3261
     or for the semphore."
a262834431c7 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18673
diff changeset
  3262
a262834431c7 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18673
diff changeset
  3263
    |index "{ Class: SmallInteger }"
a262834431c7 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18673
diff changeset
  3264
     wasBlocked|
a262834431c7 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18673
diff changeset
  3265
a262834431c7 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18673
diff changeset
  3266
    index := anID.
18776
b068b9fe6667 Fix last change
Stefan Vogel <sv@exept.de>
parents: 18775
diff changeset
  3267
    (anID notNil and:[index > 0]) ifTrue:[
19850
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  3268
	wasBlocked := OperatingSystem blockInterrupts.
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  3269
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  3270
	(aBlockOrSemaphore notNil
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  3271
	  and:[(timeoutActionArray at:index ifAbsent:[]) ~~ aBlockOrSemaphore
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  3272
	  and:[(timeoutSemaphoreArray at:index ifAbsent:[]) ~~ aBlockOrSemaphore]]) ifTrue:[
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  3273
	    'Processor: trying to remove stale timeout id - ignored' errorPrintCR.
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  3274
	] ifFalse:[
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  3275
	    timeoutArray at:index put:nil.
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  3276
	    timeoutActionArray at:index put:nil.
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  3277
	    timeoutSemaphoreArray at:index put:nil.
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  3278
	    timeoutProcessArray at:index put:nil.
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  3279
	].
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  3280
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  3281
	wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
18774
a262834431c7 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18673
diff changeset
  3282
    ]
a262834431c7 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18673
diff changeset
  3283
!
a262834431c7 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18673
diff changeset
  3284
9437
432a4a06934f + timeoutHandlerProcess
ca
parents: 9295
diff changeset
  3285
timeoutHandlerProcess
9452
921f2690dfe6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9450
diff changeset
  3286
    (timeoutHandlerProcess isNil or:[timeoutHandlerProcess isDead]) ifTrue:[
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  3287
	timeoutHandlerProcess :=
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  3288
		[
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  3289
		    [
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  3290
			self timeoutHandlerProcessLoop.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  3291
		    ] ensure:[
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  3292
			timeoutHandlerProcess := nil
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  3293
		    ].
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  3294
		] newProcess.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  3295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  3296
	timeoutHandlerProcess
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  3297
	    priority:TimingPriority;
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  3298
	    name:'timeout handler';
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  3299
	    beSystemProcess;
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  3300
	    resume.
9437
432a4a06934f + timeoutHandlerProcess
ca
parents: 9295
diff changeset
  3301
    ].
432a4a06934f + timeoutHandlerProcess
ca
parents: 9295
diff changeset
  3302
    ^ timeoutHandlerProcess.
9450
cc3954feef43 timeoutHandler clearing
Claus Gittinger <cg@exept.de>
parents: 9437
diff changeset
  3303
9452
921f2690dfe6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9450
diff changeset
  3304
    "Modified: / 20-07-2006 / 09:52:27 / cg"
9437
432a4a06934f + timeoutHandlerProcess
ca
parents: 9295
diff changeset
  3305
!
432a4a06934f + timeoutHandlerProcess
ca
parents: 9295
diff changeset
  3306
432a4a06934f + timeoutHandlerProcess
ca
parents: 9295
diff changeset
  3307
timeoutHandlerProcessLoop
10489
e55d1a27d02b Mark timeoutHandlerProcess as system process
Stefan Vogel <sv@exept.de>
parents: 10435
diff changeset
  3308
    "The timeoutHandlerProcess does nothing but wait.
19850
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  3309
     It exists only, so that timeout blocks may be executed in its context
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  3310
     (i.e. it will always just wait forever, and perform timeout actions
19859
000d1c4aa7e6 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19858
diff changeset
  3311
     in its interrupt handler)."
14775
fa2e7d4afdef class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 14771
diff changeset
  3312
20887
65afdf8260e3 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 20884
diff changeset
  3313
    |mySema|
65afdf8260e3 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 20884
diff changeset
  3314
65afdf8260e3 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 20884
diff changeset
  3315
    mySema := Semaphore new name:'timeoutHandler'.
16538
1a94d96f14d9 class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16514
diff changeset
  3316
    [
20887
65afdf8260e3 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 20884
diff changeset
  3317
        [
65afdf8260e3 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 20884
diff changeset
  3318
            mySema wait.
65afdf8260e3 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 20884
diff changeset
  3319
        ] on:Exception do:[:ex|
65afdf8260e3 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 20884
diff changeset
  3320
            "/ an error occurred in one of the timeout actions.
65afdf8260e3 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 20884
diff changeset
  3321
            
65afdf8260e3 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 20884
diff changeset
  3322
            "ignore errors, but tell the user"
65afdf8260e3 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 20884
diff changeset
  3323
            InfoPrinting == true ifTrue:[
65afdf8260e3 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 20884
diff changeset
  3324
                ('ProcessorScheduler [warning]: error while handling timeouts in TimeoutHandlerProcess: ''' , ex description , '''') infoPrintCR.
65afdf8260e3 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 20884
diff changeset
  3325
                thisContext fullPrintAll.
65afdf8260e3 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 20884
diff changeset
  3326
            ].
65afdf8260e3 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 20884
diff changeset
  3327
        ].
16538
1a94d96f14d9 class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16514
diff changeset
  3328
    ] loop.
10
claus
parents: 3
diff changeset
  3329
! !
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3330
6619
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
  3331
!ProcessorScheduler methodsFor:'wait hooks'!
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
  3332
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
  3333
addPreWaitAction:aBlock
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
  3334
    "add the argument, aBlock to the list of preWait-actions.
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
  3335
     These blocks are evaluated right before the CPU is given up for the OS-wait.
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
  3336
     (i.e. the OS-wait for next event or timeout).
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
  3337
     Systems with buffered output (i.e. Xlib) can install a flush-block here,
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
  3338
     to force unflushed output to be sent out in regular intervals)"
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
  3339
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
  3340
    |wasBlocked|
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
  3341
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
  3342
    wasBlocked := OperatingSystem blockInterrupts.
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
  3343
    preWaitActions isNil ifTrue:[
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  3344
	preWaitActions := OrderedCollection new
6619
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
  3345
    ].
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
  3346
    preWaitActions add:aBlock.
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
  3347
    wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
  3348
!
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
  3349
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
  3350
removePreWaitAction:aBlock
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
  3351
    "remove the argument, aBlock from the list of preWait-actions."
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
  3352
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
  3353
    |wasBlocked|
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
  3354
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
  3355
    wasBlocked := OperatingSystem blockInterrupts.
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
  3356
    preWaitActions notNil ifTrue:[
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
  3357
       preWaitActions removeIdentical:aBlock ifAbsent:nil
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
  3358
    ].
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
  3359
    wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
  3360
! !
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
  3361
10
claus
parents: 3
diff changeset
  3362
!ProcessorScheduler methodsFor:'waiting'!
claus
parents: 3
diff changeset
  3363
20722
0eeb9a61979f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20713
diff changeset
  3364
checkForEndOfDispatch
20736
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  3365
    |wasBlocked|
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  3366
    
20722
0eeb9a61979f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20713
diff changeset
  3367
    exitWhenNoMoreUserProcesses ifTrue:[
0eeb9a61979f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20713
diff changeset
  3368
        "/ check if there are any processes at all
0eeb9a61979f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20713
diff changeset
  3369
        "/ stop dispatching if there is none
0eeb9a61979f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20713
diff changeset
  3370
        "/ (and anyTimeouts is false, which means that no timeout blocks are present)
0eeb9a61979f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20713
diff changeset
  3371
        "/ and no readSemaphores are present (which means that noone is waiting for input)
0eeb9a61979f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20713
diff changeset
  3372
        "/ and no writeSemaphores are present
20736
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  3373
        wasBlocked := OperatingSystem blockInterrupts.
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  3374
20884
a09b61740576 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20883
diff changeset
  3375
        "/ 'scheduled: ' _errorPrint. self anyScheduledWindowGroupAtAll asString _errorPrintCR.
a09b61740576 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20883
diff changeset
  3376
        "/ 'anyUserProcess: ' _errorPrint. self anyUserProcessAtAll asString _errorPrintCR.
20881
6a895fbce7d6 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20869
diff changeset
  3377
        
20754
6d076c61a915 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20753
diff changeset
  3378
        self anyScheduledWindowGroupAtAll ifFalse:[
6d076c61a915 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20753
diff changeset
  3379
            self anyUserProcessAtAll ifFalse:[
20756
14201f1661e9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20754
diff changeset
  3380
                Smalltalk verbose ifTrue:[
14201f1661e9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20754
diff changeset
  3381
                    'Processor [info]: end of dispatch' infoPrintCR.
14201f1661e9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20754
diff changeset
  3382
                ].
20754
6d076c61a915 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20753
diff changeset
  3383
                dispatching := false.
20884
a09b61740576 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20883
diff changeset
  3384
                "/ false ifTrue:[
a09b61740576 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20883
diff changeset
  3385
                "/     MiniInspector basicNew printInstVarsOf:self.
a09b61740576 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20883
diff changeset
  3386
                "/     MiniDebugger enter:thisContext withMessage:'about to exit' mayProceed:true.
a09b61740576 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20883
diff changeset
  3387
                "/ ].
20754
6d076c61a915 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20753
diff changeset
  3388
            ].
20722
0eeb9a61979f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20713
diff changeset
  3389
        ].
20736
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  3390
        
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  3391
        wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
20722
0eeb9a61979f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20713
diff changeset
  3392
    ].
0eeb9a61979f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20713
diff changeset
  3393
!
0eeb9a61979f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20713
diff changeset
  3394
7510
46a848d466b5 select: wake up readFDs if readable only;
Claus Gittinger <cg@exept.de>
parents: 7495
diff changeset
  3395
checkForIOWithTimeout:millis
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  3396
    "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
  3397
     hard wait for either input to arrive, or output to be possible
46a848d466b5 select: wake up readFDs if readable only;
Claus Gittinger <cg@exept.de>
parents: 7495
diff changeset
  3398
     or a timeout to occur."
46a848d466b5 select: wake up readFDs if readable only;
Claus Gittinger <cg@exept.de>
parents: 7495
diff changeset
  3399
46a848d466b5 select: wake up readFDs if readable only;
Claus Gittinger <cg@exept.de>
parents: 7495
diff changeset
  3400
    |nReady index sema action wasBlocked err fd readyIndex
18957
e0bb91eae748 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18941
diff changeset
  3401
     newProcessMaybeReady fdOrPid exceptArray|
2116
1bcb6ee86fca fixed pending sigChild problem;
Claus Gittinger <cg@exept.de>
parents: 2111
diff changeset
  3402
1bcb6ee86fca fixed pending sigChild problem;
Claus Gittinger <cg@exept.de>
parents: 2111
diff changeset
  3403
    "/ must enable interrupts, to be able to get out of a
1bcb6ee86fca fixed pending sigChild problem;
Claus Gittinger <cg@exept.de>
parents: 2111
diff changeset
  3404
    "/ long wait (especially, to handle sigChild in the meantime)
1bcb6ee86fca fixed pending sigChild problem;
Claus Gittinger <cg@exept.de>
parents: 2111
diff changeset
  3405
8504
93b46834c68f #unblockInterrupts returns the prvious blocking state
Stefan Vogel <sv@exept.de>
parents: 8494
diff changeset
  3406
    wasBlocked := OperatingSystem unblockInterrupts.
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  3407
7493
5c67c45b11cb New select for fair scheduling (not giving low filedescriptors
Stefan Vogel <sv@exept.de>
parents: 7264
diff changeset
  3408
    newProcessMaybeReady := false.
14943
141d20b16378 class: ProcessorScheduler
Claus Gittinger <cg@exept.de>
parents: 14780
diff changeset
  3409
    readableResultFdArray size < readFdArray size ifTrue:[
19850
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  3410
	readableResultFdArray := Array new:(40 max:readFdArray size).
14943
141d20b16378 class: ProcessorScheduler
Claus Gittinger <cg@exept.de>
parents: 14780
diff changeset
  3411
    ].
141d20b16378 class: ProcessorScheduler
Claus Gittinger <cg@exept.de>
parents: 14780
diff changeset
  3412
    writableResultFdArray size < writeFdArray size ifTrue:[
19850
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  3413
	writableResultFdArray := Array new:(40 max:writeFdArray size).
14943
141d20b16378 class: ProcessorScheduler
Claus Gittinger <cg@exept.de>
parents: 14780
diff changeset
  3414
    ].
7510
46a848d466b5 select: wake up readFDs if readable only;
Claus Gittinger <cg@exept.de>
parents: 7495
diff changeset
  3415
18957
e0bb91eae748 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18941
diff changeset
  3416
    exceptArray := exceptFdArray.
e0bb91eae748 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18941
diff changeset
  3417
16858
39f5a709a6ff class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16857
diff changeset
  3418
    OperatingSystem isMSWINDOWSlike ifTrue:[
19850
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  3419
	"/
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  3420
	"/ win32 does a WaitForMultipleObjects in select...
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  3421
	"/ unix waits for SIGCHLD
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  3422
	"/
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  3423
	|hasPids|
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  3424
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  3425
	hasPids := false.
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  3426
	osChildExitActions keysDo:[:eachPid|
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  3427
	    eachPid address = 0 ifTrue:[
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  3428
		'Processor: remove 0-handle pid: ' infoPrint. eachPid infoPrintCR.
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  3429
		osChildExitActions safeRemoveKey:eachPid.
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  3430
	    ] ifFalse:[
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  3431
		hasPids := true.
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  3432
	    ].
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  3433
	].
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  3434
	hasPids ifTrue:[
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  3435
	    exceptArray := (exceptArray upTo:nil), osChildExitActions keys asArray.
18957
e0bb91eae748 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18941
diff changeset
  3436
"/'exceptArray: ' print. exceptArray printCR.
19850
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  3437
	].
16338
b8defcce7efc class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16322
diff changeset
  3438
    ].
b8defcce7efc class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16322
diff changeset
  3439
18957
e0bb91eae748 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18941
diff changeset
  3440
    exceptResultFdArray size < exceptArray size ifTrue:[
19850
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  3441
	exceptResultFdArray := Array new:(40 max:exceptArray size).
18957
e0bb91eae748 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18941
diff changeset
  3442
    ].
e0bb91eae748 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18941
diff changeset
  3443
7510
46a848d466b5 select: wake up readFDs if readable only;
Claus Gittinger <cg@exept.de>
parents: 7495
diff changeset
  3444
    nReady := OperatingSystem
19850
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  3445
		selectOnAnyReadable:readFdArray
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  3446
		writable:writeFdArray
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  3447
		exception:exceptArray
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  3448
		readableInto:readableResultFdArray
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  3449
		writableInto:writableResultFdArray
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  3450
		exceptionInto:exceptResultFdArray
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  3451
		withTimeOut:millis.
1061
61012b7bed9c protect myself against invalid fd's in readFdArray/writeFdArray
Claus Gittinger <cg@exept.de>
parents: 1042
diff changeset
  3452
2116
1bcb6ee86fca fixed pending sigChild problem;
Claus Gittinger <cg@exept.de>
parents: 2111
diff changeset
  3453
    wasBlocked ifTrue:[
19850
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  3454
	OperatingSystem blockInterrupts.
2116
1bcb6ee86fca fixed pending sigChild problem;
Claus Gittinger <cg@exept.de>
parents: 2111
diff changeset
  3455
    ].
1bcb6ee86fca fixed pending sigChild problem;
Claus Gittinger <cg@exept.de>
parents: 2111
diff changeset
  3456
11836
0d70352a70bc Avoid blocking in PipeStream (e.g. when doing a CVS checkin)
Stefan Vogel <sv@exept.de>
parents: 11622
diff changeset
  3457
    nReady <= 0 ifTrue:[
19850
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  3458
	"/ either still nothing to do,
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  3459
	"/ or error (which should not happen)
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  3460
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  3461
	(nReady < 0 and:[(err := OperatingSystem lastErrorSymbol) notNil]) ifTrue:[
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  3462
	    err == #EBADF ifTrue:[
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  3463
		"/ mhmh - one of the fd's given to me is corrupt.
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  3464
		"/ find out which one .... and remove it
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  3465
		self removeCorruptedFds
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  3466
	    ] ifFalse:[
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  3467
		err == #ENOENT ifTrue:[
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  3468
		    'Processor [warning]: ENOENT in select; rd=' infoPrint.
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  3469
		    readFdArray infoPrint. ' wr=' infoPrint. writeFdArray infoPrintCR.
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  3470
		] ifFalse:[
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  3471
		    'Processor [warning]: error in select: ' infoPrint. err infoPrintCR.
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  3472
		]
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  3473
	    ].
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  3474
	]
1061
61012b7bed9c protect myself against invalid fd's in readFdArray/writeFdArray
Claus Gittinger <cg@exept.de>
parents: 1042
diff changeset
  3475
    ] ifFalse:[
19850
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  3476
	readyIndex := 1.
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  3477
	[nReady > 0
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  3478
	     and:[ readyIndex <= readableResultFdArray size
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  3479
	     and:[ (fd := readableResultFdArray at:readyIndex) notNil ]]
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  3480
	] whileTrue:[
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  3481
	    index := readFdArray identityIndexOf:fd.
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  3482
	    index ~~ 0 ifTrue:[
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  3483
		action := readCheckArray at:index.
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  3484
		sema := readSemaphoreArray at:index.
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  3485
		sema notNil ifTrue:[
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  3486
		    sema signalOnce.
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  3487
		    newProcessMaybeReady := true.
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  3488
		    action isNil ifTrue:[
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  3489
			"before May 2014 we disabled the sema in the caller after wakeup.
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  3490
			 This caused ST/X to consume 100% cpu, when the caller didn't read
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  3491
			 the data (e.g. because his process was stopped)."
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  3492
			"disable possible write side and timeouts as well"
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  3493
			self disableSemaphore:sema.
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  3494
		    ].
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  3495
		].
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  3496
		(action notNil and:[action value]) ifTrue:[
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  3497
		    newProcessMaybeReady := true.
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  3498
		].
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  3499
	    ].
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  3500
	    nReady := nReady - 1.
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  3501
	    readyIndex := readyIndex + 1.
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  3502
	].
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  3503
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  3504
	readyIndex := 1.
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  3505
	[nReady > 0
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  3506
	     and:[ readyIndex <= writableResultFdArray size
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  3507
	     and:[ (fd := writableResultFdArray at:readyIndex) notNil ]]
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  3508
	] whileTrue:[
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  3509
	    index := writeFdArray identityIndexOf:fd.
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  3510
	    index ~~ 0 ifTrue:[
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  3511
		action := writeCheckArray at:index.
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  3512
		sema := writeSemaphoreArray at:index.
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  3513
		sema notNil ifTrue:[
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  3514
		    sema signalOnce.
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  3515
		    newProcessMaybeReady := true.
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  3516
		    action isNil ifTrue:[
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  3517
			"now this is a one shot operation - see the input above"
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  3518
			"disable possible read side and timeouts as well"
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  3519
			self disableSemaphore:sema.
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  3520
		    ].
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  3521
		].
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  3522
		(action notNil and:[action value]) ifTrue:[
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  3523
		    newProcessMaybeReady := true.
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  3524
		].
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  3525
	    ].
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  3526
	    nReady := nReady - 1.
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  3527
	    readyIndex := readyIndex + 1.
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  3528
	].
18957
e0bb91eae748 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18941
diff changeset
  3529
e0bb91eae748 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18941
diff changeset
  3530
"/'except result got: ' print. exceptArray printCR. exceptResultFdArray printCR.
19850
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  3531
	readyIndex := 1.
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  3532
	[nReady > 0
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  3533
	     and:[ readyIndex <= exceptResultFdArray size
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  3534
	     and:[ (fdOrPid := exceptResultFdArray at:readyIndex) notNil ]]
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  3535
	] whileTrue:[
18957
e0bb91eae748 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18941
diff changeset
  3536
"/'except got: ' print. fdOrPid printCR.
19850
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  3537
	    index := exceptFdArray identityIndexOf:fdOrPid.
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  3538
	    index ~~ 0 ifTrue:[
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  3539
		sema := exceptSemaphoreArray at:index.
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  3540
		sema notNil ifTrue:[
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  3541
		    sema signalOnce.
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  3542
		    newProcessMaybeReady := true.
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  3543
		    "disable possible read/write side and timeouts as well"
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  3544
		    self disableSemaphore:sema.
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  3545
		].
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  3546
	    ] ifFalse:[ "may be a PID?"
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  3547
		|osProcessStatus actionBlock|
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  3548
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  3549
		actionBlock := osChildExitActions removeKey:fdOrPid ifAbsent:nil.
18957
e0bb91eae748 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18941
diff changeset
  3550
"/'pid signaled: ' print. fdOrPid printCR.
19850
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  3551
		actionBlock notNil ifTrue:[
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  3552
		    osProcessStatus := OperatingSystem childProcessWait:false pid:fdOrPid.
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  3553
		    (osProcessStatus notNil and:[osProcessStatus pid = fdOrPid]) ifTrue:[
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  3554
			actionBlock value:osProcessStatus.
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  3555
			newProcessMaybeReady := true.
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  3556
		    ].
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  3557
		].
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  3558
	    ].
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  3559
	    nReady := nReady - 1.
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  3560
	    readyIndex := readyIndex + 1.
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  3561
	].
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  3562
    ].
7493
5c67c45b11cb New select for fair scheduling (not giving low filedescriptors
Stefan Vogel <sv@exept.de>
parents: 7264
diff changeset
  3563
    ^ 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
  3564
10233
4006fa954217 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9991
diff changeset
  3565
    "Modified: / 12-04-1996 / 09:31:22 / stefan"
10269
c9eae9f888c7 changed #checkForIOWithTimeout:
Claus Gittinger <cg@exept.de>
parents: 10268
diff changeset
  3566
    "Modified: / 07-12-2006 / 19:48:17 / cg"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  3567
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  3568
10
claus
parents: 3
diff changeset
  3569
ioInterrupt
1787
32632b6f969d remember threadSwitch:from: idea for later implementation;
Claus Gittinger <cg@exept.de>
parents: 1783
diff changeset
  3570
    "{ Pragma: +returnable }"
32632b6f969d remember threadSwitch:from: idea for later implementation;
Claus Gittinger <cg@exept.de>
parents: 1783
diff changeset
  3571
10747
e9ea71d01445 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10497
diff changeset
  3572
    "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
  3573
     what to do now.
be7402f74d94 hide timerInterrupt & ioInterrupt contexts when switching
Claus Gittinger <cg@exept.de>
parents: 1780
diff changeset
  3574
     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
  3575
     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
  3576
     of whichever process is currently running."
10
claus
parents: 3
diff changeset
  3577
804
264d440a67a0 Fixes when useIOInterrupts == true.
Stefan Vogel <sv@exept.de>
parents: 786
diff changeset
  3578
    gotIOInterrupt := true.
2966
856dfc8a294a lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2962
diff changeset
  3579
    activeProcess ~~ scheduler ifTrue:[
20706
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  3580
	interruptCounter := interruptCounter + 1 bitAnd:SmallInteger maxVal.
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  3581
	interruptedProcess := activeProcess.
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  3582
	self threadSwitch:scheduler
2966
856dfc8a294a lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2962
diff changeset
  3583
    ]
804
264d440a67a0 Fixes when useIOInterrupts == true.
Stefan Vogel <sv@exept.de>
parents: 786
diff changeset
  3584
264d440a67a0 Fixes when useIOInterrupts == true.
Stefan Vogel <sv@exept.de>
parents: 786
diff changeset
  3585
    "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
  3586
    "Modified: 4.8.1997 / 14:23:08 / cg"
10
claus
parents: 3
diff changeset
  3587
!
claus
parents: 3
diff changeset
  3588
1086
7b0641a2e1ef nicer message
Claus Gittinger <cg@exept.de>
parents: 1061
diff changeset
  3589
removeCorruptedFds
10747
e9ea71d01445 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10497
diff changeset
  3590
    "this is sent when select returns an error due to some invalid
e9ea71d01445 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10497
diff changeset
  3591
     fileDescriptor. May happen, if someone does a readWait/writeWait on a
e9ea71d01445 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10497
diff changeset
  3592
     socket connection, which somehow got corrupted
2280
aca71c89f32c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2269
diff changeset
  3593
     (shutdown by partner, or closed by another thread, while being in a read/write-wait).
10747
e9ea71d01445 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10497
diff changeset
  3594
     Without special care, all following selects would immediately return with
1086
7b0641a2e1ef nicer message
Claus Gittinger <cg@exept.de>
parents: 1061
diff changeset
  3595
     an #EBADF error, leading to high-frequency polling and a locked up system.
7b0641a2e1ef nicer message
Claus Gittinger <cg@exept.de>
parents: 1061
diff changeset
  3596
     (you could still fix things by interrupting on the console and fixing the
7b0641a2e1ef nicer message
Claus Gittinger <cg@exept.de>
parents: 1061
diff changeset
  3597
      readFdArray/writeFdArray in the debugger)"
7b0641a2e1ef nicer message
Claus Gittinger <cg@exept.de>
parents: 1061
diff changeset
  3598
7b0641a2e1ef nicer message
Claus Gittinger <cg@exept.de>
parents: 1061
diff changeset
  3599
    readFdArray keysAndValuesDo:[:idx :fd |
20706
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  3600
	|result sema|
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  3601
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  3602
	fd notNil ifTrue:[
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  3603
	    result := OperatingSystem
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  3604
			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
  3605
			   readableInto:nil writableInto:nil exceptionInto:nil
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  3606
			   withTimeOut:0.
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  3607
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  3608
	    result < 0 ifTrue:[
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  3609
		'Processor [info]: removing invalid read-select fileDescriptor: ' infoPrint. fd infoPrint. ' idx: 'infoPrint. idx infoPrintCR.
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  3610
		readFdArray at:idx put:nil.
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  3611
		readCheckArray at:idx put:nil.
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  3612
		(sema := readSemaphoreArray at:idx) notNil ifTrue:[
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  3613
		    readSemaphoreArray at:idx put:nil.
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  3614
		    self removeTimeoutForSemaphore:sema.
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  3615
		    sema signalForAll.
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  3616
		].
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  3617
	    ]
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  3618
	].
1086
7b0641a2e1ef nicer message
Claus Gittinger <cg@exept.de>
parents: 1061
diff changeset
  3619
    ].
7b0641a2e1ef nicer message
Claus Gittinger <cg@exept.de>
parents: 1061
diff changeset
  3620
7b0641a2e1ef nicer message
Claus Gittinger <cg@exept.de>
parents: 1061
diff changeset
  3621
    writeFdArray keysAndValuesDo:[:idx :fd |
20706
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  3622
	|result sema|
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  3623
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  3624
	fd notNil ifTrue:[
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  3625
	    result := OperatingSystem
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  3626
			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
  3627
			   readableInto:nil writableInto:nil exceptionInto:nil
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  3628
			   withTimeOut:0.
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  3629
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  3630
	    result < 0 ifTrue:[
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  3631
		'Processor [info]: removing invalid write-select fileDescriptor: ' infoPrint. fd infoPrint. ' idx: 'infoPrint. idx infoPrintCR.
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  3632
		writeFdArray at:idx put:nil.
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  3633
		writeCheckArray at:idx put:nil.
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  3634
		(sema := writeSemaphoreArray at:idx) notNil ifTrue:[
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  3635
		    writeSemaphoreArray at:idx put:nil.
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  3636
		    self removeTimeoutForSemaphore:sema.
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  3637
		    sema signalForAll.
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  3638
		].
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  3639
	    ]
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  3640
	]
1086
7b0641a2e1ef nicer message
Claus Gittinger <cg@exept.de>
parents: 1061
diff changeset
  3641
    ].
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
  3642
18957
e0bb91eae748 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18941
diff changeset
  3643
    exceptFdArray keysAndValuesDo:[:idx :fd |
20706
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  3644
	|result sema|
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  3645
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  3646
	fd notNil ifTrue:[
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  3647
	    result := OperatingSystem
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  3648
			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
  3649
			   readableInto:nil writableInto:nil exceptionInto:nil
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  3650
			   withTimeOut:0.
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  3651
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  3652
	    result < 0 ifTrue:[
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  3653
		'Processor [info]: removing invalid exception-select fileDescriptor: ' infoPrint. fd infoPrint. ' idx: 'infoPrint. idx infoPrintCR.
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  3654
		exceptFdArray at:idx put:nil.
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  3655
		(sema := exceptSemaphoreArray at:idx) notNil ifTrue:[
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  3656
		    exceptSemaphoreArray at:idx put:nil.
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  3657
		    self removeTimeoutForSemaphore:sema.
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  3658
		    sema signalForAll.
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  3659
		].
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  3660
	    ]
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  3661
	]
18957
e0bb91eae748 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18941
diff changeset
  3662
    ].
e0bb91eae748 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18941
diff changeset
  3663
e0bb91eae748 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18941
diff changeset
  3664
16858
39f5a709a6ff class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16857
diff changeset
  3665
    OperatingSystem isMSWINDOWSlike ifTrue:[
20706
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  3666
	"/
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  3667
	"/ win32 does a WaitForMultipleObjects in select...
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  3668
	"/ unix waits for SIGCHLD
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  3669
	"/
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  3670
	osChildExitActions keysDo:[:eachPid |
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  3671
	    |result sema|
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  3672
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  3673
	    eachPid notNil ifTrue:[
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  3674
		result := OperatingSystem
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  3675
			    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
  3676
			       readableInto:nil writableInto:nil exceptionInto:nil
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  3677
			       withTimeOut:0.
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  3678
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  3679
		result < 0 ifTrue:[
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  3680
		    'Processor [info]: removing invalid exception-select pid: ' infoPrint. eachPid infoPrintCR.
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  3681
		    osChildExitActions safeRemoveKey:eachPid.
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  3682
		]
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  3683
	    ]
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  3684
	].
16338
b8defcce7efc class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16322
diff changeset
  3685
    ].
b8defcce7efc class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16322
diff changeset
  3686
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
  3687
    "Modified: 12.4.1996 / 09:32:58 / stefan"
2280
aca71c89f32c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2269
diff changeset
  3688
    "Modified: 27.1.1997 / 20:09:27 / cg"
1086
7b0641a2e1ef nicer message
Claus Gittinger <cg@exept.de>
parents: 1061
diff changeset
  3689
!
7b0641a2e1ef nicer message
Claus Gittinger <cg@exept.de>
parents: 1061
diff changeset
  3690
750
f4ed622893ce added schedulerInterrupt - for soon to come semaSignal primitive function
Claus Gittinger <cg@exept.de>
parents: 699
diff changeset
  3691
schedulerInterrupt
f4ed622893ce added schedulerInterrupt - for soon to come semaSignal primitive function
Claus Gittinger <cg@exept.de>
parents: 699
diff changeset
  3692
    "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
  3693
     what to do now."
f4ed622893ce added schedulerInterrupt - for soon to come semaSignal primitive function
Claus Gittinger <cg@exept.de>
parents: 699
diff changeset
  3694
2966
856dfc8a294a lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2962
diff changeset
  3695
    activeProcess ~~ scheduler ifTrue:[
20706
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  3696
	interruptCounter := interruptCounter + 1 bitAnd:SmallInteger maxVal.
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  3697
	interruptedProcess := activeProcess.
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  3698
	self threadSwitch:scheduler
2966
856dfc8a294a lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2962
diff changeset
  3699
    ]
750
f4ed622893ce added schedulerInterrupt - for soon to come semaSignal primitive function
Claus Gittinger <cg@exept.de>
parents: 699
diff changeset
  3700
!
f4ed622893ce added schedulerInterrupt - for soon to come semaSignal primitive function
Claus Gittinger <cg@exept.de>
parents: 699
diff changeset
  3701
10
claus
parents: 3
diff changeset
  3702
timeToNextTimeout
claus
parents: 3
diff changeset
  3703
    "return the delta-T (in millis) to next timeout, or nil if
claus
parents: 3
diff changeset
  3704
     there is none"
claus
parents: 3
diff changeset
  3705
231
fd0e55e352f8 cleanup
claus
parents: 217
diff changeset
  3706
    |aTime now delta minDelta n "{ Class: SmallInteger }"|
10
claus
parents: 3
diff changeset
  3707
claus
parents: 3
diff changeset
  3708
    "find next timeout. since there are usually not many, just search.
302
1f76060d58a4 *** empty log message ***
claus
parents: 271
diff changeset
  3709
     If there were many, the list should be kept sorted ... keeping deltas
10
claus
parents: 3
diff changeset
  3710
     to next (as in Unix kernel)"
claus
parents: 3
diff changeset
  3711
231
fd0e55e352f8 cleanup
claus
parents: 217
diff changeset
  3712
    n := timeoutArray size.
10
claus
parents: 3
diff changeset
  3713
    1 to:n do:[:index |
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  3714
	aTime := timeoutArray at:index.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  3715
	aTime notNil ifTrue:[
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  3716
	    now isNil ifTrue:[
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  3717
		now := OperatingSystem getMillisecondTime.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  3718
	    ].
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  3719
	    delta := OperatingSystem millisecondTimeDeltaBetween:aTime and:now.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  3720
	    delta <= 0 ifTrue:[
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  3721
		^ 0.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  3722
	    ].
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  3723
	    minDelta isNil ifTrue:[
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  3724
		minDelta := delta
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  3725
	    ] ifFalse:[
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  3726
		minDelta := minDelta min:delta
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  3727
	    ]
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  3728
	]
15634
9ace007bd248 class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 15581
diff changeset
  3729
    ].
9ace007bd248 class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 15581
diff changeset
  3730
    minDelta isNil ifTrue:[
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  3731
	"this is safe, since always called with interruptsBlocked"
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  3732
	anyTimeouts := false.
10
claus
parents: 3
diff changeset
  3733
    ].
claus
parents: 3
diff changeset
  3734
claus
parents: 3
diff changeset
  3735
    ^ minDelta
claus
parents: 3
diff changeset
  3736
!
claus
parents: 3
diff changeset
  3737
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  3738
timerInterrupt
1787
32632b6f969d remember threadSwitch:from: idea for later implementation;
Claus Gittinger <cg@exept.de>
parents: 1783
diff changeset
  3739
    "{ Pragma: +returnable }"
32632b6f969d remember threadSwitch:from: idea for later implementation;
Claus Gittinger <cg@exept.de>
parents: 1783
diff changeset
  3740
10747
e9ea71d01445 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10497
diff changeset
  3741
    "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
  3742
     what to do now.
be7402f74d94 hide timerInterrupt & ioInterrupt contexts when switching
Claus Gittinger <cg@exept.de>
parents: 1780
diff changeset
  3743
     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
  3744
     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
  3745
     of whichever process is currently running."
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  3746
2966
856dfc8a294a lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2962
diff changeset
  3747
    activeProcess ~~ scheduler ifTrue:[
20706
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  3748
	interruptCounter := interruptCounter + 1 bitAnd:SmallInteger maxVal.
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  3749
	interruptedProcess := activeProcess.
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  3750
	self threadSwitch:scheduler
2966
856dfc8a294a lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2962
diff changeset
  3751
    ]
1783
be7402f74d94 hide timerInterrupt & ioInterrupt contexts when switching
Claus Gittinger <cg@exept.de>
parents: 1780
diff changeset
  3752
be7402f74d94 hide timerInterrupt & ioInterrupt contexts when switching
Claus Gittinger <cg@exept.de>
parents: 1780
diff changeset
  3753
    "Modified: 18.10.1996 / 20:35:54 / cg"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  3754
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  3755
10
claus
parents: 3
diff changeset
  3756
waitForEventOrTimeout
44
b262907c93ea *** empty log message ***
claus
parents: 42
diff changeset
  3757
    "entered when no process is runnable - wait for either input on
b262907c93ea *** empty log message ***
claus
parents: 42
diff changeset
  3758
     any file descriptors to arrive or a timeout to happen.
b262907c93ea *** empty log message ***
claus
parents: 42
diff changeset
  3759
     If it makes sense, do some background garbage collection.
b262907c93ea *** empty log message ***
claus
parents: 42
diff changeset
  3760
     The idle actions are a leftover from previous ST/X releases and will
93
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
  3761
     vanish (installing a low-prio process has the same effect)."
44
b262907c93ea *** empty log message ***
claus
parents: 42
diff changeset
  3762
18670
34a2526aa029 class: ProcessorScheduler
Claus Gittinger <cg@exept.de>
parents: 18620
diff changeset
  3763
    |millis doingGC dT|
10
claus
parents: 3
diff changeset
  3764
claus
parents: 3
diff changeset
  3765
    doingGC := true.
claus
parents: 3
diff changeset
  3766
    [doingGC] whileTrue:[
20722
0eeb9a61979f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20713
diff changeset
  3767
        anyTimeouts ifTrue:[
0eeb9a61979f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20713
diff changeset
  3768
            millis := self timeToNextTimeout.
0eeb9a61979f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20713
diff changeset
  3769
            (millis notNil and:[millis <= 0]) ifTrue:[
0eeb9a61979f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20713
diff changeset
  3770
                ^ self    "oops - hurry up checking"
0eeb9a61979f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20713
diff changeset
  3771
            ].
0eeb9a61979f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20713
diff changeset
  3772
        ].
0eeb9a61979f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20713
diff changeset
  3773
0eeb9a61979f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20713
diff changeset
  3774
        "
0eeb9a61979f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20713
diff changeset
  3775
         if its worth doing, collect a bit of garbage;
0eeb9a61979f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20713
diff changeset
  3776
         but not, if a backgroundCollector is active
0eeb9a61979f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20713
diff changeset
  3777
        "
0eeb9a61979f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20713
diff changeset
  3778
        ObjectMemory backgroundCollectorRunning ifTrue:[
0eeb9a61979f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20713
diff changeset
  3779
            doingGC := false
0eeb9a61979f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20713
diff changeset
  3780
        ] ifFalse:[
0eeb9a61979f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20713
diff changeset
  3781
            doingGC := ObjectMemory gcStepIfUseful.
0eeb9a61979f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20713
diff changeset
  3782
        ].
0eeb9a61979f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20713
diff changeset
  3783
0eeb9a61979f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20713
diff changeset
  3784
        "then do idle actions"
0eeb9a61979f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20713
diff changeset
  3785
        (idleActions notNil and:[idleActions size ~~ 0]) ifTrue:[
0eeb9a61979f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20713
diff changeset
  3786
            idleActions do:[:aBlock |
0eeb9a61979f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20713
diff changeset
  3787
                aBlock value.
0eeb9a61979f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20713
diff changeset
  3788
            ].
0eeb9a61979f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20713
diff changeset
  3789
            ^ self   "go back checking"
0eeb9a61979f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20713
diff changeset
  3790
        ].
0eeb9a61979f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20713
diff changeset
  3791
0eeb9a61979f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20713
diff changeset
  3792
        doingGC ifTrue:[
0eeb9a61979f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20713
diff changeset
  3793
            (self checkForIOWithTimeout:0) ifTrue:[
0eeb9a61979f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20713
diff changeset
  3794
                ^ self  "go back checking"
0eeb9a61979f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20713
diff changeset
  3795
            ]
0eeb9a61979f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20713
diff changeset
  3796
        ]
10
claus
parents: 3
diff changeset
  3797
    ].
claus
parents: 3
diff changeset
  3798
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
  3799
    exitWhenNoMoreUserProcesses ifTrue:[
20722
0eeb9a61979f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20713
diff changeset
  3800
        "/ check if there are any processes at all
0eeb9a61979f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20713
diff changeset
  3801
        "/ stop dispatching if there is none
0eeb9a61979f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20713
diff changeset
  3802
        "/ (and anyTimeouts is false, which means that no timeout blocks are present)
0eeb9a61979f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20713
diff changeset
  3803
        "/ and no readSemaphores are present (which means that noone is waiting for input)
0eeb9a61979f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20713
diff changeset
  3804
        "/ and no writeSemaphores are present
20869
86fa4bf29d65 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20810
diff changeset
  3805
        
86fa4bf29d65 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20810
diff changeset
  3806
        "/ cg: changed to only check when a process terminated
86fa4bf29d65 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20810
diff changeset
  3807
        "/ self checkForEndOfDispatch.
20722
0eeb9a61979f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20713
diff changeset
  3808
        dispatching ifFalse:[
0eeb9a61979f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20713
diff changeset
  3809
            ^ self
0eeb9a61979f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20713
diff changeset
  3810
        ].
6619
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
  3811
    ].
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
  3812
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
  3813
    preWaitActions notNil ifTrue:[
20722
0eeb9a61979f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20713
diff changeset
  3814
        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
  3815
    ].
10
claus
parents: 3
diff changeset
  3816
1627
f95285226059 infoPrint for NT (no select)
Claus Gittinger <cg@exept.de>
parents: 1618
diff changeset
  3817
    "/
f95285226059 infoPrint for NT (no select)
Claus Gittinger <cg@exept.de>
parents: 1618
diff changeset
  3818
    "/ absolutely nothing to do - simply wait
f95285226059 infoPrint for NT (no select)
Claus Gittinger <cg@exept.de>
parents: 1618
diff changeset
  3819
    "/
49
f1c2d75f2eb6 *** empty log message ***
claus
parents: 44
diff changeset
  3820
    OperatingSystem supportsSelect ifFalse:[
20722
0eeb9a61979f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20713
diff changeset
  3821
        "SCO instant ShitStation has a bug here,
0eeb9a61979f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20713
diff changeset
  3822
         waiting always 1 sec in the select - therefore we delay a bit and
0eeb9a61979f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20713
diff changeset
  3823
         return - effectively polling in 50ms cycles
0eeb9a61979f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20713
diff changeset
  3824
        "
0eeb9a61979f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20713
diff changeset
  3825
        (self checkForIOWithTimeout:0) ifTrue:[
0eeb9a61979f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20713
diff changeset
  3826
            ^ self  "go back checking"
0eeb9a61979f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20713
diff changeset
  3827
        ].
0eeb9a61979f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20713
diff changeset
  3828
        OperatingSystem millisecondDelay:EventPollingInterval.
0eeb9a61979f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20713
diff changeset
  3829
        ^ self
10
claus
parents: 3
diff changeset
  3830
    ].
claus
parents: 3
diff changeset
  3831
6044
f752aac6b456 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5840
diff changeset
  3832
    useIOInterrupts ifTrue:[
20722
0eeb9a61979f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20713
diff changeset
  3833
        dT := 999999
3745
3fd121f2e74e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3740
diff changeset
  3834
    ] ifFalse:[
20722
0eeb9a61979f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20713
diff changeset
  3835
        dT := EventPollingInterval
3745
3fd121f2e74e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3740
diff changeset
  3836
    ].
3fd121f2e74e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3740
diff changeset
  3837
10
claus
parents: 3
diff changeset
  3838
    millis isNil ifTrue:[
20722
0eeb9a61979f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20713
diff changeset
  3839
        millis := dT.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3840
    ] ifFalse:[
20722
0eeb9a61979f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20713
diff changeset
  3841
        millis := millis rounded min:dT.
10
claus
parents: 3
diff changeset
  3842
    ].
6619
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
  3843
7510
46a848d466b5 select: wake up readFDs if readable only;
Claus Gittinger <cg@exept.de>
parents: 7495
diff changeset
  3844
    self checkForIOWithTimeout:millis
768
20434b8239f3 stefans modalBox changes (no more polling)
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  3845
20434b8239f3 stefans modalBox changes (no more polling)
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  3846
    "Modified: 14.12.1995 / 13:37:46 / stefan"
1576
3f6c39471342 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1575
diff changeset
  3847
    "Modified: 18.7.1996 / 20:42:17 / cg"
10
claus
parents: 3
diff changeset
  3848
! !
claus
parents: 3
diff changeset
  3849
1783
be7402f74d94 hide timerInterrupt & ioInterrupt contexts when switching
Claus Gittinger <cg@exept.de>
parents: 1780
diff changeset
  3850
!ProcessorScheduler class methodsFor:'documentation'!
10
claus
parents: 3
diff changeset
  3851
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  3852
version
18620
b4e9f25d6ce6 preparations for lined index list in WeakArray
Claus Gittinger <cg@exept.de>
parents: 18295
diff changeset
  3853
    ^ '$Header$'
12717
594a44c45567 changed: #vmResumeInterrupt:
Stefan Vogel <sv@exept.de>
parents: 11836
diff changeset
  3854
!
594a44c45567 changed: #vmResumeInterrupt:
Stefan Vogel <sv@exept.de>
parents: 11836
diff changeset
  3855
594a44c45567 changed: #vmResumeInterrupt:
Stefan Vogel <sv@exept.de>
parents: 11836
diff changeset
  3856
version_CVS
18620
b4e9f25d6ce6 preparations for lined index list in WeakArray
Claus Gittinger <cg@exept.de>
parents: 18295
diff changeset
  3857
    ^ '$Header$'
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3858
! !
6939
6f6ea7b0a5ab stopping an suspended process fix
Claus Gittinger <cg@exept.de>
parents: 6807
diff changeset
  3859
14771
c85f3f394aae class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 14442
diff changeset
  3860
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  3861
ProcessorScheduler initialize!