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