ProcessorScheduler.st
author Jan Vrany <jan.vrany@labware.com>
Tue, 01 Jun 2021 20:19:13 +0100
branchjv
changeset 25424 51bd8a6b196f
parent 25422 3b02b0f1f647
child 25429 14ed0c85e7ab
permissions -rw-r--r--
Cherry-picked `Context` cherry-picked Context.st from a6b6dda4caff: * 4aaf30c174e9: #DOCUMENTATION by cg, Claus Gittinger <cg@exept.de> * c67311afcc6c: #OTHER by cg, Claus Gittinger <cg@exept.de> * 883f79e7b2a6: #FEATURE by cg, Claus Gittinger <cg@exept.de> * 716f3fbb09e9: Don't mark contexts with `CATCHMARK`, Jan Vrany <jan.vrany@fit.cvut.cz> * cff24fa817b0: #REFACTORING by stefan, Stefan Vogel <sv@exept.de> * 521f0d837330: #UI_ENHANCEMENT by cg, Claus Gittinger <cg@exept.de> * bf1118f0fcca: #UI_ENHANCEMENT by cg, Claus Gittinger <cg@exept.de> * e587cdd22868: #BUGFIX by cg, Claus Gittinger <cg@exept.de> * fe9f9487a3ed: #DOCUMENTATION by cg, Claus Gittinger <cg@exept.de> * d5b781899274: #BUGFIX by cg, Claus Gittinger <cg@exept.de> * 8258751a7465: #FEATURE by cg, Claus Gittinger <cg@exept.de> * 40173e082cbc: Copyright updates, Jan Vrany <jan.vrany@fit.cvut.cz> * 6db5c28207d5: #UI_ENHANCEMENT by cg, Claus Gittinger <cg@exept.de> * 871ea64fd5dc: #FEATURE by cg, Claus Gittinger <cg@exept.de> * 4b544a108e4e: #DOCUMENTATION by cg, Claus Gittinger <cg@exept.de> * 9a8d8399e566: #FEATURE by cgexept.de, Claus Gittinger <cg@exept.de> * 170b00be0103: #BUGFIX by stefan, Stefan Vogel <sv@exept.de> * a6c73965eae8: #FEATURE by cg, Claus Gittinger <cg@exept.de> * ce2a0e462ff0: #FEATURE by cg, Claus Gittinger <cg@exept.de> * 46a260a9ca92: #FEATURE by cg, Claus Gittinger <cg@exept.de> * 46cab49167fb: #UI_ENHANCEMENT by exept, Claus Gittinger <cg@exept.de> * 7d52dfd3997d: #DOCUMENTATION by exept, Claus Gittinger <cg@exept.de> * c52eeea62763: Fix `Context >> argAndVarNames` in cases when debug info is not available, Jan Vrany <jan.vrany@labware.com> * b5d6963fe4a9: Backed out changeset c52eeea62763, Jan Vrany <jan.vrany@labware.com> * 6fd3896f8703: #FEATURE by exept, Claus Gittinger <cg@exept.de> * b530ee616256: #REFACTORING by cg, Claus Gittinger <cg@exept.de> * ef9b481d7498: #FEATURE by cg, Claus Gittinger <cg@exept.de> * ea663b72bd51: #UI_ENHANCEMENT by cg, Claus Gittinger <cg@exept.de> * 6179572a733c: #FEATURE by exept, Claus Gittinger <cg@exept.de> * 84155b1b6622: #DOCUMENTATION by exept, Claus Gittinger <cg@exept.de> * 37d06602d856: *** empty log message ***, Claus Gittinger <cg@exept.de> * f927b9022fea: *** empty log message ***, Claus Gittinger <cg@exept.de> * 427d3be62d97: #UI_ENHANCEMENT by exept, Claus Gittinger <cg@exept.de>
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
23107
40173e082cbc Copyright updates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 23074
diff changeset
     3
 COPYRIGHT (c) 2016-2017 Jan Vrany
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
     4
	      All Rights Reserved
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
     5
a27a279701f8 Initial revision
claus
parents:
diff changeset
     6
 This software is furnished under a license and may be used
a27a279701f8 Initial revision
claus
parents:
diff changeset
     7
 only in accordance with the terms of that license and with the
a27a279701f8 Initial revision
claus
parents:
diff changeset
     8
 inclusion of the above copyright notice.   This software may not
a27a279701f8 Initial revision
claus
parents:
diff changeset
     9
 be provided or otherwise made available to, or used by, any
a27a279701f8 Initial revision
claus
parents:
diff changeset
    10
 other person.  No title to or ownership of the software is
a27a279701f8 Initial revision
claus
parents:
diff changeset
    11
 hereby transferred.
a27a279701f8 Initial revision
claus
parents:
diff changeset
    12
"
5396
92bf7d0b1b66 Fix typo.
Stefan Vogel <sv@exept.de>
parents: 5389
diff changeset
    13
"{ Package: 'stx:libbasic' }"
92bf7d0b1b66 Fix typo.
Stefan Vogel <sv@exept.de>
parents: 5389
diff changeset
    14
17271
47341245c458 class: ProcessorScheduler
Claus Gittinger <cg@exept.de>
parents: 16858
diff changeset
    15
"{ NameSpace: Smalltalk }"
47341245c458 class: ProcessorScheduler
Claus Gittinger <cg@exept.de>
parents: 16858
diff changeset
    16
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    17
Object subclass:#ProcessorScheduler
15687
7679c998f5ac class: ProcessorScheduler
Claus Gittinger <cg@exept.de>
parents: 15658
diff changeset
    18
	instanceVariableNames:'quiescentProcessLists scheduler zombie activeProcess
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
    19
                activeProcessId currentPriority readFdArray readSemaphoreArray
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
    20
                readCheckArray writeFdArray writeSemaphoreArray writeCheckArray
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
    21
                timeoutArray timeoutActionArray timeoutProcessArray
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
    22
                timeoutSemaphoreArray idleActions anyTimeouts dispatching
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
    23
                interruptedProcess useIOInterrupts gotIOInterrupt
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
    24
                osChildExitActions gotChildSignalInterrupt
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
    25
                exitWhenNoMoreUserProcesses suspendScheduler timeSliceProcess
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
    26
                supportDynamicPriorities timeSliceNeededSemaphore
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
    27
                scheduledProcesses preWaitActions timeoutHandlerProcess
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
    28
                readableResultFdArray writableResultFdArray exceptFdArray
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
    29
                exceptResultFdArray exceptSemaphoreArray interruptCounter
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
    30
                timedActionCounter'
15687
7679c998f5ac class: ProcessorScheduler
Claus Gittinger <cg@exept.de>
parents: 15658
diff changeset
    31
	classVariableNames:'KnownProcesses KnownProcessIds PureEventDriven
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
    32
                UserSchedulingPriority UserInterruptPriority TimingPriority
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
    33
                HighestPriority SchedulingPriority MaxNumberOfProcesses
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
    34
                InvalidProcessSignal TimeSlicingPriorityLimit TimeSliceInterval
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
    35
                EventPollingInterval MinProcessId MaxProcessId SysProcessId'
15687
7679c998f5ac class: ProcessorScheduler
Claus Gittinger <cg@exept.de>
parents: 15658
diff changeset
    36
	poolDictionaries:''
7679c998f5ac class: ProcessorScheduler
Claus Gittinger <cg@exept.de>
parents: 15658
diff changeset
    37
	category:'Kernel-Processes'
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    38
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
    39
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
    40
!ProcessorScheduler primitiveDefinitions!
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
    41
%{
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
    42
# ifndef _STDIO_H_INCLUDED_
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
    43
#  include <stdio.h>
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
    44
#  define _STDIO_H_INCLUDED_
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
    45
# endif
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
    46
%}
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
    47
! !
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
    48
1783
be7402f74d94 hide timerInterrupt & ioInterrupt contexts when switching
Claus Gittinger <cg@exept.de>
parents: 1780
diff changeset
    49
!ProcessorScheduler class methodsFor:'documentation'!
88
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    50
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    51
copyright
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    52
"
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    53
 COPYRIGHT (c) 1993 by Claus Gittinger
23107
40173e082cbc Copyright updates
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 23074
diff changeset
    54
 COPYRIGHT (c) 2016-2017 Jan Vrany
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
    55
	      All Rights Reserved
88
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    56
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    57
 This software is furnished under a license and may be used
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    58
 only in accordance with the terms of that license and with the
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    59
 inclusion of the above copyright notice.   This software may not
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    60
 be provided or otherwise made available to, or used by, any
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    61
 other person.  No title to or ownership of the software is
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    62
 hereby transferred.
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    63
"
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    64
!
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    65
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    66
documentation
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    67
"
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    68
    This class has only one instance, which is bound to the global
2193
Claus Gittinger <cg@exept.de>
parents: 2191
diff changeset
    69
    'Processor' (well, on future multiprocessor systems, things may look
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
    70
    different ... ;-). It is responsible for scheduling among the Smalltalk
88
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    71
    processes (threads; not to confuse with heavy weight unix processes).
93
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
    72
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
    73
    Scheduling is fully done in Smalltalk (the always runnable scheduler-
93
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
    74
    process, running at highest priority does this).
2193
Claus Gittinger <cg@exept.de>
parents: 2191
diff changeset
    75
    See the 'scheduling' documentation.
Claus Gittinger <cg@exept.de>
parents: 2191
diff changeset
    76
231
fd0e55e352f8 cleanup
claus
parents: 217
diff changeset
    77
    The main VM primitive to support this is found in threadSwitch, which passes
93
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
    78
    control to another process (usually selected by the scheduler).
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
    79
    Thus it is possible to modify the scheduler's policy and implementation
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
    80
    at the Smalltalk level (if you are brave enough to do this).
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
    81
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
    82
    Notice:
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
    83
    ST/X includes a timeslicer and reschedules running threads within the highest runnable
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
    84
    priority. This is done by the timeSlicer thread, which runs at high realtime prio.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
    85
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
    86
    Also notice, that ST/X supports dynamic priority ranges: a low prio (background) process
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
    87
    can be quaranteed to make progress, by giving it a range from low to a higher (usually user-) prios.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
    88
    If it was suspended long enough, its prio will be dynamically increased, until it gets a slice to run
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
    89
    (and then drops back to its low background prio). So it will get a chance to do some work.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
    90
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
    91
    Final Notice:
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
    92
    Smalltalk/X used to support a mode (configured and compiled) without
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
    93
    process support. This non-process mode was called 'pureEventDriven' mode
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
    94
    and was useful to quickly port ST/X to systems, where these facilities
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
    95
    were either not needed (server applications), or were difficult to
10747
e9ea71d01445 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10497
diff changeset
    96
    implement (threads require some assembler support functions).
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
    97
    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
    98
    system, where either a process is forked, or a timeout is used instead
93
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
    99
    (for examples, see ProcessMonitor or MemoryMonitor).
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   100
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   101
    Although still present in some places, support for this pure-event mode is no longer supported,
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   102
    and will vanish over time from the code.
93
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   103
6619
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
   104
    [instance variables:]
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   105
	quiescentProcessLists           - list of waiting processes
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   106
	scheduler                       - the scheduler process itself
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   107
	zombie                          - internal temporary (recently died process)
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   108
	activeProcess                   - the current process
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   109
	activeProcessId                 - the current processes id
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   110
	currentPriority                 - the current processes priority
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   111
	readFdArray                     - fd-sema-checkBlock triple-association
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   112
	readSemaphoreArray                (stupid historic 3-separate arrays for hi-speed-optimization reasons)
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   113
	readCheckArray
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   114
	writeFdArray                    - fd-sema-checkBlock triple-association
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   115
	writeSemaphoreArray               (stupid historic 3-separate arrays for hi-speed-optimization reasons)
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   116
	writeCheckArray
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   117
	timeoutArray                    - time-action-process-sema quadruple-association
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   118
	timeoutActionArray                (stupid historic 3-separate arrays for hi-speed-optimization reasons)
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   119
	timeoutProcessArray
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   120
	timeoutSemaphoreArray
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   121
	idleActions                     - actions to be executed when idle
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   122
	preWaitActions                  - actions to be executed BEFORE going into an OS-wait
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   123
	anyTimeouts                     - flag if any timeouts are pending
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   124
	dispatching                     - flag if dispatch process is running (i.e. NOT initializing)
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   125
	interruptedProcess              - the currently interrupted process.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   126
	useIOInterrupts                 - flag if the OS supports I/O interrupts and if they are used (to get me out of an OS wait)
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   127
	gotIOInterrupt                  - flag if I came out of a wait due to an I/O interrupt
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   128
	osChildExitActions              - OS chid process actions
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   129
	gotChildSignalInterrupt         - flag if I came out of a wait due to an OS child interrupt
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   130
	exitWhenNoMoreUserProcesses     - flag which controls if ST/X should exit when the last process dies (for standalone apps)
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   131
	suspendScheduler                - internal use
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   132
	timeSliceProcess                - the timeSlicer process
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   133
	supportDynamicPriorities        - flag if dynamic priorities should be supported by the timeSlicer
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   134
	scheduledProcesses              - list of scheduled processes for the timeSlicers dynamic prio handling
369
claus
parents: 362
diff changeset
   135
1273
f8449f53a6a3 commentary
Claus Gittinger <cg@exept.de>
parents: 1177
diff changeset
   136
    [class variables:]
93
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   137
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   138
	KnownProcesses          <WeakArray>     all known processes
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   139
	KnownProcessIds         <Array>         and their IDs
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   140
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   141
	PureEventDriven         <Boolean>       true, if no process support
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   142
						is available
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   143
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   144
	UserSchedulingPriority  <Integer>       the priority at which normal
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   145
						user interfaces run
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   146
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   147
	UserInterruptPriority                   the priority at which user-
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   148
						interrupts (Cntl-C) processing
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   149
						takes place. Processes with
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   150
						a greater or equal priority are
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   151
						not interruptable.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   152
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   153
	TimingPriority                          the priority used for timing.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   154
						Processes with a greater or
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   155
						equal priority are not interrupted
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   156
						by timers.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   157
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   158
	HighestPriority                         The highest allowed prio for processes
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   159
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   160
	SchedulingPriority                      The priority of the scheduler (must
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   161
						me higher than any other).
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   162
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   163
	MaxNumberOfProcesses                    if non-nil, no more than this
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   164
						number of processes are allowed
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   165
						(for debugging)
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   166
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   167
	TimeSliceInterval                       for preemptive priority scheduling only:
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   168
						the time interval in millis, at which processes
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   169
						are timesliced
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   170
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   171
	TimeSlicingPriorityLimit                for preemptive priority scheduling only:
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   172
						processes are only timesliced, if running
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   173
						at or below this priority.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   174
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   175
	EventPollingInterval                    for systems which do not support select on
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   176
						a fileDescriptor: the polling interval in millis.
2626
4194d370d46f made event polling interval a variable
Claus Gittinger <cg@exept.de>
parents: 2625
diff changeset
   177
759
908363ce8a32 interest is written with one 'r' (shame on me)
Claus Gittinger <cg@exept.de>
parents: 752
diff changeset
   178
    most interesting methods:
93
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   179
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   180
	Processor>>suspend:                  (see also Process>>suspend)
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   181
	Processor>>resume:                   (see also Process>>resume)
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   182
	Processor>>terminate:                (see also Process>>terminate)
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   183
	Processor>>yield
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   184
	Processor>>changePriority:for:       (see also Process>>priority:
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   185
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   186
	Processor>>signal:afterSeconds:      (see also Delay>>forSeconds:)
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   187
	Processor>>signal:afterMilliseconds: (see also Delay>>forMilliseconds:)
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   188
	Processor>>signal:onInput:           (see also ExternalStream>>readWait)
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   189
	Processor>>signal:onOutput:          (see also ExternalStream>>writeWait)
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   190
	Processor>>disableSemaphore:
1273
f8449f53a6a3 commentary
Claus Gittinger <cg@exept.de>
parents: 1177
diff changeset
   191
f8449f53a6a3 commentary
Claus Gittinger <cg@exept.de>
parents: 1177
diff changeset
   192
f8449f53a6a3 commentary
Claus Gittinger <cg@exept.de>
parents: 1177
diff changeset
   193
    [see also:]
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   194
	Process
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   195
	Delay Semaphore SemaphoreSet SharedQueue
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   196
	WindowGroup
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   197
	(``Working with processes'': programming/processes.html)
1294
e26bbb61f6b2 documentation
Claus Gittinger <cg@exept.de>
parents: 1273
diff changeset
   198
e26bbb61f6b2 documentation
Claus Gittinger <cg@exept.de>
parents: 1273
diff changeset
   199
    [author:]
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   200
	Claus Gittinger
88
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
   201
"
2193
Claus Gittinger <cg@exept.de>
parents: 2191
diff changeset
   202
!
Claus Gittinger <cg@exept.de>
parents: 2191
diff changeset
   203
Claus Gittinger <cg@exept.de>
parents: 2191
diff changeset
   204
scheduling
Claus Gittinger <cg@exept.de>
parents: 2191
diff changeset
   205
"
10747
e9ea71d01445 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10497
diff changeset
   206
    By default, the scheduler does 'non preemptive priority scheduling';
e9ea71d01445 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10497
diff changeset
   207
e9ea71d01445 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10497
diff changeset
   208
    this means, that the highest priority runnable process
2193
Claus Gittinger <cg@exept.de>
parents: 2191
diff changeset
   209
    is choosen and allowed to run, until it either gives back the CPU (via #yield),
Claus Gittinger <cg@exept.de>
parents: 2191
diff changeset
   210
    or suspends (i.e. waiting for I/O, the time or a semaphore),
Claus Gittinger <cg@exept.de>
parents: 2191
diff changeset
   211
    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
   212
    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
   213
    (i.e. signalling a semaphore), by a timer or by IO availability.
2193
Claus Gittinger <cg@exept.de>
parents: 2191
diff changeset
   214
Claus Gittinger <cg@exept.de>
parents: 2191
diff changeset
   215
    If another process is runnable at the same priority, it will not
Claus Gittinger <cg@exept.de>
parents: 2191
diff changeset
   216
    be given CPU-time, unless one of the above happens.
Claus Gittinger <cg@exept.de>
parents: 2191
diff changeset
   217
Claus Gittinger <cg@exept.de>
parents: 2191
diff changeset
   218
    The consequence is, that a user process running at (say) priority 8,
Claus Gittinger <cg@exept.de>
parents: 2191
diff changeset
   219
    may block other user processes at the same priority, if it does heavy
Claus Gittinger <cg@exept.de>
parents: 2191
diff changeset
   220
    processing, or loops.
10747
e9ea71d01445 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10497
diff changeset
   221
    (the event handling which is responsible to care for userInterrupts,
e9ea71d01445 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10497
diff changeset
   222
     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
   223
     so that interrupting the process should always be possible).
2193
Claus Gittinger <cg@exept.de>
parents: 2191
diff changeset
   224
Claus Gittinger <cg@exept.de>
parents: 2191
diff changeset
   225
Claus Gittinger <cg@exept.de>
parents: 2191
diff changeset
   226
    The scheduler also supports 'timesliced priority scheduling', which is enabled
Claus Gittinger <cg@exept.de>
parents: 2191
diff changeset
   227
    via the #startTimeSlicing message (and disabled by #stopTimeSlicing).
Claus Gittinger <cg@exept.de>
parents: 2191
diff changeset
   228
    In this mode, the highest priority running process is suspended in regular intervals
Claus Gittinger <cg@exept.de>
parents: 2191
diff changeset
   229
    (the TimeSliceInterval) IFF there is another runnable process with the same priority.
Claus Gittinger <cg@exept.de>
parents: 2191
diff changeset
   230
    I.e. the top highest priority processes are timeshared.
Claus Gittinger <cg@exept.de>
parents: 2191
diff changeset
   231
    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
   232
    lower priority process will only run, IFF all higher prio processes are waiting for an
Claus Gittinger <cg@exept.de>
parents: 2191
diff changeset
   233
    event.
Claus Gittinger <cg@exept.de>
parents: 2191
diff changeset
   234
    Timeslicing will not be done for processes running above TimeSlicingPriorityLimit, which
Claus Gittinger <cg@exept.de>
parents: 2191
diff changeset
   235
    allows for critical processes to run unaffected to completion.
Claus Gittinger <cg@exept.de>
parents: 2191
diff changeset
   236
Claus Gittinger <cg@exept.de>
parents: 2191
diff changeset
   237
    WARNING:
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
   238
	timesliced priority scheduling is an experimental feature. There is no warranty,
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
   239
	(at the moment), that the system runs reliable in this mode.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
   240
	The problem is, that shared collections may now be easily modified by other
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
   241
	processes, running at the same time.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
   242
	The class library has being investigated for such possible trouble spots
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
   243
	(we have eliminated many weak spots, and added critical regions at many places,
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
   244
	 but cannot guarantee that all of them have been found so far ...)
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
   245
	We found that many existing public domain programs are not prepared for
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
   246
	being interrupted by a same-prio process and therefore may corrupt their
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
   247
	data. If in doubt, disable this fefature.
2193
Claus Gittinger <cg@exept.de>
parents: 2191
diff changeset
   248
Claus Gittinger <cg@exept.de>
parents: 2191
diff changeset
   249
    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
   250
    for it to be evaluated, therefore, its included.
2193
Claus Gittinger <cg@exept.de>
parents: 2191
diff changeset
   251
    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
   252
523781600982 added #useIOInterrupts: to allow disabling this feature
Claus Gittinger <cg@exept.de>
parents: 3644
diff changeset
   253
    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
   254
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
   255
	- disable timeSlicing (in the launchers misc-settings menu)
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
   256
	- open a workSpace
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
   257
	- in the workspace, evaluate:
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
   258
		[true] whileTrue:[1000 factorial]
3650
523781600982 added #useIOInterrupts: to allow disabling this feature
Claus Gittinger <cg@exept.de>
parents: 3644
diff changeset
   259
523781600982 added #useIOInterrupts: to allow disabling this feature
Claus Gittinger <cg@exept.de>
parents: 3644
diff changeset
   260
    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
   261
    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
   262
    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
   263
    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
   264
523781600982 added #useIOInterrupts: to allow disabling this feature
Claus Gittinger <cg@exept.de>
parents: 3644
diff changeset
   265
    Now, stop the factorial-loop, enable timeSlicing, and try again.
10747
e9ea71d01445 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10497
diff changeset
   266
    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
   267
    since the CPU is now divided equally among the runnable processes (timeSliced).
2193
Claus Gittinger <cg@exept.de>
parents: 2191
diff changeset
   268
"
88
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
   269
! !
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
   270
1783
be7402f74d94 hide timerInterrupt & ioInterrupt contexts when switching
Claus Gittinger <cg@exept.de>
parents: 1780
diff changeset
   271
!ProcessorScheduler class methodsFor:'initialization'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   272
a27a279701f8 Initial revision
claus
parents:
diff changeset
   273
initialize
44
b262907c93ea *** empty log message ***
claus
parents: 42
diff changeset
   274
    "class setup: create the one-and-only instance of myself and
b262907c93ea *** empty log message ***
claus
parents: 42
diff changeset
   275
     setup some priority values."
b262907c93ea *** empty log message ***
claus
parents: 42
diff changeset
   276
2193
Claus Gittinger <cg@exept.de>
parents: 2191
diff changeset
   277
    TimeSliceInterval := 50.
2626
4194d370d46f made event polling interval a variable
Claus Gittinger <cg@exept.de>
parents: 2625
diff changeset
   278
    EventPollingInterval := 20.
2193
Claus Gittinger <cg@exept.de>
parents: 2191
diff changeset
   279
93
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   280
    UserSchedulingPriority := 8.
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   281
    UserInterruptPriority := 24.
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   282
    TimingPriority := 16.
2190
8afa4709d8a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2188
diff changeset
   283
    TimeSlicingPriorityLimit := 26.
8afa4709d8a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2188
diff changeset
   284
    HighestPriority := 30.
93
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   285
    SchedulingPriority := 31.
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   286
23071
77ad9497363c Issue #94 [3/x]: Respect `SYS_PROCESS_ID` when creating an initial system process
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 20080
diff changeset
   287
    self initializeVMProcessIdConstants.
77ad9497363c Issue #94 [3/x]: Respect `SYS_PROCESS_ID` when creating an initial system process
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 20080
diff changeset
   288
1679
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   289
    InvalidProcessSignal isNil ifTrue:[
20706
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
   290
	InvalidProcessSignal := Error newSignalMayProceed:true.
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
   291
	InvalidProcessSignal nameClass:self message:#invalidProcessSignal.
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
   292
	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
   293
    ].
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   294
159
514c749165c3 *** empty log message ***
claus
parents: 144
diff changeset
   295
    Processor isNil ifTrue:[
20706
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
   296
	"create the one and only processor"
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
   297
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
   298
	Smalltalk at:#Processor put:(self basicNew initialize).
10
claus
parents: 3
diff changeset
   299
    ].
77
6c38ca59927f *** empty log message ***
claus
parents: 76
diff changeset
   300
6c38ca59927f *** empty log message ***
claus
parents: 76
diff changeset
   301
    "
6c38ca59927f *** empty log message ***
claus
parents: 76
diff changeset
   302
     allow configurations without processes
2129
e03cd7bc3475 newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents: 2123
diff changeset
   303
     (but such configurations are no longer distributed)
77
6c38ca59927f *** empty log message ***
claus
parents: 76
diff changeset
   304
    "
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   305
    PureEventDriven := self threadsAvailable not.
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   306
    PureEventDriven ifTrue:[
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   307
	Logger error:'Processor: no process support - running event driven'.
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   308
    ].
23071
77ad9497363c Issue #94 [3/x]: Respect `SYS_PROCESS_ID` when creating an initial system process
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 20080
diff changeset
   309
    
16841
9e5808800de0 Added MaxProcessId variable & accessor.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16624
diff changeset
   310
9e5808800de0 Added MaxProcessId variable & accessor.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16624
diff changeset
   311
    "Modified: / 23-09-1996 / 14:24:50 / stefan"
9e5808800de0 Added MaxProcessId variable & accessor.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16624
diff changeset
   312
    "Modified: / 10-01-1997 / 18:03:03 / cg"
9e5808800de0 Added MaxProcessId variable & accessor.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16624
diff changeset
   313
    "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
   314
!
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
   315
23071
77ad9497363c Issue #94 [3/x]: Respect `SYS_PROCESS_ID` when creating an initial system process
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 20080
diff changeset
   316
initializeVMProcessIdConstants
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
   317
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
   318
    "/ for java locks, the VM may reserve some bits
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
   319
    "/ and reduce the maximum processID to be able to
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
   320
    "/ encode the id in an object's header field.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
   321
%{
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
   322
#ifndef __SCHTEAM__
23071
77ad9497363c Issue #94 [3/x]: Respect `SYS_PROCESS_ID` when creating an initial system process
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 20080
diff changeset
   323
    @global(ProcessorScheduler:MinProcessId) = __MKSMALLINT(MIN_PROCESS_ID);
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
   324
    @global(ProcessorScheduler:MaxProcessId) = __MKSMALLINT(MAX_PROCESS_ID);
23071
77ad9497363c Issue #94 [3/x]: Respect `SYS_PROCESS_ID` when creating an initial system process
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 20080
diff changeset
   325
    @global(ProcessorScheduler:SysProcessId) = __MKSMALLINT(SYS_PROCESS_ID);
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
   326
    RETURN (self);
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
   327
#endif /* not SCHTEAM */
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
   328
%}.
23071
77ad9497363c Issue #94 [3/x]: Respect `SYS_PROCESS_ID` when creating an initial system process
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 20080
diff changeset
   329
    self primitiveFailed
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   330
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   331
1783
be7402f74d94 hide timerInterrupt & ioInterrupt contexts when switching
Claus Gittinger <cg@exept.de>
parents: 1780
diff changeset
   332
!ProcessorScheduler class methodsFor:'instance creation'!
10
claus
parents: 3
diff changeset
   333
claus
parents: 3
diff changeset
   334
new
claus
parents: 3
diff changeset
   335
    "there is (currently) only one processor ..."
claus
parents: 3
diff changeset
   336
159
514c749165c3 *** empty log message ***
claus
parents: 144
diff changeset
   337
    self error:'only one processor is allowed in the system'
10
claus
parents: 3
diff changeset
   338
! !
claus
parents: 3
diff changeset
   339
1783
be7402f74d94 hide timerInterrupt & ioInterrupt contexts when switching
Claus Gittinger <cg@exept.de>
parents: 1780
diff changeset
   340
!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
   341
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   342
invalidProcessSignal
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   343
    ^ InvalidProcessSignal
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   344
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   345
    "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
   346
! !
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   347
1783
be7402f74d94 hide timerInterrupt & ioInterrupt contexts when switching
Claus Gittinger <cg@exept.de>
parents: 1780
diff changeset
   348
!ProcessorScheduler class methodsFor:'instance release'!
10
claus
parents: 3
diff changeset
   349
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   350
update:anAspect with:aParameter from:changedObject
10747
e9ea71d01445 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10497
diff changeset
   351
    "some Process has been garbage collected
e9ea71d01445 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10497
diff changeset
   352
     - terminate the underlying thread.
e9ea71d01445 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10497
diff changeset
   353
     Usually this does not happen; instead, the process terminates itself
335
claus
parents: 326
diff changeset
   354
     by sending #terminate."
10
claus
parents: 3
diff changeset
   355
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   356
    |id sz "{ Class: SmallInteger }" wasBlocked|
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   357
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   358
    anAspect == #ElementExpired ifTrue:[
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   359
	wasBlocked := OperatingSystem blockInterrupts.
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
   360
	sz := KnownProcessIds size.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
   361
	1 to:sz do:[:index |
18620
b4e9f25d6ce6 preparations for lined index list in WeakArray
Claus Gittinger <cg@exept.de>
parents: 18295
diff changeset
   362
	    (KnownProcesses at:index) class == SmallInteger ifTrue:[
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   363
		"weak element has been collected"
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
   364
		id := KnownProcessIds at:index.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
   365
		id notNil ifTrue:[
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   366
		    Logger warning:'Processor: terminating thread %1 (no longer refd)' with:id.
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
   367
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
   368
		    self threadDestroy:id.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
   369
		    KnownProcessIds at:index put:nil.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
   370
		].
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
   371
		KnownProcesses at:index put:nil.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
   372
	    ]
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   373
	].
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   374
	wasBlocked ifFalse:[ OperatingSystem unblockInterrupts ].
10
claus
parents: 3
diff changeset
   375
    ]
2091
c11bb3e29a1b Use dependent mechamism of WeakArray instead of #watcher.
Stefan Vogel <sv@exept.de>
parents: 1981
diff changeset
   376
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   377
    "Created: / 07-01-1997 / 16:45:42 / stefan"
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   378
    "Modified: / 01-06-2020 / 14:11:34 / cg"
10
claus
parents: 3
diff changeset
   379
! !
claus
parents: 3
diff changeset
   380
1783
be7402f74d94 hide timerInterrupt & ioInterrupt contexts when switching
Claus Gittinger <cg@exept.de>
parents: 1780
diff changeset
   381
!ProcessorScheduler class methodsFor:'primitive process primitives'!
10
claus
parents: 3
diff changeset
   382
339
claus
parents: 337
diff changeset
   383
threadCreate:aProcess withId:id
159
514c749165c3 *** empty log message ***
claus
parents: 144
diff changeset
   384
    "physical creation of a process.
10
claus
parents: 3
diff changeset
   385
     (warning: low level entry, no administration done).
339
claus
parents: 337
diff changeset
   386
     This may raise an exception, if a VM process could not be created."
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   387
369
claus
parents: 362
diff changeset
   388
    MaxNumberOfProcesses notNil ifTrue:[
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   389
	KnownProcessIds size >= MaxNumberOfProcesses ifTrue:[
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   390
	    (KnownProcessIds count:[:el | el notNil]) >= MaxNumberOfProcesses ifTrue:[
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   391
		"
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   392
		 the number of processes has reached the (soft) limit.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   393
		 This limit prevents runaway programs from creating too many
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   394
		 processes. If you continue in the debugger, the process will be
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   395
		 created as usual. If you don't want this, abort or terminate.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   396
		"
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   397
		self error:'too many processes'.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   398
	    ]
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   399
	]
369
claus
parents: 362
diff changeset
   400
    ].
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   401
    "/ e'threadCreate {(ObjectMemory addressOf:aProcess)hexPrintString} id:{id}\n' printOn:Stderr.
369
claus
parents: 362
diff changeset
   402
claus
parents: 362
diff changeset
   403
%{
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   404
    int tid;
a27a279701f8 Initial revision
claus
parents:
diff changeset
   405
    extern int __threadCreate();
a27a279701f8 Initial revision
claus
parents:
diff changeset
   406
10747
e9ea71d01445 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10497
diff changeset
   407
    tid = __threadCreate(aProcess,
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   408
			 0   /* stackSize: no longer needed */,
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   409
			 __isSmallInteger(id) ? __intVal(id)     /* assign id */
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   410
					      : -1              /* let VM assign one */  );
339
claus
parents: 337
diff changeset
   411
    if (tid) {
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   412
	RETURN ( __mkSmallInteger(tid));
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   413
    }
a27a279701f8 Initial revision
claus
parents:
diff changeset
   414
%}
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   415
.
69
4564b6328136 *** empty log message ***
claus
parents: 59
diff changeset
   416
    "
4564b6328136 *** empty log message ***
claus
parents: 59
diff changeset
   417
     arrive here, if creation of process in VM failed.
159
514c749165c3 *** empty log message ***
claus
parents: 144
diff changeset
   418
     This may happen, if the VM does not support more processes,
514c749165c3 *** empty log message ***
claus
parents: 144
diff changeset
   419
     or if it ran out of memory, when allocating internal data
514c749165c3 *** empty log message ***
claus
parents: 144
diff changeset
   420
     structures.
69
4564b6328136 *** empty log message ***
claus
parents: 59
diff changeset
   421
    "
20706
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
   422
    ^ AllocationFailure raise.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   423
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   424
a27a279701f8 Initial revision
claus
parents:
diff changeset
   425
threadDestroy:id
a27a279701f8 Initial revision
claus
parents:
diff changeset
   426
    "physical destroy other process ...
a27a279701f8 Initial revision
claus
parents:
diff changeset
   427
     (warning: low level entry, no administration done)"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   428
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   429
%{  /* NOCONTEXT */
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   430
253
30daee717a53 *** empty log message ***
claus
parents: 243
diff changeset
   431
    if (__isSmallInteger(id)) {
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
   432
	__threadDestroy(__intVal(id));
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   433
    }
a27a279701f8 Initial revision
claus
parents:
diff changeset
   434
%}
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   435
!
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
threadInterrupt:id
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   438
    "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
   439
     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
   440
     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
   441
     interrupt (currently, it looks for interruptBlocks to evaluate)."
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   442
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   443
%{  /* NOCONTEXT */
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   444
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   445
    if (__isSmallInteger(id)) {
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
   446
	__threadInterrupt(__intVal(id));
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   447
    }
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   448
%}
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   449
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   450
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   451
threadsAvailable
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   452
    "return true, if the runtime system supports threads (i.e. processes);
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   453
     false otherwise."
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   454
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   455
%{  /* NOCONTEXT */
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   456
    RETURN (__threadsAvailable());
5406
4a6995b61c0e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5396
diff changeset
   457
%}.
4a6995b61c0e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5396
diff changeset
   458
    ^ true
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   459
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   460
1783
be7402f74d94 hide timerInterrupt & ioInterrupt contexts when switching
Claus Gittinger <cg@exept.de>
parents: 1780
diff changeset
   461
!ProcessorScheduler class methodsFor:'queries'!
699
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
isPureEventDriven
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   464
    "this is temporary - (maybe not :-).
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   465
     you can run ST/X either with or without processes.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   466
     Without, there is conceptionally a single process handling all
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   467
     outside events and timeouts. This has some negative implications
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   468
     (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
   469
     assembler support - i.e. quick portability.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   470
     The PureEvent flag will automatically be set if the runtime system
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   471
     does not support threads - otherwise, it can be set manually
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   472
     (from rc-file).
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   473
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   474
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   475
    ^ PureEventDriven
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   476
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   477
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   478
knownProcesses
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   479
    "return a collection of all (living) processes in the system"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   480
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   481
    |wasBlocked ret|
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   482
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   483
    wasBlocked := OperatingSystem blockInterrupts.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   484
    ret := KnownProcesses select:[:p | p notNil and:[p class ~~ SmallInteger]] as:OrderedCollection.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   485
    wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   486
    ^ ret
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   487
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   488
    "Modified: / 01-06-2020 / 14:02:21 / cg"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   489
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   490
14442
92bfe052854b added: #knownProcessesDo:
Claus Gittinger <cg@exept.de>
parents: 14230
diff changeset
   491
knownProcessesDo:aBlock
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   492
    <resource: #obsolete>
14442
92bfe052854b added: #knownProcessesDo:
Claus Gittinger <cg@exept.de>
parents: 14230
diff changeset
   493
    "evaluate aBlock for each (living) processes in the system"
92bfe052854b added: #knownProcessesDo:
Claus Gittinger <cg@exept.de>
parents: 14230
diff changeset
   494
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   495
    KnownProcesses nonNilElementsDo:aBlock
14442
92bfe052854b added: #knownProcessesDo:
Claus Gittinger <cg@exept.de>
parents: 14230
diff changeset
   496
92bfe052854b added: #knownProcessesDo:
Claus Gittinger <cg@exept.de>
parents: 14230
diff changeset
   497
    "Created: / 26-10-2012 / 13:02:33 / cg"
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   498
    "Modified: / 01-06-2020 / 14:06:45 / cg"
14442
92bfe052854b added: #knownProcessesDo:
Claus Gittinger <cg@exept.de>
parents: 14230
diff changeset
   499
!
92bfe052854b added: #knownProcessesDo:
Claus Gittinger <cg@exept.de>
parents: 14230
diff changeset
   500
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   501
maxNumberOfProcesses
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   502
    "return the limit on the number of processes;
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   503
     the default is nil (i.e. unlimited)."
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   504
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   505
    ^ MaxNumberOfProcesses
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   506
!
10
claus
parents: 3
diff changeset
   507
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   508
maxNumberOfProcesses:aNumber
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   509
    "set the limit on the number of processes.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   510
     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
   511
     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
   512
     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
   513
     processes is unlimited."
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   514
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   515
    MaxNumberOfProcesses := aNumber
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
16841
9e5808800de0 Added MaxProcessId variable & accessor.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16624
diff changeset
   518
maxProcessId
9e5808800de0 Added MaxProcessId variable & accessor.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16624
diff changeset
   519
    "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
   520
9e5808800de0 Added MaxProcessId variable & accessor.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16624
diff changeset
   521
    ^ MaxProcessId
9e5808800de0 Added MaxProcessId variable & accessor.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16624
diff changeset
   522
9e5808800de0 Added MaxProcessId variable & accessor.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16624
diff changeset
   523
    "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
   524
!
9e5808800de0 Added MaxProcessId variable & accessor.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16624
diff changeset
   525
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   526
processDriven
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   527
    "turn on process driven mode"
10
claus
parents: 3
diff changeset
   528
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   529
    PureEventDriven := false
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   530
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   531
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   532
processWithID:id
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   533
    |wasBlocked|
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   534
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   535
    wasBlocked := OperatingSystem blockInterrupts.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   536
    KnownProcesses nonNilElementsDo:[:p|
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   537
	p id = id ifTrue:[
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   538
	    wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   539
	    ^ p
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   540
	].
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   541
    ].
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   542
    wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   543
    ^ nil.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   544
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   545
    "Created: / 01-06-2020 / 14:03:54 / cg"
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   546
!
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   547
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   548
pureEventDriven
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   549
    "turn on pure-event driven mode - no processes, single dispatch loop"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   550
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   551
    PureEventDriven := true
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   552
! !
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   553
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   554
!ProcessorScheduler methodsFor:'I/O event actions'!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   555
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   556
enableIOAction:aBlock onInput:aFileDescriptor
5101
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
   557
    "obsolete event support: arrange for aBlock to be
10747
e9ea71d01445 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10497
diff changeset
   558
     evaluated when input on aFileDescriptor arrives.
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   559
     This is a leftover support for pure-event systems and may vanish."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   560
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   561
    |idx "{Class: SmallInteger }"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   562
     wasBlocked|
10
claus
parents: 3
diff changeset
   563
3116
e535e4e266dd more error handling;
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   564
    aFileDescriptor < 0 ifTrue:[
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   565
	Logger warning:'Processor: ignored invalid fd for IO action.'.
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
   566
	thisContext fullPrintAll.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
   567
	^ self
3116
e535e4e266dd more error handling;
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   568
    ].
e535e4e266dd more error handling;
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   569
93
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   570
    wasBlocked := OperatingSystem blockInterrupts.
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   571
    (readFdArray identityIndexOf:aFileDescriptor startingAt:1) == 0 ifTrue:[
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
   572
	idx := readFdArray identityIndexOf:nil startingAt:1.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
   573
	idx ~~ 0 ifTrue:[
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
   574
	    readFdArray at:idx put:aFileDescriptor.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
   575
	    readCheckArray at:idx put:aBlock.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
   576
	    readSemaphoreArray at:idx put:nil
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
   577
	] ifFalse:[
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
   578
	    readFdArray := readFdArray copyWith:aFileDescriptor.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
   579
	    readCheckArray := readCheckArray copyWith:aBlock.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
   580
	    readSemaphoreArray := readSemaphoreArray copyWith:nil.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
   581
	].
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
   582
	useIOInterrupts ifTrue:[
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
   583
	    OperatingSystem enableIOInterruptsOn:aFileDescriptor
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
   584
	].
2831
02f9aa61f71b ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   585
93
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   586
    ].
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   587
    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
   588
02f9aa61f71b ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   589
    "Modified: 4.8.1997 / 15:17:28 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   590
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   591
a27a279701f8 Initial revision
claus
parents:
diff changeset
   592
!ProcessorScheduler methodsFor:'accessing'!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   593
69
4564b6328136 *** empty log message ***
claus
parents: 59
diff changeset
   594
activePriority
4564b6328136 *** empty log message ***
claus
parents: 59
diff changeset
   595
    "return the priority of the currently running process.
159
514c749165c3 *** empty log message ***
claus
parents: 144
diff changeset
   596
     GNU-ST & ST-80 compatibility; this is the same as currentPriority"
69
4564b6328136 *** empty log message ***
claus
parents: 59
diff changeset
   597
4564b6328136 *** empty log message ***
claus
parents: 59
diff changeset
   598
    ^ currentPriority
4564b6328136 *** empty log message ***
claus
parents: 59
diff changeset
   599
!
4564b6328136 *** empty log message ***
claus
parents: 59
diff changeset
   600
25
e34a6267c79b *** empty log message ***
claus
parents: 24
diff changeset
   601
activeProcess
10
claus
parents: 3
diff changeset
   602
    "return the currently running process"
claus
parents: 3
diff changeset
   603
25
e34a6267c79b *** empty log message ***
claus
parents: 24
diff changeset
   604
    ^ activeProcess
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   605
25
e34a6267c79b *** empty log message ***
claus
parents: 24
diff changeset
   606
    "Processor activeProcess"
181
ef3ccf27e2e0 interrupted process now kept for monitor
claus
parents: 161
diff changeset
   607
!
ef3ccf27e2e0 interrupted process now kept for monitor
claus
parents: 161
diff changeset
   608
2262
4c4d810f006f semaphore names
Claus Gittinger <cg@exept.de>
parents: 2258
diff changeset
   609
activeProcessId
4c4d810f006f semaphore names
Claus Gittinger <cg@exept.de>
parents: 2258
diff changeset
   610
    "return the currently running process's ID.
4c4d810f006f semaphore names
Claus Gittinger <cg@exept.de>
parents: 2258
diff changeset
   611
     The same as returned by 'Processor activeProcess id';
4c4d810f006f semaphore names
Claus Gittinger <cg@exept.de>
parents: 2258
diff changeset
   612
     added for to avoid another send in semaphores debugging support."
4c4d810f006f semaphore names
Claus Gittinger <cg@exept.de>
parents: 2258
diff changeset
   613
4c4d810f006f semaphore names
Claus Gittinger <cg@exept.de>
parents: 2258
diff changeset
   614
    ^ activeProcessId
4c4d810f006f semaphore names
Claus Gittinger <cg@exept.de>
parents: 2258
diff changeset
   615
!
4c4d810f006f semaphore names
Claus Gittinger <cg@exept.de>
parents: 2258
diff changeset
   616
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   617
currentPriority
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   618
    "return the priority of the currently running process"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   619
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   620
    ^ currentPriority
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   621
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   622
    "Processor currentPriority"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   623
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   624
21114
f8153ed0902e #DOCUMENTATION by sr
sr
parents: 21099
diff changeset
   625
exitWhenNoMoreUserProcesses:aBoolean
f8153ed0902e #DOCUMENTATION by sr
sr
parents: 21099
diff changeset
   626
    "set/clear the flag, which controls if the scheduler should exit and return
f8153ed0902e #DOCUMENTATION by sr
sr
parents: 21099
diff changeset
   627
     when the last user process finishes (and therefore exit the smalltalk system).
f8153ed0902e #DOCUMENTATION by sr
sr
parents: 21099
diff changeset
   628
     A userProcess is defined as a process with a non-zero processGroup.
f8153ed0902e #DOCUMENTATION by sr
sr
parents: 21099
diff changeset
   629
     This flag is typically set for standAlone operation, to terminate the (Unix-)
f8153ed0902e #DOCUMENTATION by sr
sr
parents: 21099
diff changeset
   630
     process, when the last thread terminates."
f8153ed0902e #DOCUMENTATION by sr
sr
parents: 21099
diff changeset
   631
f8153ed0902e #DOCUMENTATION by sr
sr
parents: 21099
diff changeset
   632
    exitWhenNoMoreUserProcesses := aBoolean
f8153ed0902e #DOCUMENTATION by sr
sr
parents: 21099
diff changeset
   633
!
f8153ed0902e #DOCUMENTATION by sr
sr
parents: 21099
diff changeset
   634
19850
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
   635
interruptCounter
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
   636
    "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
   637
19850
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
   638
    ^ interruptCounter
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
   639
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
   640
    "
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
   641
     Processor interruptCounter
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
   642
    "
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
   643
!
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
   644
181
ef3ccf27e2e0 interrupted process now kept for monitor
claus
parents: 161
diff changeset
   645
interruptedProcess
ef3ccf27e2e0 interrupted process now kept for monitor
claus
parents: 161
diff changeset
   646
    "returns the process which was interrupted by the active one"
ef3ccf27e2e0 interrupted process now kept for monitor
claus
parents: 161
diff changeset
   647
ef3ccf27e2e0 interrupted process now kept for monitor
claus
parents: 161
diff changeset
   648
    ^ interruptedProcess
7046
b7ae8faff2ac Access method for scheduler
Stefan Vogel <sv@exept.de>
parents: 6990
diff changeset
   649
!
b7ae8faff2ac Access method for scheduler
Stefan Vogel <sv@exept.de>
parents: 6990
diff changeset
   650
16842
01a2d5d91c96 Oops, added #maxProcessId also to instance side.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16841
diff changeset
   651
maxProcessId
01a2d5d91c96 Oops, added #maxProcessId also to instance side.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16841
diff changeset
   652
    ^ self class maxProcessId
01a2d5d91c96 Oops, added #maxProcessId also to instance side.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16841
diff changeset
   653
01a2d5d91c96 Oops, added #maxProcessId also to instance side.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16841
diff changeset
   654
    "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
   655
!
01a2d5d91c96 Oops, added #maxProcessId also to instance side.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16841
diff changeset
   656
7046
b7ae8faff2ac Access method for scheduler
Stefan Vogel <sv@exept.de>
parents: 6990
diff changeset
   657
scheduler
b7ae8faff2ac Access method for scheduler
Stefan Vogel <sv@exept.de>
parents: 6990
diff changeset
   658
    "return the scheduling process"
b7ae8faff2ac Access method for scheduler
Stefan Vogel <sv@exept.de>
parents: 6990
diff changeset
   659
b7ae8faff2ac Access method for scheduler
Stefan Vogel <sv@exept.de>
parents: 6990
diff changeset
   660
    ^ scheduler
19850
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
   661
!
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
   662
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
   663
timedActionCounter
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
   664
    "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
   665
19850
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
   666
    ^ timedActionCounter
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
   667
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
   668
    "
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
   669
     Processor timedActionCounter
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
   670
    "
10
claus
parents: 3
diff changeset
   671
! !
claus
parents: 3
diff changeset
   672
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   673
!ProcessorScheduler methodsFor:'background processing'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   674
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   675
addIdleBlock:aBlock
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   676
    "add the argument, aBlock to the list of idle-actions.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   677
     Idle blocks are evaluated whenever no other process is runnable,
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   678
     and no events are pending.
10747
e9ea71d01445 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10497
diff changeset
   679
     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
   680
     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
   681
     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
   682
     are available.
6619
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
   683
     ATTENTION: Support for idle-blocks may vanish."
10
claus
parents: 3
diff changeset
   684
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   685
    |wasBlocked|
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   686
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   687
    wasBlocked := OperatingSystem blockInterrupts.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   688
    idleActions isNil ifTrue:[
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
   689
	idleActions := OrderedCollection new
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   690
    ].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   691
    idleActions add:aBlock.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   692
    wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   693
!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   694
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   695
removeIdleBlock:aBlock
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   696
    "remove the argument, aBlock from the list of idle-blocks.
6619
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
   697
     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
   698
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   699
    |wasBlocked|
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   700
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   701
    wasBlocked := OperatingSystem blockInterrupts.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   702
    idleActions notNil ifTrue:[
3969
0f30268b10c3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3967
diff changeset
   703
       idleActions removeIdentical:aBlock ifAbsent:nil
10
claus
parents: 3
diff changeset
   704
    ].
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   705
    wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
2353
ce92d04c41cc use removeIdentical
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   706
ce92d04c41cc use removeIdentical
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   707
    "Modified: 1.2.1997 / 12:09:46 / cg"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   708
! !
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   709
10
claus
parents: 3
diff changeset
   710
!ProcessorScheduler methodsFor:'dispatching'!
claus
parents: 3
diff changeset
   711
claus
parents: 3
diff changeset
   712
dispatch
93
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   713
     "It handles timeouts and switches to the highest prio runnable process"
44
b262907c93ea *** empty log message ***
claus
parents: 42
diff changeset
   714
19083
504ff3f2cfa0 #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 19063
diff changeset
   715
    |millis pri p nActions "{ Class: SmallInteger }"
3745
3fd121f2e74e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3740
diff changeset
   716
     checkBlock sema wasBlocked|
3fd121f2e74e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3740
diff changeset
   717
3fd121f2e74e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3740
diff changeset
   718
    wasBlocked := OperatingSystem blockInterrupts.
10
claus
parents: 3
diff changeset
   719
93
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   720
    "
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   721
     handle all timeout actions
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   722
    "
27
d98f9dd437f7 *** empty log message ***
claus
parents: 25
diff changeset
   723
    anyTimeouts ifTrue:[
20810
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   724
        self evaluateTimeouts
10
claus
parents: 3
diff changeset
   725
    ].
claus
parents: 3
diff changeset
   726
231
fd0e55e352f8 cleanup
claus
parents: 217
diff changeset
   727
    "first do a quick check for semaphores using checkActions - this is needed for
302
1f76060d58a4 *** empty log message ***
claus
parents: 271
diff changeset
   728
     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
   729
     queue but the sockets input queue is empty.
5101
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
   730
     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
   731
     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
   732
     sockets and pipes (sigh)
93
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   733
    "
231
fd0e55e352f8 cleanup
claus
parents: 217
diff changeset
   734
    nActions := readCheckArray size.
10
claus
parents: 3
diff changeset
   735
    1 to:nActions do:[:index |
20810
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   736
        checkBlock := readCheckArray at:index.
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   737
        (checkBlock notNil and:[checkBlock value]) ifTrue:[
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   738
            sema := readSemaphoreArray at:index.
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   739
            sema notNil ifTrue:[
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   740
                sema signalOnce.
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   741
            ].
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   742
        ]
5101
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
   743
    ].
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
   744
    nActions := writeCheckArray size.
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
   745
    1 to:nActions do:[:index |
20810
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   746
        checkBlock := writeCheckArray at:index.
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   747
        (checkBlock notNil and:[checkBlock value]) ifTrue:[
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   748
            sema := writeSemaphoreArray at:index.
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   749
            sema notNil ifTrue:[
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   750
                sema signalOnce.
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   751
            ].
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   752
        ]
10
claus
parents: 3
diff changeset
   753
    ].
claus
parents: 3
diff changeset
   754
231
fd0e55e352f8 cleanup
claus
parents: 217
diff changeset
   755
    "now, someone might be runnable ..."
10
claus
parents: 3
diff changeset
   756
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   757
    p := self highestPriorityRunnableProcess.
10
claus
parents: 3
diff changeset
   758
    p isNil ifTrue:[
20810
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   759
        "/ no one runnable, hard wait for event or timeout
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   760
        "/ Trace ifTrue:['w' printCR.].
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   761
        self waitForEventOrTimeout.
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   762
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   763
        "/ check for OS process termination
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   764
        gotChildSignalInterrupt ifTrue:[
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   765
            gotChildSignalInterrupt := false.
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   766
            self handleChildSignalInterrupt
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   767
        ].
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   768
        wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   769
        ^ self
10
claus
parents: 3
diff changeset
   770
    ].
claus
parents: 3
diff changeset
   771
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   772
    pri := p priority.
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   773
302
1f76060d58a4 *** empty log message ***
claus
parents: 271
diff changeset
   774
    "
1f76060d58a4 *** empty log message ***
claus
parents: 271
diff changeset
   775
     want to give control to the process p.
10
claus
parents: 3
diff changeset
   776
     If the switched-to processes priority is lower than the
10747
e9ea71d01445 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10497
diff changeset
   777
     userSchedulingPriority, we have to make certain, that the
10
claus
parents: 3
diff changeset
   778
     next input or timer will bring us back for a reschedule.
claus
parents: 3
diff changeset
   779
     This is done by enabling ioInterrupts for all file descriptors.
10747
e9ea71d01445 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10497
diff changeset
   780
     If ioInterrupts are not available (OS does not support them),
302
1f76060d58a4 *** empty log message ***
claus
parents: 271
diff changeset
   781
     we schedule a timer interrupt to interrupt us after 1/20s of a second
1f76060d58a4 *** empty log message ***
claus
parents: 271
diff changeset
   782
     - effectively polling the filedescriptors 20 times a second.
1f76060d58a4 *** empty log message ***
claus
parents: 271
diff changeset
   783
     (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
   784
     Therefore, don't let benchmarks run with low prio ...
302
1f76060d58a4 *** empty log message ***
claus
parents: 271
diff changeset
   785
10747
e9ea71d01445 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10497
diff changeset
   786
     Higher prio processes must be suspended,
302
1f76060d58a4 *** empty log message ***
claus
parents: 271
diff changeset
   787
     same prio ones must yield or suspend to get back control
1f76060d58a4 *** empty log message ***
claus
parents: 271
diff changeset
   788
    "
10
claus
parents: 3
diff changeset
   789
93
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   790
"
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   791
 uncommenting this will make timeouts interrupt the current process
10747
e9ea71d01445 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10497
diff changeset
   792
 (i.e. as if the interrupt runs at TimingPrio);
93
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   793
 if left commented, they are handled at UserSchedulingPrio.
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   794
 this will all change, when timeouts are removed and all is process driven
231
fd0e55e352f8 cleanup
claus
parents: 217
diff changeset
   795
 (a future version will have a process running to handle a timeout queue)
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   796
"
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   797
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   798
"
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   799
    pri < TimingPriority ifTrue:[
20810
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   800
        anyTimeouts ifTrue:[
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   801
            millis := self timeToNextTimeout.
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   802
            millis == 0 ifTrue:[
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   803
                wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   804
                ^ self
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
    ].
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   808
"
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   809
93
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   810
    "
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   811
     if the process to run has a lower than UserInterruptPriority,
302
1f76060d58a4 *** empty log message ***
claus
parents: 271
diff changeset
   812
     arrange for an interrupt to occur on I/O.
231
fd0e55e352f8 cleanup
claus
parents: 217
diff changeset
   813
     This is done by enabling IO-signals (if the OS supports them)
93
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   814
     or by installing a poll-interrupt after 50ms (if the OS does not).
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   815
    "
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   816
    pri < UserInterruptPriority ifTrue:[
10747
e9ea71d01445 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10497
diff changeset
   817
93
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   818
"comment out this if above is uncommented"
20810
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   819
        anyTimeouts ifTrue:[
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   820
            millis := self timeToNextTimeout.
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   821
            millis == 0 ifTrue:[
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   822
                wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   823
                ^ self
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   824
            ].
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   825
        ].
93
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   826
"---"
10
claus
parents: 3
diff changeset
   827
20810
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   828
        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
   829
"/            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
   830
"/                (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
   831
"/                    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
   832
"/                ].
02f9aa61f71b ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   833
"/            ].
20810
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   834
        ] ifFalse:[
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   835
            millis notNil ifTrue:[
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   836
                millis := millis min:EventPollingInterval
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   837
            ] ifFalse:[
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   838
                millis := EventPollingInterval
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   839
            ]
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   840
        ]
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   841
    ].
10
claus
parents: 3
diff changeset
   842
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   843
    millis notNil ifTrue:[
20810
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   844
        "/ Trace ifTrue:['C' print. millis printCR.].
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   845
        "schedule a clock interrupt after millis milliseconds"
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   846
        OperatingSystem enableTimer:millis rounded.
10
claus
parents: 3
diff changeset
   847
    ].
claus
parents: 3
diff changeset
   848
3722
1114c2014bea added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents: 3718
diff changeset
   849
    scheduledProcesses notNil ifTrue:[
20810
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   850
        scheduledProcesses add:p
3722
1114c2014bea added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents: 3718
diff changeset
   851
    ].
1114c2014bea added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents: 3718
diff changeset
   852
231
fd0e55e352f8 cleanup
claus
parents: 217
diff changeset
   853
    "
fd0e55e352f8 cleanup
claus
parents: 217
diff changeset
   854
     now let the process run - will come back here by reschedule
15438
9934d8542668 class: ProcessorScheduler
Claus Gittinger <cg@exept.de>
parents: 15402
diff changeset
   855
     from ioInterrupt, scheduler or timerInterrupt ... (running at max+1)
231
fd0e55e352f8 cleanup
claus
parents: 217
diff changeset
   856
    "
10747
e9ea71d01445 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10497
diff changeset
   857
    "/ Trace ifTrue:['->' print. p printCR.].
10
claus
parents: 3
diff changeset
   858
    self threadSwitch:p.
10747
e9ea71d01445 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10497
diff changeset
   859
    "/ Trace ifTrue:['<-' printCR.].
10
claus
parents: 3
diff changeset
   860
804
264d440a67a0 Fixes when useIOInterrupts == true.
Stefan Vogel <sv@exept.de>
parents: 786
diff changeset
   861
    "... when we arrive here, we are back on stage.
20810
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   862
         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
   863
    "
10
claus
parents: 3
diff changeset
   864
claus
parents: 3
diff changeset
   865
    millis notNil ifTrue:[
20810
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   866
        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
   867
    ].
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
   868
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
   869
    "/ 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
   870
    gotChildSignalInterrupt ifTrue:[
20810
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   871
        gotChildSignalInterrupt := false.
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   872
        self handleChildSignalInterrupt
804
264d440a67a0 Fixes when useIOInterrupts == true.
Stefan Vogel <sv@exept.de>
parents: 786
diff changeset
   873
    ].
264d440a67a0 Fixes when useIOInterrupts == true.
Stefan Vogel <sv@exept.de>
parents: 786
diff changeset
   874
264d440a67a0 Fixes when useIOInterrupts == true.
Stefan Vogel <sv@exept.de>
parents: 786
diff changeset
   875
    "/ check for new input
264d440a67a0 Fixes when useIOInterrupts == true.
Stefan Vogel <sv@exept.de>
parents: 786
diff changeset
   876
3745
3fd121f2e74e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3740
diff changeset
   877
    OperatingSystem unblockInterrupts.
3fd121f2e74e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3740
diff changeset
   878
804
264d440a67a0 Fixes when useIOInterrupts == true.
Stefan Vogel <sv@exept.de>
parents: 786
diff changeset
   879
    (gotIOInterrupt or:[useIOInterrupts not]) ifTrue:[
20810
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   880
        gotIOInterrupt := false.
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
   881
        self checkForIOWithTimeout:0.
3745
3fd121f2e74e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3740
diff changeset
   882
    ].
3fd121f2e74e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3740
diff changeset
   883
3fd121f2e74e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3740
diff changeset
   884
    wasBlocked ifTrue:[OperatingSystem blockInterrupts].
768
20434b8239f3 stefans modalBox changes (no more polling)
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
   885
3722
1114c2014bea added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents: 3718
diff changeset
   886
    "Modified: / 12.4.1996 / 10:14:18 / stefan"
1114c2014bea added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents: 3718
diff changeset
   887
    "Modified: / 3.8.1998 / 21:54:01 / cg"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   888
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   889
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   890
dispatchLoop
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   891
    "central dispatch loop; the scheduler process is always staying in
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   892
     this method, looping forever."
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   893
806
409a8c189e01 also handle termination of the scheduler process
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
   894
    |dispatchAction handlerAction ignoredSignals|
786
789e2f20de44 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 780
diff changeset
   895
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   896
    "avoid confusion if entered twice"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   897
14230
4d97053eeff0 changed: #dispatchLoop
Claus Gittinger <cg@exept.de>
parents: 13813
diff changeset
   898
    dispatching == true ifTrue:[
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   899
       Logger info:'Processor: already in dispatch'.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   900
	^ self
14230
4d97053eeff0 changed: #dispatchLoop
Claus Gittinger <cg@exept.de>
parents: 13813
diff changeset
   901
    ].
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   902
    dispatching := true.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   903
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
   904
    "/ 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
   905
    "/ 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
   906
    "/ (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
   907
    "/  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
   908
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   909
    dispatchAction :=
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   910
	[
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   911
	    [dispatching] whileTrue:[
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   912
		self dispatch
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   913
	    ]
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   914
	].
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   915
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   916
    handlerAction :=
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   917
	[:ex |
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   918
	    (HaltInterrupt accepts:ex creator) ifTrue:[
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   919
		"/ in a standalone application, we do not want those
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   920
		(Smalltalk isDebuggableApp) ifTrue:[
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   921
		    Logger info:'Processor: ignored (%1)' with:ex creator.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   922
		    "/ MiniDebugger enter. -- should this be done when some --debug/--verbose was given?
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   923
		].
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   924
		ex proceed.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   925
	    ].
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   926
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   927
	    Logger info:'Processor: caught (and ignored) signal (%1)' with:ex creator.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   928
	    ex return
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   929
	 ].
10747
e9ea71d01445 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10497
diff changeset
   930
e9ea71d01445 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10497
diff changeset
   931
    ignoredSignals := SignalSet
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   932
			with:HaltInterrupt
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   933
			with:TerminateProcessRequest
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   934
			with:RecursionError
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   935
			with:AbortAllOperationRequest.
786
789e2f20de44 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 780
diff changeset
   936
789e2f20de44 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 780
diff changeset
   937
    "/
789e2f20de44 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 780
diff changeset
   938
    "/ I made this an extra call to dispatch; this allows recompilation
789e2f20de44 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 780
diff changeset
   939
    "/  of the dispatch-handling code in the running system.
789e2f20de44 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 780
diff changeset
   940
    "/
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
   941
    [dispatching] whileTrue:[
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   942
	ignoredSignals
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   943
	    handle:handlerAction
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   944
	    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
   945
    ].
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
   946
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
   947
    "/ 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
   948
    "/ 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
   949
    "/ 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
   950
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   951
    Logger info:'Processor: finish dispatch (no more processes)'.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   952
14230
4d97053eeff0 changed: #dispatchLoop
Claus Gittinger <cg@exept.de>
parents: 13813
diff changeset
   953
    "Modified: / 20-07-2012 / 18:34:48 / cg"
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   954
    "Modified: / 19-04-2018 / 10:36:29 / stefan"
827
3eb3911cb63e Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents: 807
diff changeset
   955
! !
806
409a8c189e01 also handle termination of the scheduler process
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
   956
6434
f23d12900e18 category rename
Claus Gittinger <cg@exept.de>
parents: 6421
diff changeset
   957
!ProcessorScheduler methodsFor:'initialization'!
3522
291ec553ac33 restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents: 3312
diff changeset
   958
291ec553ac33 restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents: 3312
diff changeset
   959
initialize
291ec553ac33 restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents: 3312
diff changeset
   960
    "initialize the one-and-only ProcessorScheduler"
291ec553ac33 restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents: 3312
diff changeset
   961
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   962
    |schedulingProcess initialSize|
3522
291ec553ac33 restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents: 3312
diff changeset
   963
291ec553ac33 restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents: 3312
diff changeset
   964
    KnownProcesses isNil ifTrue:[
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   965
        initialSize := 30.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   966
        KnownProcesses := WeakArray new:initialSize.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   967
        KnownProcesses addDependent:self class.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   968
        KnownProcessIds := Array new:initialSize.
3522
291ec553ac33 restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents: 3312
diff changeset
   969
    ].
291ec553ac33 restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents: 3312
diff changeset
   970
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
     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
   973
    "
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   974
    quiescentProcessLists := Array new:SchedulingPriority.  "/ SchedulingPriority is even higher than HighestPriority
3967
5e0053fdbf52 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3917
diff changeset
   975
5e0053fdbf52 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3917
diff changeset
   976
    readFdArray := Array new:5.
5e0053fdbf52 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3917
diff changeset
   977
    readCheckArray := Array new:5.
5e0053fdbf52 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3917
diff changeset
   978
    readSemaphoreArray := Array new:5.
5e0053fdbf52 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3917
diff changeset
   979
    writeFdArray := Array new:3.
5101
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
   980
    writeCheckArray := Array new:3.
3967
5e0053fdbf52 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3917
diff changeset
   981
    writeSemaphoreArray := Array new:3.
18957
e0bb91eae748 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18941
diff changeset
   982
    exceptFdArray := Array new:3.
e0bb91eae748 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18941
diff changeset
   983
    exceptSemaphoreArray := Array new:3.
e0bb91eae748 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18941
diff changeset
   984
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   985
    timeoutArray := Array new:10.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   986
    timeoutSemaphoreArray := Array new:10.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   987
    timeoutActionArray := Array new:10.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
   988
    timeoutProcessArray := Array new:10.
3967
5e0053fdbf52 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3917
diff changeset
   989
3522
291ec553ac33 restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents: 3312
diff changeset
   990
    anyTimeouts := false.
291ec553ac33 restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents: 3312
diff changeset
   991
    dispatching := false.
291ec553ac33 restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents: 3312
diff changeset
   992
    useIOInterrupts := OperatingSystem supportsIOInterrupts.
291ec553ac33 restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents: 3312
diff changeset
   993
    gotIOInterrupt := false.
291ec553ac33 restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents: 3312
diff changeset
   994
    osChildExitActions := Dictionary new.
291ec553ac33 restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents: 3312
diff changeset
   995
    gotChildSignalInterrupt := false.
19850
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
   996
    interruptCounter := timedActionCounter := 0.
3522
291ec553ac33 restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents: 3312
diff changeset
   997
17412
ef9b82b8ce77 class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 17341
diff changeset
   998
    supportDynamicPriorities := false.
ef9b82b8ce77 class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 17341
diff changeset
   999
    exitWhenNoMoreUserProcesses isNil ifTrue:[
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1000
        exitWhenNoMoreUserProcesses := false. "/ mhmh - how about true ?
17412
ef9b82b8ce77 class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 17341
diff changeset
  1001
    ].
ef9b82b8ce77 class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 17341
diff changeset
  1002
3522
291ec553ac33 restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents: 3312
diff changeset
  1003
    "
291ec553ac33 restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents: 3312
diff changeset
  1004
     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
  1005
     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
  1006
     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
  1007
     for a runnable process.
291ec553ac33 restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents: 3312
diff changeset
  1008
    "
291ec553ac33 restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents: 3312
diff changeset
  1009
    currentPriority := SchedulingPriority.
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1010
    schedulingProcess := Process basicNew.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1011
    schedulingProcess
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1012
        setId:SysProcessId state:#run;
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1013
        setPriority:currentPriority;
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1014
        name:'System: scheduler';
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1015
        beSystemProcess.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1016
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1017
    scheduler := activeProcess := schedulingProcess.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1018
    activeProcessId := 0.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1019
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1020
    quiescentProcessLists
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1021
        at:currentPriority put:(LinkedList with:schedulingProcess).
3522
291ec553ac33 restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents: 3312
diff changeset
  1022
291ec553ac33 restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents: 3312
diff changeset
  1023
    "
291ec553ac33 restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents: 3312
diff changeset
  1024
     let me handle IO and timer interrupts
291ec553ac33 restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents: 3312
diff changeset
  1025
    "
5406
4a6995b61c0e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5396
diff changeset
  1026
    useIOInterrupts ifTrue:[ObjectMemory ioInterruptHandler:self].
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1027
    ObjectMemory
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1028
        timerInterruptHandler:self;
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1029
        childSignalInterruptHandler:self.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1030
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1031
    "Modified: / 07-01-1997 / 16:48:26 / stefan"
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1032
    "Modified: / 04-02-1999 / 13:08:39 / cg"
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1033
    "Modified: / 15-08-2018 / 15:03:50 / Claus Gittinger"
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1034
    "Modified: / 05-02-2020 / 16:06:38 / Stefan Vogel"
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
reinitialize
10747
e9ea71d01445 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10497
diff changeset
  1038
    "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
  1039
     - 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
  1040
     especially, windowgroups have to.
291ec553ac33 restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents: 3312
diff changeset
  1041
     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
  1042
     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
  1043
     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
  1044
     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
  1045
     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
  1046
     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
  1047
     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
  1048
     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
  1049
3525
26fe903e0250 oops - no need for last change
Claus Gittinger <cg@exept.de>
parents: 3522
diff changeset
  1050
    |processesToRestart|
26fe903e0250 oops - no need for last change
Claus Gittinger <cg@exept.de>
parents: 3522
diff changeset
  1051
3522
291ec553ac33 restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents: 3312
diff changeset
  1052
    "
291ec553ac33 restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents: 3312
diff changeset
  1053
     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
  1054
    "
291ec553ac33 restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents: 3312
diff changeset
  1055
    processesToRestart := OrderedCollection new.
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1056
    KnownProcesses nonNilElementsDo:[:p |
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1057
	"how, exactly should this be done ?"
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1058
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1059
	p isRestartable ifTrue:[
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1060
	    p nextLink:nil.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1061
	    processesToRestart add:p
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1062
	] ifFalse:[
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1063
	    p setId:nil state:#dead
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1064
	].
3522
291ec553ac33 restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents: 3312
diff changeset
  1065
    ].
10747
e9ea71d01445 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10497
diff changeset
  1066
    scheduler setId:nil state:#dead.
3522
291ec553ac33 restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents: 3312
diff changeset
  1067
291ec553ac33 restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents: 3312
diff changeset
  1068
    "
291ec553ac33 restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents: 3312
diff changeset
  1069
     now, start from scratch
291ec553ac33 restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents: 3312
diff changeset
  1070
    "
291ec553ac33 restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents: 3312
diff changeset
  1071
    KnownProcesses := nil.
291ec553ac33 restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents: 3312
diff changeset
  1072
    self initialize.
291ec553ac33 restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents: 3312
diff changeset
  1073
3525
26fe903e0250 oops - no need for last change
Claus Gittinger <cg@exept.de>
parents: 3522
diff changeset
  1074
    processesToRestart do:[:p |
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1075
	p imageRestart
3522
291ec553ac33 restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents: 3312
diff changeset
  1076
    ]
291ec553ac33 restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents: 3312
diff changeset
  1077
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1078
    "Modified: / 05-02-2020 / 16:19:12 / Stefan Vogel"
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1079
    "Modified: / 01-06-2020 / 14:10:06 / cg"
3522
291ec553ac33 restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents: 3312
diff changeset
  1080
! !
291ec553ac33 restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents: 3312
diff changeset
  1081
3777
f351744c575f fix terminate/interrupt/reschedule while in osWait (win32)
Claus Gittinger <cg@exept.de>
parents: 3745
diff changeset
  1082
!ProcessorScheduler methodsFor:'native thread support'!
f351744c575f fix terminate/interrupt/reschedule while in osWait (win32)
Claus Gittinger <cg@exept.de>
parents: 3745
diff changeset
  1083
7842
c6ce40656157 preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents: 7761
diff changeset
  1084
vmResumeInterrupt:id
10747
e9ea71d01445 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10497
diff changeset
  1085
    "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
  1086
     MUST be invoked with interrupts blocked.
c6ce40656157 preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents: 7761
diff changeset
  1087
     This is only used with native threads."
c6ce40656157 preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents: 7761
diff changeset
  1088
8504
93b46834c68f #unblockInterrupts returns the prvious blocking state
Stefan Vogel <sv@exept.de>
parents: 8494
diff changeset
  1089
    <context: #return>
93b46834c68f #unblockInterrupts returns the prvious blocking state
Stefan Vogel <sv@exept.de>
parents: 8494
diff changeset
  1090
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1091
    |index pri aProcess listAtPrio|
7842
c6ce40656157 preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents: 7761
diff changeset
  1092
c6ce40656157 preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents: 7761
diff changeset
  1093
    OperatingSystem interruptsBlocked ifFalse:[
19850
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  1094
	MiniDebugger
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  1095
	    enterWithMessage:'vmResumeInterrupt with no interruptsBlocked'
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  1096
	    mayProceed:true.
7842
c6ce40656157 preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents: 7761
diff changeset
  1097
    ].
c6ce40656157 preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents: 7761
diff changeset
  1098
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1099
    index := KnownProcessIds identityIndexOf:id startingAt:1.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1100
    index == 0 ifTrue:[
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1101
	Logger info:'Processor: resumeIRQ for unknown process: %1' with:id.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1102
	^ self.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1103
    ].
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1104
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1105
    aProcess := KnownProcesses at:index.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1106
    aProcess isNil ifTrue:[
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1107
	Logger info:'Processor: resumeIRQ for dead process: %1' with:id.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1108
	^ self.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1109
    ].
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1110
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1111
    pri := aProcess priority.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1112
    listAtPrio := quiescentProcessLists at:pri.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1113
    listAtPrio notNil ifTrue:[
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1114
	(listAtPrio includesIdentical:aProcess) ifTrue:[
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1115
	    "/ aProcess is on a run queue.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1116
	    "/ CG: this situation may happen, if the wrapCall
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1117
	    "/ finishes before the process was layed to sleep
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1118
	    "/ (i.e. schedulerIRQ arrives before the threadSwitch was finished).
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1119
	    "/ In that case, simply resume it and everything is OK.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1120
	    "/ If the process is state running, ignore.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1121
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1122
	    |state|
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1123
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1124
	    state := aProcess state.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1125
	    (state == #wrapWait or:[(state == #osWait) or:[state == #stopped]]) ifTrue:[
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1126
		aProcess setStateRun.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1127
	    ].
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1128
	    Logger info:'Processor: resumeIRQ ignored for process: %1  in state: %2'
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1129
		   with:aProcess id with:state.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1130
	    ^ self
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1131
	]
7842
c6ce40656157 preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents: 7761
diff changeset
  1132
    ] ifFalse:[
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1133
	listAtPrio := LinkedList new.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1134
	quiescentProcessLists at:pri put:listAtPrio.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1135
    ].
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1136
    listAtPrio addLast:aProcess.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1137
    aProcess setStateRun.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1138
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1139
    "Modified: / 29-05-2019 / 01:05:42 / Claus Gittinger"
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1140
    "Modified: / 28-05-2020 / 12:10:01 / cg"
7842
c6ce40656157 preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents: 7761
diff changeset
  1141
!
c6ce40656157 preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents: 7761
diff changeset
  1142
7844
906062102891 preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents: 7843
diff changeset
  1143
vmSuspendInterrupt:whyCode
7842
c6ce40656157 preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents: 7761
diff changeset
  1144
    "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
  1145
     Invoked before the VM switches to the scheduler process.
7842
c6ce40656157 preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents: 7761
diff changeset
  1146
     MUST be invoked with interrupts blocked.
c6ce40656157 preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents: 7761
diff changeset
  1147
     This is only used with native threads."
c6ce40656157 preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents: 7761
diff changeset
  1148
8504
93b46834c68f #unblockInterrupts returns the prvious blocking state
Stefan Vogel <sv@exept.de>
parents: 8494
diff changeset
  1149
    <context: #return>
93b46834c68f #unblockInterrupts returns the prvious blocking state
Stefan Vogel <sv@exept.de>
parents: 8494
diff changeset
  1150
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1151
    |pri listAtPrio newState|
7842
c6ce40656157 preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents: 7761
diff changeset
  1152
c6ce40656157 preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents: 7761
diff changeset
  1153
    OperatingSystem interruptsBlocked ifFalse:[
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1154
	MiniDebugger
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1155
	    enterWithMessage:'immediateInterrupt with no interruptsBlocked'
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1156
	    mayProceed:true.
7842
c6ce40656157 preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents: 7761
diff changeset
  1157
    ].
c6ce40656157 preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents: 7761
diff changeset
  1158
7844
906062102891 preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents: 7843
diff changeset
  1159
    (whyCode == 2) ifTrue:[
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1160
	 newState := #wrapWait.
7843
922a4285375a preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents: 7842
diff changeset
  1161
    ] ifFalse:[
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1162
	(whyCode == 3) ifTrue:[
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1163
	    newState := #osWait.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1164
	] ifFalse:[
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1165
	    newState := #stopped.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1166
	].
7843
922a4285375a preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents: 7842
diff changeset
  1167
    ].
7842
c6ce40656157 preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents: 7761
diff changeset
  1168
    activeProcess setStateTo:newState if:#active.
c6ce40656157 preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents: 7761
diff changeset
  1169
c6ce40656157 preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents: 7761
diff changeset
  1170
    pri := activeProcess priority.
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1171
    listAtPrio := quiescentProcessLists at:pri.
7842
c6ce40656157 preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents: 7761
diff changeset
  1172
c6ce40656157 preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents: 7761
diff changeset
  1173
    "notice: this is slightly faster than putting the if-code into
c6ce40656157 preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents: 7761
diff changeset
  1174
     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
  1175
    "
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1176
    (listAtPrio isNil
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1177
     or:[(listAtPrio removeIdentical:activeProcess ifAbsent:nil) isNil]) ifTrue:[
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1178
	"/ the vm wants to suspend a not running thread.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1179
	"/ should not, but does happen, although very seldom (a race condition?)
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1180
	"/ ignore in standalone apps; enter a minidebugger if not.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1181
	"/ it is (currently not clear, how this happens, but seems to be harmless)
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1182
	Logger warning:'Processor [warning]: bad vmSuspendInterrupt: process not on run list'.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1183
	Smalltalk isDebuggableApp ifTrue:[
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1184
	    MiniDebugger enterWithMessage:'bad vmSuspendInterrupt: not on run list' mayProceed:true.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1185
	].
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1186
	^ self
7842
c6ce40656157 preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents: 7761
diff changeset
  1187
    ].
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1188
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1189
    "Modified: / 31-03-2017 / 13:12:49 / cg"
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1190
    "Modified: / 19-04-2018 / 10:37:55 / stefan"
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1191
    "Modified (format): / 05-02-2020 / 16:15:18 / Stefan Vogel"
3777
f351744c575f fix terminate/interrupt/reschedule while in osWait (win32)
Claus Gittinger <cg@exept.de>
parents: 3745
diff changeset
  1192
! !
f351744c575f fix terminate/interrupt/reschedule while in osWait (win32)
Claus Gittinger <cg@exept.de>
parents: 3745
diff changeset
  1193
827
3eb3911cb63e Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents: 807
diff changeset
  1194
!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
  1195
3eb3911cb63e Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents: 807
diff changeset
  1196
childSignalInterrupt
2116
1bcb6ee86fca fixed pending sigChild problem;
Claus Gittinger <cg@exept.de>
parents: 2111
diff changeset
  1197
    "{ Pragma: +returnable }"
1bcb6ee86fca fixed pending sigChild problem;
Claus Gittinger <cg@exept.de>
parents: 2111
diff changeset
  1198
10747
e9ea71d01445 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10497
diff changeset
  1199
    "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
  1200
     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
  1201
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
  1202
    gotChildSignalInterrupt := true.
20052
4bd27ae52593 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19859
diff changeset
  1203
    interruptCounter := interruptCounter + 1 bitAnd:SmallInteger maxVal.
2966
856dfc8a294a lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2962
diff changeset
  1204
    activeProcess ~~ scheduler ifTrue:[
20706
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  1205
	interruptCounter := interruptCounter + 1 bitAnd:SmallInteger maxVal.
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  1206
	interruptedProcess := activeProcess.
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  1207
	self threadSwitch:scheduler
2966
856dfc8a294a lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2962
diff changeset
  1208
    ]
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
  1209
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
  1210
    "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
  1211
!
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
  1212
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
  1213
handleChildSignalInterrupt
827
3eb3911cb63e Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents: 807
diff changeset
  1214
    "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
  1215
     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
  1216
523533898acd Reset sigCHLD interrupt handler, when no more processes are being waited for.
Stefan Vogel <sv@exept.de>
parents: 829
diff changeset
  1217
    |osProcessStatus blocking wasBlocked|
827
3eb3911cb63e Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents: 807
diff changeset
  1218
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1219
    "/ blocking waits are no longer supported - see ProcessorScheduler>>#monitor:action:
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1220
    blocking := OperatingSystem blockingChildProcessWait.
827
3eb3911cb63e Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents: 807
diff changeset
  1221
840
523533898acd Reset sigCHLD interrupt handler, when no more processes are being waited for.
Stefan Vogel <sv@exept.de>
parents: 829
diff changeset
  1222
    "/ 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
  1223
    wasBlocked := OperatingSystem blockInterrupts.
827
3eb3911cb63e Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents: 807
diff changeset
  1224
    [
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1225
	[
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1226
	    osProcessStatus := OperatingSystem childProcessWait:blocking pid:nil.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1227
	    osProcessStatus notNil ifTrue:[
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1228
		|pid action|
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1229
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1230
		pid := osProcessStatus pid.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1231
		osProcessStatus stillAlive ifTrue:[
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1232
		    action := osChildExitActions at:pid ifAbsent:nil.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1233
		] ifFalse:[
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1234
		    action := osChildExitActions removeKey:pid ifAbsent:nil.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1235
		].
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1236
		action notNil ifTrue:[
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1237
		    action value:osProcessStatus
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1238
		].
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1239
	    ].
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1240
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1241
	    "/ if pollChildProcesses does block, poll only one status change.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1242
	    "/ we will get another SIGCHLD for other status changes.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1243
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1244
	    osProcessStatus notNil and:[blocking not]
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1245
	] whileTrue.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1246
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1247
	"/ if there are no more waiters, disable SIGCHILD handler.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1248
	"/ this helps us with synchronous waiters (e.g. pclose),
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1249
	"/ But they should block SIGCHLD anyway.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1250
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1251
	osChildExitActions isEmpty ifTrue:[
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1252
	    OperatingSystem disableChildSignalInterrupts.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1253
	].
6421
58dca33cf0fc #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 6376
diff changeset
  1254
    ] ensure:[
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1255
	wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
1032
924c177085f8 care to reenable interrupts
Claus Gittinger <cg@exept.de>
parents: 1001
diff changeset
  1256
    ]
827
3eb3911cb63e Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents: 807
diff changeset
  1257
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1258
    "Modified: / 28-02-1996 / 21:36:31 / cg"
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1259
    "Created: / 12-04-1996 / 10:08:21 / stefan"
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1260
    "Modified: / 29-03-2018 / 16:00:34 / stefan"
827
3eb3911cb63e Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents: 807
diff changeset
  1261
!
3eb3911cb63e Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents: 807
diff changeset
  1262
2499
95392696facc Fix race condition when waiting for SIGCHLD.
Stefan Vogel <sv@exept.de>
parents: 2468
diff changeset
  1263
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
  1264
    "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
  1265
     aBlockReturningPid is evaluated and supposed to return
95392696facc Fix race condition when waiting for SIGCHLD.
Stefan Vogel <sv@exept.de>
parents: 2468
diff changeset
  1266
     the process-id of an OS-process or nil.
10747
e9ea71d01445 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10497
diff changeset
  1267
     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
  1268
     within the block.
95392696facc Fix race condition when waiting for SIGCHLD.
Stefan Vogel <sv@exept.de>
parents: 2468
diff changeset
  1269
     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
  1270
     status of the OS process changes (e.g. the process terminates).
20053
b46edac25a4e #DOCUMENTATION by mawalch
mawalch
parents: 20052
diff changeset
  1271
     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
  1272
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1273
    |pid waitedForactionBlock wasBlocked osProcessStatus|
16338
b8defcce7efc class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16322
diff changeset
  1274
b8defcce7efc class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16322
diff changeset
  1275
    "/ aBlock will be evaluated:
b8defcce7efc class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16322
diff changeset
  1276
    "/   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
  1277
    "/   on win:  as soon as a select for the pid handle returns
b8defcce7efc class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16322
diff changeset
  1278
b8defcce7efc class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16322
diff changeset
  1279
    OperatingSystem enableChildSignalInterrupts.        "/ no-op in windows
b8defcce7efc class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16322
diff changeset
  1280
    wasBlocked := OperatingSystem blockInterrupts.
b8defcce7efc class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16322
diff changeset
  1281
    "/ start the OS-Process
b8defcce7efc class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16322
diff changeset
  1282
    pid := aBlockReturningPid value.
b8defcce7efc class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16322
diff changeset
  1283
    pid notNil ifTrue:[
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1284
        osChildExitActions at:pid put:actionBlock.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1285
        "check for a race, that SIGCHILD was received before we could register the actionBlock"
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1286
        osProcessStatus := OperatingSystem childProcessWait:false pid:pid.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1287
        osProcessStatus notNil ifTrue:[
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1288
            "be careful, some implementations of #childProcessWait:pid:
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1289
             (wait() and wait3() in very old unixes) wait for any pid!!"
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1290
            osProcessStatus stillAlive ifTrue:[
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1291
                waitedForactionBlock := osChildExitActions at:pid ifAbsent:nil.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1292
            ] ifFalse:[
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1293
                waitedForactionBlock := osChildExitActions removeKey:pid ifAbsent:nil.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1294
            ].
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1295
            waitedForactionBlock notNil ifTrue:[
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1296
                waitedForactionBlock value:osProcessStatus
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1297
            ].
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1298
        ].
840
523533898acd Reset sigCHLD interrupt handler, when no more processes are being waited for.
Stefan Vogel <sv@exept.de>
parents: 829
diff changeset
  1299
    ].
16338
b8defcce7efc class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16322
diff changeset
  1300
    wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
2499
95392696facc Fix race condition when waiting for SIGCHLD.
Stefan Vogel <sv@exept.de>
parents: 2468
diff changeset
  1301
    ^ pid
95392696facc Fix race condition when waiting for SIGCHLD.
Stefan Vogel <sv@exept.de>
parents: 2468
diff changeset
  1302
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1303
    "Created: / 25-03-1997 / 10:54:56 / stefan"
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1304
    "Modified: / 15-04-1997 / 11:55:57 / David"
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1305
    "Modified: / 27-04-1999 / 20:09:38 / cg"
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1306
    "Modified (format): / 29-03-2018 / 15:53:53 / stefan"
1166
f5affd8cb289 added #unmonitorPid: - there still is trouble with zombie subchilds, if a process is killed via #killProcess:
Claus Gittinger <cg@exept.de>
parents: 1154
diff changeset
  1307
!
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
  1308
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
  1309
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
  1310
    "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
  1311
2966
856dfc8a294a lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2962
diff changeset
  1312
    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
  1313
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
  1314
    "Created: 12.4.1996 / 19:01:59 / cg"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1315
! !
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1316
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1317
!ProcessorScheduler methodsFor:'primitive process primitives'!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1318
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1319
scheduleForInterrupt:aProcess
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1320
    "make aProcess evaluate its pushed interrupt block(s)"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1321
1092
2a8acc60f5b5 added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents: 1086
diff changeset
  1322
    self scheduleInterruptActionsOf:aProcess.
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1323
    aProcess isStopped ifFalse:[
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1324
	"
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1325
	 make the process runnable
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1326
	"
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1327
	self resume:aProcess
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1328
    ]
1092
2a8acc60f5b5 added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents: 1086
diff changeset
  1329
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1330
    "Modified: / 24-08-1998 / 18:31:32 / cg"
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1331
    "Modified: / 29-05-2019 / 01:05:10 / Claus Gittinger"
1092
2a8acc60f5b5 added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents: 1086
diff changeset
  1332
!
2a8acc60f5b5 added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents: 1086
diff changeset
  1333
2a8acc60f5b5 added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents: 1086
diff changeset
  1334
scheduleInterruptActionsOf:aProcess
2a8acc60f5b5 added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents: 1086
diff changeset
  1335
    "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
  1336
     when resumed."
2a8acc60f5b5 added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents: 1086
diff changeset
  1337
2a8acc60f5b5 added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents: 1086
diff changeset
  1338
    aProcess isNil ifTrue:[^ self].
2a8acc60f5b5 added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents: 1086
diff changeset
  1339
    aProcess == activeProcess ifTrue:[^ self].
2a8acc60f5b5 added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents: 1086
diff changeset
  1340
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1341
    self class threadInterrupt:aProcess id.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1342
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1343
    "Created: / 05-03-1996 / 17:25:55 / cg"
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1344
    "Modified: / 20-02-2017 / 10:51:23 / stefan"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1345
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1346
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1347
threadSwitch:aProcess
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1348
    "continue execution in aProcess.
1783
be7402f74d94 hide timerInterrupt & ioInterrupt contexts when switching
Claus Gittinger <cg@exept.de>
parents: 1780
diff changeset
  1349
     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
  1350
3644
dacb2b9d4867 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3566
diff changeset
  1351
    |id pri ok oldProcess oldPri oldId p nm singleStep wasBlocked|
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1352
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1353
    (aProcess isNil or:[aProcess == activeProcess]) ifTrue:[^ self].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1354
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1355
    wasBlocked := OperatingSystem blockInterrupts.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1356
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1357
    oldProcess := activeProcess.
2262
4c4d810f006f semaphore names
Claus Gittinger <cg@exept.de>
parents: 2258
diff changeset
  1358
    oldId := activeProcessId.
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1359
    oldPri := currentPriority.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1360
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1361
    id := aProcess id.
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1362
    id class == SmallInteger ifFalse:[
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1363
        Logger error: 'Bad id in process %1' with: aProcess.        
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1364
    ].
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1365
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1366
    pri := aProcess priority.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1367
    singleStep := aProcess isSingleStepping.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1368
    aProcess state:#active.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1369
    oldProcess setStateTo:#run if:#active.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1370
5449
bf1de72fd2bb preps for rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5406
diff changeset
  1371
    currentPriority := pri.
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1372
    activeProcess := aProcess.
2262
4c4d810f006f semaphore names
Claus Gittinger <cg@exept.de>
parents: 2258
diff changeset
  1373
    activeProcessId := id.
12958
fc084b295df6 changed: #threadSwitch:
Claus Gittinger <cg@exept.de>
parents: 12717
diff changeset
  1374
fc084b295df6 changed: #threadSwitch:
Claus Gittinger <cg@exept.de>
parents: 12717
diff changeset
  1375
    "
fc084b295df6 changed: #threadSwitch:
Claus Gittinger <cg@exept.de>
parents: 12717
diff changeset
  1376
     no interrupts now - activeProcess has already been changed
20810
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
  1377
     (don't add any message sends here)
12958
fc084b295df6 changed: #threadSwitch:
Claus Gittinger <cg@exept.de>
parents: 12717
diff changeset
  1378
    "
fc084b295df6 changed: #threadSwitch:
Claus Gittinger <cg@exept.de>
parents: 12717
diff changeset
  1379
"/    ok := self threadSwitchFrom:oldProcess to:aProcess id:id singleStep:singleStep.
fc084b295df6 changed: #threadSwitch:
Claus Gittinger <cg@exept.de>
parents: 12717
diff changeset
  1380
%{
fc084b295df6 changed: #threadSwitch:
Claus Gittinger <cg@exept.de>
parents: 12717
diff changeset
  1381
    extern OBJ ___threadSwitch();
fc084b295df6 changed: #threadSwitch:
Claus Gittinger <cg@exept.de>
parents: 12717
diff changeset
  1382
fc084b295df6 changed: #threadSwitch:
Claus Gittinger <cg@exept.de>
parents: 12717
diff changeset
  1383
    if (__isSmallInteger(id)) {
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1384
        ok = ___threadSwitch(__context, __intVal(id), singleStep == true, 0);
12958
fc084b295df6 changed: #threadSwitch:
Claus Gittinger <cg@exept.de>
parents: 12717
diff changeset
  1385
    } else {
20810
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
  1386
        ok = false;
12958
fc084b295df6 changed: #threadSwitch:
Claus Gittinger <cg@exept.de>
parents: 12717
diff changeset
  1387
    }
fc084b295df6 changed: #threadSwitch:
Claus Gittinger <cg@exept.de>
parents: 12717
diff changeset
  1388
%}.
5449
bf1de72fd2bb preps for rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5406
diff changeset
  1389
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1390
    "time passes spent in some other process ...
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1391
     ... here again"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1392
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1393
    p := activeProcess.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1394
    activeProcess := oldProcess.
2262
4c4d810f006f semaphore names
Claus Gittinger <cg@exept.de>
parents: 2258
diff changeset
  1395
    activeProcessId := oldId.
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1396
    currentPriority := oldProcess priority.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1397
21009
d4035978c3c7 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20964
diff changeset
  1398
    ok ~~ true ifTrue:[
20810
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
  1399
        "
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
  1400
         switch failed for some reason -
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
  1401
         destroy (hard-terminate) the bad process.
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
  1402
         This happens when:
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
  1403
         - the stack went above the absolute limit
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
  1404
           (VM switches back to scheduler)
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
  1405
         - a halted process cannot execute its interrupt
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
  1406
           actions (win32 only)
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
  1407
        "
21009
d4035978c3c7 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20964
diff changeset
  1408
        id := p id.
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1409
        (id ~~ 0 and:[id notNil]) ifTrue:[
21009
d4035978c3c7 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20964
diff changeset
  1410
            ok == #halted ifTrue:[
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1411
               "/ that process was halted (win32 only)
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1412
               Logger warning:'Processor: problem (%1) with process %2 (%3); stop it' with:ok with:id with:p name.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1413
               p state:#halted.
21009
d4035978c3c7 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20964
diff changeset
  1414
               self suspend:p.
d4035978c3c7 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20964
diff changeset
  1415
            ] ifFalse:[
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1416
               Logger warning:'Processor: problem (%1) with process %2 (%3); hard-terminate it' with:ok with:id with:p name.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1417
               Logger info:'Processor: cleanup may take a while if stack is huge'.
21009
d4035978c3c7 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20964
diff changeset
  1418
               p state:#cleanup.
d4035978c3c7 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20964
diff changeset
  1419
               self terminateNoSignal:p.
20810
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
  1420
            ]
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
  1421
        ]
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1422
    ].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1423
    zombie notNil ifTrue:[
21284
4662d72c8a26 #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 21240
diff changeset
  1424
        "delayed processing of terminated process (see #terminateNoSignal)"
20810
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
  1425
        self class threadDestroy:zombie.
86f0131cd99a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20763
diff changeset
  1426
        zombie := nil
1783
be7402f74d94 hide timerInterrupt & ioInterrupt contexts when switching
Claus Gittinger <cg@exept.de>
parents: 1780
diff changeset
  1427
    ].
be7402f74d94 hide timerInterrupt & ioInterrupt contexts when switching
Claus Gittinger <cg@exept.de>
parents: 1780
diff changeset
  1428
    wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
12958
fc084b295df6 changed: #threadSwitch:
Claus Gittinger <cg@exept.de>
parents: 12717
diff changeset
  1429
fc084b295df6 changed: #threadSwitch:
Claus Gittinger <cg@exept.de>
parents: 12717
diff changeset
  1430
    "Modified: / 23-07-2010 / 10:32:11 / cg"
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1431
    "Modified: / 03-05-2018 / 17:24:42 / stefan"
1787
32632b6f969d remember threadSwitch:from: idea for later implementation;
Claus Gittinger <cg@exept.de>
parents: 1783
diff changeset
  1432
! !
32632b6f969d remember threadSwitch:from: idea for later implementation;
Claus Gittinger <cg@exept.de>
parents: 1783
diff changeset
  1433
1981
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1434
!ProcessorScheduler methodsFor:'priority constants'!
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
highIOPriority
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1437
    "not currently used - for ST80 compatibility only"
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1438
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1439
    ^ 16 "claus: is this ok ?"
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1440
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1441
    "Created: 15.11.1996 / 11:42:39 / cg"
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1442
!
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1443
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1444
highestPriority
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1445
    "return the highest priority value (normal) processes can have."
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1446
10747
e9ea71d01445 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10497
diff changeset
  1447
    "must be below schedulingPriority -
1981
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1448
     otherwise scheduler could be blocked ...
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1449
    "
10747
e9ea71d01445 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10497
diff changeset
  1450
    ^ HighestPriority
1981
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1451
!
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1452
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1453
lowIOPriority
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1454
    "not currently used - for ST80 compatibility only"
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
    ^ 2 "claus: is this ok ?"
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1457
!
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1458
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1459
lowestPriority
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1460
    "return the lowest priority value"
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
    ^ 1   "do not change this - its not variable"
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1463
!
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1464
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1465
schedulingPriority
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1466
    "return the priority at which the scheduler runs."
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1467
10747
e9ea71d01445 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10497
diff changeset
  1468
    "must be above highestPriority -
1981
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1469
     otherwise scheduler could be blocked ...
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
    ^ SchedulingPriority
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1472
!
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1473
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1474
systemBackgroundPriority
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1475
    "return the priority, at which background system processing
7076
738bbff659e8 comments
Claus Gittinger <cg@exept.de>
parents: 7046
diff changeset
  1476
     should take place."
1981
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1477
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1478
    ^ 4
7076
738bbff659e8 comments
Claus Gittinger <cg@exept.de>
parents: 7046
diff changeset
  1479
738bbff659e8 comments
Claus Gittinger <cg@exept.de>
parents: 7046
diff changeset
  1480
    "
738bbff659e8 comments
Claus Gittinger <cg@exept.de>
parents: 7046
diff changeset
  1481
     Processor systemBackgroundPriority
738bbff659e8 comments
Claus Gittinger <cg@exept.de>
parents: 7046
diff changeset
  1482
    "
1981
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1483
!
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1484
2190
8afa4709d8a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2188
diff changeset
  1485
timeSlicingPriorityLimit
8afa4709d8a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2188
diff changeset
  1486
    "return the priority, above which no timeslicing takes place
8afa4709d8a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2188
diff changeset
  1487
     (i.e. processes running at a higher priority are not preempted).
8afa4709d8a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2188
diff changeset
  1488
     This is only effective, if preemption is enabled."
8afa4709d8a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2188
diff changeset
  1489
8afa4709d8a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2188
diff changeset
  1490
    ^ TimeSlicingPriorityLimit
8afa4709d8a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2188
diff changeset
  1491
!
8afa4709d8a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2188
diff changeset
  1492
2191
6c641780265d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2190
diff changeset
  1493
timingPriority
6c641780265d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2190
diff changeset
  1494
    "return the priority, at which all timing takes place (messageTally,
6c641780265d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2190
diff changeset
  1495
     delay etc.)"
6c641780265d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2190
diff changeset
  1496
6c641780265d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2190
diff changeset
  1497
    ^ TimingPriority
6c641780265d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2190
diff changeset
  1498
!
6c641780265d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2190
diff changeset
  1499
1981
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1500
userBackgroundPriority
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1501
    "return the priority, at which background user (non-interactive) processing
7076
738bbff659e8 comments
Claus Gittinger <cg@exept.de>
parents: 7046
diff changeset
  1502
     should take place."
1981
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1503
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1504
    ^ 6
7076
738bbff659e8 comments
Claus Gittinger <cg@exept.de>
parents: 7046
diff changeset
  1505
738bbff659e8 comments
Claus Gittinger <cg@exept.de>
parents: 7046
diff changeset
  1506
    "
738bbff659e8 comments
Claus Gittinger <cg@exept.de>
parents: 7046
diff changeset
  1507
     Processor userBackgroundPriority
738bbff659e8 comments
Claus Gittinger <cg@exept.de>
parents: 7046
diff changeset
  1508
    "
1981
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1509
!
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1510
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1511
userInterruptPriority
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1512
    "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
  1513
     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
  1514
     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
  1515
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1516
    ^ UserInterruptPriority
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1517
!
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1518
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1519
userSchedulingPriority
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1520
    "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
  1521
     takes place"
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1522
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1523
    ^ UserSchedulingPriority
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1524
! !
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1525
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1526
!ProcessorScheduler methodsFor:'private'!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1527
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1528
remember:aProcess
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1529
    "remember aProcess for later disposal (where the underlying
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1530
     system resources have to be freed)."
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1531
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1532
    |newShadows newIDs oldId wasBlocked
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1533
     oldSize "{ Class: SmallInteger }"
1787
32632b6f969d remember threadSwitch:from: idea for later implementation;
Claus Gittinger <cg@exept.de>
parents: 1783
diff changeset
  1534
     sz      "{ Class: SmallInteger }" |
699
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
    wasBlocked := OperatingSystem blockInterrupts.
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1537
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1538
    "/ '---------- remember ' printOn:Stderr. aProcess printOn:Stderr. ' ' printOn:Stderr.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1539
    "/ (ObjectMemory addressOf:aProcess) hexPrintString printOn:Stderr.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1540
    "/ c'\n' printOn:Stderr.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1541
    "/
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1542
    "/ c'KnownProcesses: ' printOn:Stderr.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1543
    "/ KnownProcesses printOn:Stderr.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1544
    "/ c'\n' printOn:Stderr.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1545
    "/ c'KnownProcessIds: ' printOn:Stderr.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1546
    "/ KnownProcessIds printOn:Stderr.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1547
    "/ c'\n' printOn:Stderr.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1548
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1549
    sz := KnownProcessIds size.
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1550
    "first: try to find an empty slot"
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1551
    1 to:sz do:[:index|
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1552
	(KnownProcesses at:index) isNil ifTrue:[
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1553
	    oldId := KnownProcessIds at:index.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1554
	    oldId notNil ifTrue:[
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1555
		"Process object has been collected,
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1556
		 but thread is still present - destroy the thread"
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1557
		self class threadDestroy:oldId.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1558
	    ].
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1559
	    KnownProcesses at:index put:aProcess.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1560
	    KnownProcessIds at:index put:aProcess id.
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1561
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1562
	    "/ '********************* after (1): ' printOn:Stderr.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1563
	    "/ c'\nprocesses: ' printOn:Stderr.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1564
	    "/ KnownProcesses printOn:Stderr.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1565
	    "/ c'\nids: ' printOn:Stderr.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1566
	    "/ KnownProcessIds printOn:Stderr.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1567
	    "/ c'\nidx: ' printOn:Stderr.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1568
	    "/ index printOn:Stderr.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1569
	    "/ c'\n' printOn:Stderr.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1570
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1571
	    wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1572
	    ^ self
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1573
	].
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1574
    ].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1575
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1576
    "no empty slot available - have to grow"
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1577
    sz := sz+1.
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
    oldSize := KnownProcesses size.
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1580
    (sz > oldSize) ifTrue:[
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1581
	newShadows := KnownProcesses class new:(oldSize * 2).
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1582
	newShadows addDependent:self class.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1583
	newShadows replaceFrom:1 to:oldSize with:KnownProcesses startingAt:1.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1584
	KnownProcesses removeDependent:self class.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1585
	KnownProcesses := newShadows.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1586
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1587
	newIDs := Array new:(oldSize * 2).
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1588
	newIDs replaceFrom:1 to:oldSize with:KnownProcessIds startingAt:1.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1589
	KnownProcessIds := newIDs.
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1590
    ].
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1591
    KnownProcesses at:sz put:aProcess.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1592
    KnownProcessIds at:sz put:aProcess id.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1593
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1594
    "/ '********************* after (2): ' printOn:Stderr.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1595
    "/ c'\nprocesses: ' printOn:Stderr.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1596
    "/ KnownProcesses printOn:Stderr.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1597
    "/ c'\nids: ' printOn:Stderr.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1598
    "/ KnownProcessIds printOn:Stderr.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1599
    "/ c'\nidx: ' printOn:Stderr.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1600
    "/ sz printOn:Stderr.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1601
    "/ c'\n' printOn:Stderr.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1602
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1603
    wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
2091
c11bb3e29a1b Use dependent mechamism of WeakArray instead of #watcher.
Stefan Vogel <sv@exept.de>
parents: 1981
diff changeset
  1604
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1605
    "Modified: / 07-01-1997 / 16:48:39 / stefan"
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1606
    "Modified (format): / 05-02-2020 / 15:47:39 / Stefan Vogel"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1607
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1608
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1609
unRemember:aProcess
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1610
    "forget aProcess - dispose processing will not consider this one"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1611
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1612
    |index wasBlocked|
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1613
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1614
    wasBlocked := OperatingSystem blockInterrupts.
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1615
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1616
    "/ '---------- unremember ' printOn:Stderr. aProcess printOn:Stderr. ' ' printOn:Stderr.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1617
    "/ (ObjectMemory addressOf:aProcess) hexPrintString printOn:Stderr.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1618
    "/ c'\n' printOn:Stderr.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1619
    "/ thisContext fullPrintAllOn:Stderr.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1620
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1621
    index := KnownProcesses identityIndexOf:aProcess startingAt:1.
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1622
    index ~~ 0 ifTrue:[
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1623
	KnownProcessIds at:index put:nil.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1624
	KnownProcesses at:index put:nil.
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1625
    ].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1626
    wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1627
! !
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1628
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1629
!ProcessorScheduler methodsFor:'process creation'!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1630
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1631
newProcessFor:aProcess
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1632
    "create a physical (VM-) process for aProcess.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1633
     Return true if ok, false if something went wrong.
10747
e9ea71d01445 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10497
diff changeset
  1634
     The process is not scheduled; to start it running,
e9ea71d01445 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10497
diff changeset
  1635
     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
  1636
     get control in its #start method."
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1637
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1638
    |id|
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1639
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1640
    id := self class threadCreate:aProcess withId:nil.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1641
    aProcess setId:id state:#light.   "meaning: has no stack yet"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1642
    self remember:aProcess.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1643
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1644
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1645
newProcessFor:aProcess withId:idWant
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1646
    "private entry for Process restart - do not use in your program"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1647
1836
08a200835cc8 process restart is different if done at image restart time.
Claus Gittinger <cg@exept.de>
parents: 1793
diff changeset
  1648
    idWant isNil ifTrue:[
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1649
	self newProcessFor:aProcess.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1650
	^ true.
1836
08a200835cc8 process restart is different if done at image restart time.
Claus Gittinger <cg@exept.de>
parents: 1793
diff changeset
  1651
    ].
08a200835cc8 process restart is different if done at image restart time.
Claus Gittinger <cg@exept.de>
parents: 1793
diff changeset
  1652
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1653
    (self class threadCreate:aProcess withId:idWant) ~~ idWant ifTrue:[
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1654
	^ false
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1655
    ].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1656
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1657
    aProcess state:#light.   "meaning: has no stack yet"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1658
    self remember:aProcess.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1659
    ^ true
1836
08a200835cc8 process restart is different if done at image restart time.
Claus Gittinger <cg@exept.de>
parents: 1793
diff changeset
  1660
08a200835cc8 process restart is different if done at image restart time.
Claus Gittinger <cg@exept.de>
parents: 1793
diff changeset
  1661
    "Modified: 28.10.1996 / 19:14:28 / cg"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1662
! !
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1663
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1664
!ProcessorScheduler methodsFor:'queries'!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1665
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1666
activeProcessIsSystemProcess
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1667
    "return true if the active process is a system process,
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1668
     which should not be suspended."
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1669
2637
0d8508bedf06 Move #isSystemProcess from ProcessorScheduler to Process.
Stefan Vogel <sv@exept.de>
parents: 2626
diff changeset
  1670
    ^ activeProcess isSystemProcess
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1671
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1672
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1673
     Processor activeProcessIsSystemProcess
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1674
    "
2637
0d8508bedf06 Move #isSystemProcess from ProcessorScheduler to Process.
Stefan Vogel <sv@exept.de>
parents: 2626
diff changeset
  1675
0d8508bedf06 Move #isSystemProcess from ProcessorScheduler to Process.
Stefan Vogel <sv@exept.de>
parents: 2626
diff changeset
  1676
    "Modified: 17.4.1997 / 12:59:33 / stefan"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1677
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1678
20754
6d076c61a915 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20753
diff changeset
  1679
anyScheduledWindowGroupAtAll
6d076c61a915 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20753
diff changeset
  1680
    "return true, if there is any window group with active topviews.
6d076c61a915 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20753
diff changeset
  1681
     This is used to determine if we should stop scheduling
6d076c61a915 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20753
diff changeset
  1682
     in standAlone applications."
6d076c61a915 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20753
diff changeset
  1683
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1684
    ^ WindowGroup notNil
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1685
	and:[WindowGroup scheduledWindowGroups notEmpty].
20754
6d076c61a915 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20753
diff changeset
  1686
6d076c61a915 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20753
diff changeset
  1687
    "
6d076c61a915 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20753
diff changeset
  1688
     Processor anyScheduledWindowGroupAtAll
6d076c61a915 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20753
diff changeset
  1689
    "
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1690
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1691
    "Modified: / 05-02-2020 / 15:27:55 / Stefan Vogel"
20754
6d076c61a915 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20753
diff changeset
  1692
!
6d076c61a915 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20753
diff changeset
  1693
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
  1694
anyUserProcessAtAll
18940
dc91734b9496 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18776
diff changeset
  1695
    "return true, if there is any user process still running,
dc91734b9496 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18776
diff changeset
  1696
     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
  1697
     This is used to determine if we should stop scheduling
2193
Claus Gittinger <cg@exept.de>
parents: 2191
diff changeset
  1698
     in standAlone applications.
20736
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  1699
     A user process has a non-zero processGroup.
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  1700
     Should be called with interrupts blocked."
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  1701
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1702
    |listArray listAtPrio checkSemaBlock checkProcessBlock
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1703
     prio "{ Class: SmallInteger }" |
964
6d87e84d86ac in standAloneMode: exit dispatch if last process dies and no more sema/timer waits are pending
Claus Gittinger <cg@exept.de>
parents: 840
diff changeset
  1704
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
  1705
    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
  1706
    listArray := quiescentProcessLists.
1571
8d00e6b97ca7 changed #anyUserProcessAtAll,
Claus Gittinger <cg@exept.de>
parents: 1473
diff changeset
  1707
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1708
    prio to:1 by:-1 do:[:pri|
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1709
	listAtPrio := listArray at:pri.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1710
	listAtPrio notNil ifTrue:[
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1711
	    listAtPrio linksDo:[:aProcess |
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1712
		aProcess isUserProcess ifTrue:[
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1713
		    "/ 'anyUserProcess: found quiescent ' _errorPrint. aProcess asString _errorPrintCR.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1714
		    ^ true.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1715
		]
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1716
	    ]
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1717
	].
18940
dc91734b9496 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18776
diff changeset
  1718
    ].
dc91734b9496 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18776
diff changeset
  1719
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1720
    checkProcessBlock := [:p | p notNil and:[p isUserProcess and:[p isAlive]]].
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1721
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1722
    (scheduledProcesses notNil
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1723
     and:[scheduledProcesses contains:checkProcessBlock]) ifTrue:[
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1724
       "/ 'anyUserProcess: found scheduled ' _errorPrint.
20883
1de8290ae4d8 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20882
diff changeset
  1725
       "/ (scheduledProcesses detect:[:p | p notNil and:[p isUserProcess and:[p state ~~ #dead]] ]) asString _errorPrintCR.
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1726
	^ true.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1727
    ].
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1728
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1729
    checkSemaBlock := [:sema |
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1730
			sema notNil
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1731
			and:[sema waitingProcesses contains:checkProcessBlock]
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1732
	    ].
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1733
18940
dc91734b9496 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18776
diff changeset
  1734
    "/ any user process waiting on a sema?
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1735
    (readSemaphoreArray contains:checkSemaBlock) ifTrue:[
20883
1de8290ae4d8 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20882
diff changeset
  1736
       "/ 'anyUserProcess: found on read sema' _errorPrintCR.
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1737
	^ 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
  1738
    ].
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1739
    (writeSemaphoreArray contains:checkSemaBlock) ifTrue:[
20883
1de8290ae4d8 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20882
diff changeset
  1740
       "/ 'anyUserProcess: found on write sema' _errorPrintCR.
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1741
	^ true.
18940
dc91734b9496 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18776
diff changeset
  1742
    ].
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1743
    (timeoutSemaphoreArray contains:checkSemaBlock) ifTrue:[
20883
1de8290ae4d8 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20882
diff changeset
  1744
       "/ 'anyUserProcess: found on timeout sema' _errorPrintCR.
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1745
	^ true.
18940
dc91734b9496 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18776
diff changeset
  1746
    ].
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1747
    (exceptSemaphoreArray contains:checkSemaBlock) ifTrue:[
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1748
       "/ 'anyUserProcess: found on except sema' _errorPrintCR.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1749
	^ true.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1750
    ].
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1751
    (timeoutProcessArray contains:checkProcessBlock) ifTrue:[
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1752
	^ true.
18940
dc91734b9496 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18776
diff changeset
  1753
    ].
dc91734b9496 #BUGFIX
Claus Gittinger <cg@exept.de>
parents: 18776
diff changeset
  1754
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
  1755
    ^ false
1571
8d00e6b97ca7 changed #anyUserProcessAtAll,
Claus Gittinger <cg@exept.de>
parents: 1473
diff changeset
  1756
8d00e6b97ca7 changed #anyUserProcessAtAll,
Claus Gittinger <cg@exept.de>
parents: 1473
diff changeset
  1757
    "
10747
e9ea71d01445 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10497
diff changeset
  1758
     Processor anyUserProcessAtAll
1571
8d00e6b97ca7 changed #anyUserProcessAtAll,
Claus Gittinger <cg@exept.de>
parents: 1473
diff changeset
  1759
    "
8d00e6b97ca7 changed #anyUserProcessAtAll,
Claus Gittinger <cg@exept.de>
parents: 1473
diff changeset
  1760
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1761
    "Modified: / 29-07-1996 / 11:49:17 / cg"
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1762
    "Modified: / 01-08-2017 / 17:38:35 / stefan"
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1763
    "Modified (format): / 05-02-2020 / 15:54:10 / Stefan Vogel"
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
  1764
!
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
  1765
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1766
highestPriorityRunnableProcess
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1767
    "return the highest prio runnable process"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1768
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1769
    |wasBlocked listArray listAtPrio p
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1770
     prio "{ Class: SmallInteger }"|
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1771
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1772
    prio := HighestPriority.
3745
3fd121f2e74e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3740
diff changeset
  1773
    wasBlocked := OperatingSystem blockInterrupts.
3fd121f2e74e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3740
diff changeset
  1774
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1775
    listArray := quiescentProcessLists.
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1776
    prio to:1 by:-1 do:[:pri|
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1777
	listAtPrio := listArray at:pri.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1778
	listAtPrio notNil ifTrue:[
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1779
	    p := listAtPrio firstLinkIfEmpty:nil.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1780
	    p notNil ifTrue:[
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1781
		"
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1782
		 if it got corrupted somehow ...
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1783
		"
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1784
		p isDead ifTrue:[
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1785
		    Logger warning:'Processor: dead process removed'.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1786
		    listAtPrio removeFirst.
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1787
		    p := nil.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1788
		].
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1789
		wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1790
		^ p
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1791
	    ]
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1792
	].
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1793
    ].
3745
3fd121f2e74e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3740
diff changeset
  1794
    wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1795
    ^ nil
1086
7b0641a2e1ef nicer message
Claus Gittinger <cg@exept.de>
parents: 1061
diff changeset
  1796
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1797
    "Modified: / 12-02-1997 / 12:41:49 / cg"
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1798
    "Modified: / 01-08-2017 / 14:20:11 / stefan"
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1799
    "Modified: / 05-02-2020 / 16:00:55 / Stefan Vogel"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1800
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1801
5389
509d4228751b added query: #isDispatching
ca
parents: 5107
diff changeset
  1802
isDispatching
509d4228751b added query: #isDispatching
ca
parents: 5107
diff changeset
  1803
    ^ dispatching
509d4228751b added query: #isDispatching
ca
parents: 5107
diff changeset
  1804
!
509d4228751b added query: #isDispatching
ca
parents: 5107
diff changeset
  1805
1177
05f4917ccc4f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1166
diff changeset
  1806
isPureEventDriven
05f4917ccc4f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1166
diff changeset
  1807
    "this is temporary - (maybe not :-).
05f4917ccc4f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1166
diff changeset
  1808
     you can run ST/X either with or without processes.
05f4917ccc4f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1166
diff changeset
  1809
     Without, there is conceptionally a single process handling all
05f4917ccc4f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1166
diff changeset
  1810
     outside events and timeouts. This has some negative implications
05f4917ccc4f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1166
diff changeset
  1811
     (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
  1812
     assembler support - i.e. quick portability.
05f4917ccc4f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1166
diff changeset
  1813
     The PureEvent flag will automatically be set if the runtime system
05f4917ccc4f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1166
diff changeset
  1814
     does not support threads - otherwise, it can be set manually
05f4917ccc4f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1166
diff changeset
  1815
     (from rc-file).
05f4917ccc4f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1166
diff changeset
  1816
    "
05f4917ccc4f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1166
diff changeset
  1817
05f4917ccc4f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1166
diff changeset
  1818
    ^ PureEventDriven
05f4917ccc4f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1166
diff changeset
  1819
05f4917ccc4f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1166
diff changeset
  1820
    "Created: 13.4.1996 / 20:31:31 / cg"
05f4917ccc4f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1166
diff changeset
  1821
!
05f4917ccc4f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1166
diff changeset
  1822
2191
6c641780265d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2190
diff changeset
  1823
isTimeSlicing
6c641780265d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2190
diff changeset
  1824
    "return true, if in timeslicing mode"
6c641780265d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2190
diff changeset
  1825
6c641780265d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2190
diff changeset
  1826
    ^ timeSliceProcess notNil
6c641780265d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2190
diff changeset
  1827
6c641780265d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2190
diff changeset
  1828
    "
6c641780265d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2190
diff changeset
  1829
     Processor isTimeSlicing
6c641780265d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2190
diff changeset
  1830
    "
6c641780265d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2190
diff changeset
  1831
6c641780265d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2190
diff changeset
  1832
    "Modified: 17.1.1997 / 17:48:41 / cg"
16623
d6fb73207eca class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16538
diff changeset
  1833
!
d6fb73207eca class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16538
diff changeset
  1834
d6fb73207eca class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16538
diff changeset
  1835
processWithId:anInteger
d6fb73207eca class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16538
diff changeset
  1836
    "answer the process with id anInteger, or nil if there is none"
d6fb73207eca class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16538
diff changeset
  1837
16624
ec0aed640724 class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16623
diff changeset
  1838
    |wasBlocked slot process|
ec0aed640724 class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16623
diff changeset
  1839
ec0aed640724 class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16623
diff changeset
  1840
    wasBlocked := OperatingSystem blockInterrupts.
16623
d6fb73207eca class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16538
diff changeset
  1841
d6fb73207eca class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16538
diff changeset
  1842
    slot := KnownProcessIds indexOf:anInteger.
16624
ec0aed640724 class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16623
diff changeset
  1843
    slot ~~ 0 ifTrue:[
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1844
	process := KnownProcesses at:slot ifAbsent:[].
16624
ec0aed640724 class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16623
diff changeset
  1845
    ].
ec0aed640724 class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16623
diff changeset
  1846
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1847
    wasBlocked ifFalse:[ OperatingSystem unblockInterrupts ].
16624
ec0aed640724 class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16623
diff changeset
  1848
ec0aed640724 class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16623
diff changeset
  1849
    "Take care, the process may already have been collected"
ec0aed640724 class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16623
diff changeset
  1850
    process == 0 ifTrue:[
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1851
	^ nil.
16623
d6fb73207eca class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16538
diff changeset
  1852
    ].
16624
ec0aed640724 class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16623
diff changeset
  1853
    ^ process.
16623
d6fb73207eca class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16538
diff changeset
  1854
d6fb73207eca class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16538
diff changeset
  1855
    "
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1856
	Processor processWithId:4
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1857
	Processor processWithId:4711
16623
d6fb73207eca class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16538
diff changeset
  1858
    "
21118
9a37c4d77ea4 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21114
diff changeset
  1859
!
9a37c4d77ea4 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21114
diff changeset
  1860
9a37c4d77ea4 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21114
diff changeset
  1861
processesWithGroupId:anInteger
9a37c4d77ea4 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21114
diff changeset
  1862
    "answer a collection of processes with processGroupId, anInteger"
9a37c4d77ea4 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21114
diff changeset
  1863
9a37c4d77ea4 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21114
diff changeset
  1864
    |wasBlocked coll|
9a37c4d77ea4 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21114
diff changeset
  1865
9a37c4d77ea4 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21114
diff changeset
  1866
    coll := OrderedCollection new.
9a37c4d77ea4 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21114
diff changeset
  1867
9a37c4d77ea4 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21114
diff changeset
  1868
    wasBlocked := OperatingSystem blockInterrupts.
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1869
    KnownProcesses validElementsDo:[:eachProcess|
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1870
	eachProcess processGroupId = anInteger ifTrue:[
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1871
	    coll add:eachProcess.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1872
	].
21118
9a37c4d77ea4 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21114
diff changeset
  1873
    ].
9a37c4d77ea4 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21114
diff changeset
  1874
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1875
    wasBlocked ifFalse:[ OperatingSystem unblockInterrupts ].
21118
9a37c4d77ea4 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21114
diff changeset
  1876
9a37c4d77ea4 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21114
diff changeset
  1877
    ^ coll.
9a37c4d77ea4 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21114
diff changeset
  1878
9a37c4d77ea4 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21114
diff changeset
  1879
    "
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1880
	Processor processesWithGroupId:0
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1881
	Processor processesWithGroupId:4711
21118
9a37c4d77ea4 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21114
diff changeset
  1882
    "
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1883
! !
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1884
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1885
!ProcessorScheduler methodsFor:'scheduling'!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1886
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1887
changePriority:prio for:aProcess
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1888
    "change the priority of aProcess"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1889
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1890
    |oldList newList oldPrio newPrio wasBlocked|
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1891
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1892
    oldPrio := aProcess priority.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1893
    oldPrio == prio ifTrue:[^ self].
1042
cc49fd1e3c7e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1032
diff changeset
  1894
    aProcess == scheduler ifTrue:[^ self].
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1895
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1896
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1897
     check for valid argument
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1898
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1899
    newPrio := prio.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1900
    newPrio < 1 ifTrue:[
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1901
	newPrio := 1.
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1902
    ] ifFalse:[
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1903
	newPrio > HighestPriority ifTrue:[
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1904
	    newPrio := HighestPriority
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1905
	]
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1906
    ].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1907
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1908
    wasBlocked := OperatingSystem blockInterrupts.
1042
cc49fd1e3c7e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1032
diff changeset
  1909
    [
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1910
	aProcess setPriority:newPrio.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1911
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1912
	oldList := quiescentProcessLists at:oldPrio.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1913
	oldList notNil ifTrue:[
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1914
	    (oldList removeIdentical:aProcess ifAbsent:nil) notNil ifTrue:[
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1915
		newList := quiescentProcessLists at:newPrio.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1916
		newList isNil ifTrue:[
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1917
		    quiescentProcessLists at:newPrio put:(newList := LinkedList new).
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1918
		].
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1919
		newList addLast:aProcess.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1920
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1921
		"if it's the current process lowering its prio
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1922
		 or another one raising, we have to reschedule"
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1923
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1924
		aProcess == activeProcess ifTrue:[
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1925
		    currentPriority := newPrio.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1926
		    newPrio < oldPrio ifTrue:[
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1927
			self threadSwitch:scheduler.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1928
		    ]
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1929
		] ifFalse:[
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1930
		    newPrio > currentPriority ifTrue:[
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1931
			self threadSwitch:aProcess.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1932
		    ]
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1933
		].
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1934
		timeSliceNeededSemaphore notNil ifTrue:[
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1935
		    "/ tell timeslicer, that some work might be needed...
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1936
		    timeSliceNeededSemaphore signalIf.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1937
		]
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1938
	    ]
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1939
	]
6421
58dca33cf0fc #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 6376
diff changeset
  1940
    ] ensure:[
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1941
	wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
1042
cc49fd1e3c7e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1032
diff changeset
  1942
    ]
1032
924c177085f8 care to reenable interrupts
Claus Gittinger <cg@exept.de>
parents: 1001
diff changeset
  1943
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1944
    "Modified: / 04-08-1998 / 00:08:54 / cg"
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1945
    "Modified (comment): / 13-02-2017 / 20:29:13 / cg"
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1946
    "Modified: / 05-02-2020 / 15:17:08 / Stefan Vogel"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1947
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1948
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1949
interruptActive
10747
e9ea71d01445 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10497
diff changeset
  1950
    "interrupt the current process
1783
be7402f74d94 hide timerInterrupt & ioInterrupt contexts when switching
Claus Gittinger <cg@exept.de>
parents: 1780
diff changeset
  1951
     - 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
  1952
     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
  1953
     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
  1954
9991
a03847e11498 make #interruptActive returnable for better debugging
Stefan Vogel <sv@exept.de>
parents: 9452
diff changeset
  1955
    <context: #return>
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1956
    <resource: #skipInDebuggersWalkBack>
9991
a03847e11498 make #interruptActive returnable for better debugging
Stefan Vogel <sv@exept.de>
parents: 9452
diff changeset
  1957
1791
9278f0b8a7e1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1787
diff changeset
  1958
    |s|
9278f0b8a7e1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1787
diff changeset
  1959
9278f0b8a7e1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1787
diff changeset
  1960
    "/ hide those intermediate scheduler contexts;
10747
e9ea71d01445 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10497
diff changeset
  1961
    "/ the interrupt block should think it was called right
1791
9278f0b8a7e1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1787
diff changeset
  1962
    "/ from the originally interrupted context
9278f0b8a7e1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1787
diff changeset
  1963
9278f0b8a7e1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1787
diff changeset
  1964
    s := thisContext sender.
9991
a03847e11498 make #interruptActive returnable for better debugging
Stefan Vogel <sv@exept.de>
parents: 9452
diff changeset
  1965
    s selector == #threadSwitchFrom:to:id:singleStep: ifTrue:[
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1966
        s := s sender.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1967
        s selector == #threadSwitch: ifTrue:[
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1968
            s := s sender.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1969
            s selector == #timerInterrupt ifTrue:[
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1970
                s := s sender
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1971
            ]
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1972
        ]
1791
9278f0b8a7e1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1787
diff changeset
  1973
    ].
9278f0b8a7e1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1787
diff changeset
  1974
2727
853b7910cff2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2724
diff changeset
  1975
    "/ the returned value here has a subtle effect:
853b7910cff2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2724
diff changeset
  1976
    "/ if false, the interrupt is assumed to be not taken,
853b7910cff2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2724
diff changeset
  1977
    "/ and will be redelivered.
2724
9fb9ea4bf858 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2637
diff changeset
  1978
    ^ activeProcess interruptedIn:s
1783
be7402f74d94 hide timerInterrupt & ioInterrupt contexts when switching
Claus Gittinger <cg@exept.de>
parents: 1780
diff changeset
  1979
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1980
    "Modified: / 20-10-1996 / 17:06:48 / cg"
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1981
    "Modified: / 30-05-2018 / 13:56:47 / Claus Gittinger"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1982
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1983
3273
343ecdba9817 added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents: 3271
diff changeset
  1984
makeRunnable:aProcess
14771
c85f3f394aae class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 14442
diff changeset
  1985
    "set aProcess runnable - but do not reschedule.
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1986
     Answer:
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1987
	the process, that has a higher priority than the current running process
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1988
	nil if the current process should keep running.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1989
     NOTE: must not perform an operation inside that causes a reschedule."
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1990
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1991
    |listForPrio state pri wasBlocked|
3273
343ecdba9817 added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents: 3271
diff changeset
  1992
343ecdba9817 added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents: 3271
diff changeset
  1993
    "ignore, if process is already dead"
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1994
    (aProcess isNil or:[aProcess isDead]) ifTrue:[^ nil].
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1995
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1996
    state := aProcess state.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1997
    state == #osWait ifTrue:[
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  1998
	Logger warning:'Processor: bad resume: #osWait'.
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  1999
	"/ MiniDebugger enterWithMessage:'bad resume: state osWait'.
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2000
	^ nil.
14771
c85f3f394aae class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 14442
diff changeset
  2001
    ].
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2002
    state == #stopped ifTrue:[
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2003
	"by definition, stopped processes cannot be resumed"
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2004
	^ nil.
14771
c85f3f394aae class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 14442
diff changeset
  2005
    ].
3273
343ecdba9817 added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents: 3271
diff changeset
  2006
343ecdba9817 added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents: 3271
diff changeset
  2007
    aProcess == activeProcess ifTrue:[
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2008
	"special handling for waiting schedulers"
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2009
	aProcess == scheduler ifTrue:[
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2010
	    suspendScheduler := false.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2011
	].
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2012
	^ nil
3273
343ecdba9817 added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents: 3271
diff changeset
  2013
    ].
343ecdba9817 added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents: 3271
diff changeset
  2014
343ecdba9817 added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents: 3271
diff changeset
  2015
    wasBlocked := OperatingSystem blockInterrupts.
343ecdba9817 added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents: 3271
diff changeset
  2016
    pri := aProcess priority.
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2017
    listForPrio := quiescentProcessLists at:pri.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2018
    listForPrio notNil ifTrue:[
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2019
	(listForPrio identityIndexOf:aProcess startingAt:1) ~~ 0 ifTrue:[
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2020
	    "if already running, ignore"
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2021
	    wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2022
	    ^ nil
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2023
	]
3273
343ecdba9817 added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents: 3271
diff changeset
  2024
    ] ifFalse:[
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2025
	listForPrio := LinkedList new.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2026
	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
  2027
    ].
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2028
    listForPrio addLast:aProcess.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2029
    aProcess setStateRun.
3273
343ecdba9817 added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents: 3271
diff changeset
  2030
    wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
343ecdba9817 added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents: 3271
diff changeset
  2031
14771
c85f3f394aae class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 14442
diff changeset
  2032
    pri > currentPriority ifTrue:[
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2033
	"priority of aProcess is higher, must reschedule"
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2034
	^ aProcess.
14771
c85f3f394aae class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 14442
diff changeset
  2035
    ].
11590
f98b955212c2 timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents: 11585
diff changeset
  2036
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2037
    "/ tell timeslicer (if present), that some work might be needed...
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2038
    "/ answer true, if a reschedule is needed for the timeslicer
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2039
    (timeSliceNeededSemaphore notNil and:[timeSliceNeededSemaphore signalIfWithReturn]) ifTrue:[
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2040
	"cause a reschedule"
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2041
	^ scheduler.
14771
c85f3f394aae class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 14442
diff changeset
  2042
    ].
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2043
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2044
    ^ nil.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2045
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2046
    "Modified: / 29-07-1996 / 12:07:37 / cg"
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2047
    "Created: / 04-02-1998 / 20:58:28 / cg"
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2048
    "Modified: / 20-02-2017 / 11:34:03 / stefan"
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2049
    "Modified: / 29-05-2019 / 01:04:42 / Claus Gittinger"
3273
343ecdba9817 added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents: 3271
diff changeset
  2050
!
343ecdba9817 added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents: 3271
diff changeset
  2051
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2052
processTermination
10747
e9ea71d01445 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10497
diff changeset
  2053
    "sent by VM if the current process finished its startup block
e9ea71d01445 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10497
diff changeset
  2054
     without proper process termination. Lay him to rest now.
e9ea71d01445 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10497
diff changeset
  2055
     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
  2056
     since the block defined there always terminates itself."
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2057
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2058
    self terminateNoSignal:activeProcess.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2059
    self threadSwitch:scheduler
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2060
!
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
reschedule
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2063
    "switch to the highest prio runnable process.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2064
     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
  2065
     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
  2066
     to allow giving up the CPU."
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2067
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2068
    ^ self threadSwitch:scheduler
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2069
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2070
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2071
resume:aProcess
10747
e9ea71d01445 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10497
diff changeset
  2072
    "set aProcess runnable -
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2073
     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
  2074
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2075
    |someOtherProcessToSchedule|
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2076
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2077
    someOtherProcessToSchedule := self makeRunnable:aProcess.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2078
    someOtherProcessToSchedule notNil ifTrue:[
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2079
	"another process priority is higher, reschedule"
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2080
	self threadSwitch:someOtherProcessToSchedule.
1679
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  2081
    ].
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2082
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2083
    "Modified: / 20-02-2017 / 11:35:23 / stefan"
699
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
resumeForSingleSend:aProcess
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2087
    "like resume, but let the process execute a single send only.
3271
f9b081667d3e Fix comment.
Stefan Vogel <sv@exept.de>
parents: 3270
diff changeset
  2088
     This will be used by the debugger for single stepping."
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2089
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2090
    (aProcess isNil or:[aProcess == activeProcess]) ifTrue:[^ self].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2091
    aProcess singleStep:true.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2092
    self resume:aProcess
3271
f9b081667d3e Fix comment.
Stefan Vogel <sv@exept.de>
parents: 3270
diff changeset
  2093
f9b081667d3e Fix comment.
Stefan Vogel <sv@exept.de>
parents: 3270
diff changeset
  2094
    "Modified: / 3.2.1998 / 01:08:08 / stefan"
699
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
suspend:aProcess
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2098
    "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
  2099
     If the process is the current one, reschedule.
2155
0cf80e958130 comment
Claus Gittinger <cg@exept.de>
parents: 2149
diff changeset
  2100
0cf80e958130 comment
Claus Gittinger <cg@exept.de>
parents: 2149
diff changeset
  2101
     Notice:
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2102
	 This method should only be called by Process>>suspend or
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2103
	 Process>>suspendWithState:"
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2104
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2105
    <resource: #skipInDebuggersWalkBack>
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2106
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2107
    |pri listAtPrio processToRun wasBlocked|
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2108
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2109
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2110
     some debugging stuff
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2111
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2112
    aProcess isNil ifTrue:[
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2113
	InvalidProcessSignal raiseRequestWith:aProcess errorString:'nil suspend'.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2114
	^ self
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2115
    ].
15658
f886d275e0fc class: ProcessorScheduler
Claus Gittinger <cg@exept.de>
parents: 15657
diff changeset
  2116
    aProcess isDead ifTrue:[
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2117
	InvalidProcessSignal raiseRequestWith:aProcess errorString:'bad suspend: already dead'.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2118
	self threadSwitch:scheduler.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2119
	^ self
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2120
    ].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2121
    aProcess == scheduler ifTrue:[
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2122
	"only the scheduler may suspend itself"
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2123
	activeProcess == scheduler ifTrue:[
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2124
	    suspendScheduler := true.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2125
	    [suspendScheduler] whileTrue:[
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2126
		self dispatch.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2127
	    ].
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2128
	    ^ self
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2129
	].
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2130
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2131
	InvalidProcessSignal raiseRequestWith:aProcess errorString:'attempt to suspend scheduler'.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2132
	^ self
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2133
    ].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2134
21009
d4035978c3c7 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20964
diff changeset
  2135
    (aProcess == activeProcess) ifTrue:[
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2136
	"this is a no-op if the process has no interrupt actions"
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2137
	aProcess interrupt.
7863
516fa101129e care for interrupt action before suspending a process
ca
parents: 7848
diff changeset
  2138
    ].
516fa101129e care for interrupt action before suspending a process
ca
parents: 7848
diff changeset
  2139
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2140
    wasBlocked := OperatingSystem blockInterrupts.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2141
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2142
    pri := aProcess priority.
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2143
    listAtPrio := quiescentProcessLists at:pri.
699
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
    "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
  2146
     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
  2147
    "
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2148
    (listAtPrio isNil or:[(listAtPrio removeIdentical:aProcess ifAbsent:nil) isNil]) ifTrue:[
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2149
	"/ 'Processor [warning]: bad suspend: process is not running' errorPrintCR.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2150
	"/ MiniDebugger enterWithMessage:'bad suspend: process is not running'.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2151
	aProcess == activeProcess ifTrue:[
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2152
	    self threadSwitch:scheduler.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2153
	].
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2154
	wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2155
	^ self
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2156
    ].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2157
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2158
    (aProcess == activeProcess) ifTrue:[
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2159
	"we can immediately switch sometimes"
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2160
	processToRun := listAtPrio firstLinkIfEmpty:scheduler.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2161
	self threadSwitch:processToRun
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2162
    ].
752
0259dd855289 new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents: 750
diff changeset
  2163
3745
3fd121f2e74e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3740
diff changeset
  2164
    wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
3fd121f2e74e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3740
diff changeset
  2165
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2166
    "Modified: / 23-09-1996 / 13:49:24 / stefan"
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2167
    "Modified: / 27-07-1998 / 23:34:59 / cg"
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2168
    "Modified: / 30-05-2018 / 13:56:55 / Claus Gittinger"
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2169
    "Modified: / 05-02-2020 / 16:10:58 / Stefan Vogel"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2170
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2171
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2172
terminate:aProcess
20055
04ca6d9e3268 #DOCUMENTATION by mawalch
mawalch
parents: 20054
diff changeset
  2173
    "terminate aProcess. This is done by sending aProcess the terminateSignal,
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2174
     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
  2175
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2176
    aProcess terminate
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2177
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2178
    "Modified: / 05-02-2020 / 16:25:41 / Stefan Vogel"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2179
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2180
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2181
terminateActive
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2182
    "terminate the current process (i.e. the running process kills itself).
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2183
     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
  2184
     unwind blocks and finally do a hard terminate.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2185
     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
  2186
     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
  2187
     continued to grow its stack)"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2188
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2189
    activeProcess terminate
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2190
!
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
terminateActiveNoSignal
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2193
    "hard terminate the active process, without sending any
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2194
     terminate signal thus no unwind blocks are evaluated."
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2195
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2196
    self terminateNoSignal:activeProcess
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
terminateNoSignal:aProcess
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2200
    "hard terminate aProcess without sending the terminate signal, thus
10747
e9ea71d01445 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10497
diff changeset
  2201
     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
  2202
     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
  2203
     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
  2204
     we are sitting on), a switch is forced and the process
e9ea71d01445 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10497
diff changeset
  2205
     will be physically destroyed by the next running process.
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2206
     (see zombie handling)"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2207
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2208
    |pri id listAtPrio wasBlocked|
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
    aProcess isNil ifTrue:[^ self].
20723
510279fb2401 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20722
diff changeset
  2211
807
e51ce11ca948 and dont allow quickTerminate as well.
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
  2212
    aProcess == scheduler ifTrue:[
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2213
	InvalidProcessSignal raiseWith:aProcess errorString:'attempt to terminate scheduler'.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2214
	^ self
807
e51ce11ca948 and dont allow quickTerminate as well.
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
  2215
    ].
e51ce11ca948 and dont allow quickTerminate as well.
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
  2216
6990
a6bda971619f race with threadDestroy (leftOver process-structures in VM);
ca
parents: 6940
diff changeset
  2217
    wasBlocked := OperatingSystem blockInterrupts.
a6bda971619f race with threadDestroy (leftOver process-structures in VM);
ca
parents: 6940
diff changeset
  2218
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2219
    id := aProcess id.
6990
a6bda971619f race with threadDestroy (leftOver process-structures in VM);
ca
parents: 6940
diff changeset
  2220
    id isNil ifTrue:[   "already dead"
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2221
	self checkForEndOfDispatch.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2222
	wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2223
	^ self
10747
e9ea71d01445 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10497
diff changeset
  2224
    ].
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
    aProcess setId:nil state:#dead.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2227
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2228
    "remove the process from the runnable list"
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
    pri := aProcess priority.
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2231
    listAtPrio := quiescentProcessLists at:pri.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2232
    listAtPrio notNil ifTrue:[
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2233
	(listAtPrio removeIdentical:aProcess ifAbsent:nil) "notNil ifTrue:[
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2234
	    listAtPrio isEmpty ifTrue:[
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2235
		quiescentProcessLists at:pri put:nil
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2236
	    ]
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2237
	]."
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2238
    ].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2239
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2240
    aProcess == activeProcess ifTrue:[
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2241
	"
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2242
	 hard case - it's the currently running process
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2243
	 we must have the next active process destroy this one
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2244
	 (we cannot destroy the chair we are sitting on ... :-)
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2245
	"
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2246
	zombie notNil ifTrue:[
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2247
	    self proceedableError:'active process is zombie'.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2248
	    self class threadDestroy:zombie.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2249
	].
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2250
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2251
	self unRemember:aProcess.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2252
	zombie := id.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2253
	self checkForEndOfDispatch.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2254
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2255
	wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2256
	self threadSwitch:scheduler.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2257
	"not reached"
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2258
	^ self
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2259
    ].
6990
a6bda971619f race with threadDestroy (leftOver process-structures in VM);
ca
parents: 6940
diff changeset
  2260
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2261
    self unRemember:aProcess.
6990
a6bda971619f race with threadDestroy (leftOver process-structures in VM);
ca
parents: 6940
diff changeset
  2262
    self class threadDestroy:id.
a6bda971619f race with threadDestroy (leftOver process-structures in VM);
ca
parents: 6940
diff changeset
  2263
20736
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  2264
    self checkForEndOfDispatch.
6990
a6bda971619f race with threadDestroy (leftOver process-structures in VM);
ca
parents: 6940
diff changeset
  2265
    wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
1618
9fb4ee952e89 use nil for empty lists
Claus Gittinger <cg@exept.de>
parents: 1606
diff changeset
  2266
13577
5caa91ac2963 comment/format in: #terminateNoSignal:
Claus Gittinger <cg@exept.de>
parents: 13556
diff changeset
  2267
    "Modified: / 20-03-1997 / 16:03:39 / cg"
5caa91ac2963 comment/format in: #terminateNoSignal:
Claus Gittinger <cg@exept.de>
parents: 13556
diff changeset
  2268
    "Modified (comment): / 10-08-2011 / 19:57:08 / cg"
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2269
    "Modified: / 01-08-2017 / 17:29:00 / stefan"
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2270
    "Modified: / 24-05-2018 / 21:04:28 / Claus Gittinger"
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2271
    "Modified (comment): / 05-02-2020 / 16:13:06 / Stefan Vogel"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2272
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2273
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2274
yield
17271
47341245c458 class: ProcessorScheduler
Claus Gittinger <cg@exept.de>
parents: 16858
diff changeset
  2275
    "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
  2276
     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
  2277
     next same-prio-process."
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2278
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2279
    |currentPriorityProcessList sz wasBlocked|
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2280
12981
454712945c0b changed: #yield
Claus Gittinger <cg@exept.de>
parents: 12958
diff changeset
  2281
    activeProcess == scheduler ifTrue:[
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2282
	Logger warning:'Processor: scheduler tries to yield'.
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2283
	^ self
12981
454712945c0b changed: #yield
Claus Gittinger <cg@exept.de>
parents: 12958
diff changeset
  2284
    ].
454712945c0b changed: #yield
Claus Gittinger <cg@exept.de>
parents: 12958
diff changeset
  2285
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2286
    wasBlocked := OperatingSystem blockInterrupts.
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2287
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2288
     debugging consistency check - will be removed later
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2289
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2290
    activeProcess priority ~~ currentPriority ifTrue:[
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2291
	Logger warning:'Processor: process changed its priority'.
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2292
	currentPriority := activeProcess priority.
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2293
    ].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2294
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2295
    currentPriorityProcessList := quiescentProcessLists at:currentPriority.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2296
    sz := currentPriorityProcessList size.
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2297
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2298
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2299
     debugging consistency checks - will be removed later
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2300
    "
1618
9fb4ee952e89 use nil for empty lists
Claus Gittinger <cg@exept.de>
parents: 1606
diff changeset
  2301
    sz == 0 ifTrue:[
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2302
	wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2303
	Logger warning:'Processor : empty runnable list'.
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2304
	^ self
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2305
    ].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2306
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2307
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2308
     check if the running process is not the only one
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2309
    "
1618
9fb4ee952e89 use nil for empty lists
Claus Gittinger <cg@exept.de>
parents: 1606
diff changeset
  2310
    sz ~~ 1 ifTrue:[
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2311
	"
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2312
	 bring running process to the end
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2313
	"
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2314
	currentPriorityProcessList
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2315
	    removeFirst; addLast:activeProcess.
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2316
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2317
	"
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2318
	 and switch to first in the list
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2319
	"
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2320
	self threadSwitch:(currentPriorityProcessList firstLink).
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2321
    ].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2322
    wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
1086
7b0641a2e1ef nicer message
Claus Gittinger <cg@exept.de>
parents: 1061
diff changeset
  2323
12981
454712945c0b changed: #yield
Claus Gittinger <cg@exept.de>
parents: 12958
diff changeset
  2324
    "Modified: / 02-08-2010 / 13:36:25 / cg"
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2325
    "Modified: / 05-02-2020 / 15:14:20 / Stefan Vogel"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2326
! !
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2327
7264
cf619b9f31b6 method category rename
Claus Gittinger <cg@exept.de>
parents: 7097
diff changeset
  2328
!ProcessorScheduler methodsFor:'scheduling-preemptive'!
2188
3814c1d74d2b integrated the timeSlicer
Claus Gittinger <cg@exept.de>
parents: 2155
diff changeset
  2329
3722
1114c2014bea added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents: 3718
diff changeset
  2330
recomputeDynamicPriorities
1114c2014bea added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents: 3718
diff changeset
  2331
    "recompute dynamic priorities."
1114c2014bea added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents: 3718
diff changeset
  2332
15402
a40ba0a33cab class: ProcessorScheduler
Claus Gittinger <cg@exept.de>
parents: 15118
diff changeset
  2333
    |processesToDecrease processesToIncrease|
3728
970b2b4c9118 try to avoid object allocations in timeSlicers #recomputeDynamicPriorities.
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
  2334
970b2b4c9118 try to avoid object allocations in timeSlicers #recomputeDynamicPriorities.
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
  2335
    scheduledProcesses notNil ifTrue:[
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2336
	"/ this is written a bit cryptic - to avoid creation
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2337
	"/ of garbage objects (Id'sets) if possible.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2338
	"/ since this runs 50 times a second and most of the
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2339
	"/ time, no rescheduling is req'd
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2340
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2341
	scheduledProcesses do:[:aProcess |
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2342
	    |range|
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2343
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2344
	    "/ decrease priority of processes that did run
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2345
	    (range := aProcess priorityRange) notNil ifTrue:[
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2346
		aProcess priority > range start ifTrue:[
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2347
		    processesToDecrease isNil ifTrue:[
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2348
			processesToDecrease := IdentitySet new.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2349
		    ].
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2350
		    processesToDecrease add:aProcess.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2351
		]
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2352
	    ]
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2353
	].
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2354
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2355
	processesToDecrease notNil ifTrue:[
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2356
	    processesToDecrease do:[:aProcess |
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2357
		|newPri|
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2358
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2359
		"/ newPri := aProcess priority - 1.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2360
		newPri := aProcess priorityRange start.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2361
		self changePriority:newPri for:aProcess.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2362
	    ].
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2363
	].
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2364
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2365
	"/ and increase all prios of those that did not run, but are runnable
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2366
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2367
	TimeSlicingPriorityLimit to:1 by:-1 do:[:i |
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2368
	    |list|
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2369
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2370
	    (list := quiescentProcessLists at:i) size ~~ 0 ifTrue:[
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2371
		list linksDo:[:aProcess |
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2372
		    |range|
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2373
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2374
		    (range := aProcess priorityRange) notNil ifTrue:[
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2375
			(processesToDecrease isNil
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2376
			or:[(processesToDecrease includes:aProcess) not]) ifTrue:[
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2377
			    aProcess priority < range stop ifTrue:[
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2378
				processesToIncrease isNil ifTrue:[
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2379
				    processesToIncrease := OrderedCollection new.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2380
				].
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2381
				processesToIncrease add:aProcess
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2382
			    ]
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2383
			]
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2384
		    ]
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2385
		]
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2386
	    ]
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2387
	].
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2388
	processesToIncrease notNil ifTrue:[
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2389
	    processesToIncrease do:[:aProcess |
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2390
		self changePriority:(aProcess priority + 1) for:aProcess.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2391
	    ].
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2392
	].
3722
1114c2014bea added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents: 3718
diff changeset
  2393
    ].
1114c2014bea added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents: 3718
diff changeset
  2394
15581
6332a960dbcd class: ProcessorScheduler
Claus Gittinger <cg@exept.de>
parents: 15510
diff changeset
  2395
    "Modified: / 30-07-2013 / 19:33:14 / cg"
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2396
    "Modified: / 01-03-2019 / 16:07:50 / Claus Gittinger"
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2397
    "Modified (format): / 05-02-2020 / 16:20:48 / Stefan Vogel"
3790
629791828694 also keep track of scheduler processes, if
Claus Gittinger <cg@exept.de>
parents: 3787
diff changeset
  2398
!
629791828694 also keep track of scheduler processes, if
Claus Gittinger <cg@exept.de>
parents: 3787
diff changeset
  2399
629791828694 also keep track of scheduler processes, if
Claus Gittinger <cg@exept.de>
parents: 3787
diff changeset
  2400
scheduledProcesses
629791828694 also keep track of scheduler processes, if
Claus Gittinger <cg@exept.de>
parents: 3787
diff changeset
  2401
    "return a collection of recently scheduled processes.
629791828694 also keep track of scheduler processes, if
Claus Gittinger <cg@exept.de>
parents: 3787
diff changeset
  2402
     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
  2403
     scheduler is running"
629791828694 also keep track of scheduler processes, if
Claus Gittinger <cg@exept.de>
parents: 3787
diff changeset
  2404
629791828694 also keep track of scheduler processes, if
Claus Gittinger <cg@exept.de>
parents: 3787
diff changeset
  2405
    ^ scheduledProcesses ? #()
629791828694 also keep track of scheduler processes, if
Claus Gittinger <cg@exept.de>
parents: 3787
diff changeset
  2406
629791828694 also keep track of scheduler processes, if
Claus Gittinger <cg@exept.de>
parents: 3787
diff changeset
  2407
    "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
  2408
    "Modified: / 27.8.1998 / 12:56:35 / cg"
3722
1114c2014bea added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents: 3718
diff changeset
  2409
!
1114c2014bea added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents: 3718
diff changeset
  2410
2188
3814c1d74d2b integrated the timeSlicer
Claus Gittinger <cg@exept.de>
parents: 2155
diff changeset
  2411
slice
3814c1d74d2b integrated the timeSlicer
Claus Gittinger <cg@exept.de>
parents: 2155
diff changeset
  2412
    "Give other Processes at the current priority a chance to run."
3814c1d74d2b integrated the timeSlicer
Claus Gittinger <cg@exept.de>
parents: 2155
diff changeset
  2413
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2414
    |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
  2415
     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
  2416
f98b955212c2 timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents: 11585
diff changeset
  2417
    anyShuffle := false.
3745
3fd121f2e74e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3740
diff changeset
  2418
    wasBlocked := OperatingSystem blockInterrupts.
2188
3814c1d74d2b integrated the timeSlicer
Claus Gittinger <cg@exept.de>
parents: 2155
diff changeset
  2419
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2420
    prio := TimeSlicingPriorityLimit.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2421
    [(prio > 0) and:[(list := quiescentProcessLists at:prio) size <= 1]] whileTrue: [prio := prio - 1].
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2422
    prio ~~ 0 ifTrue: [
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2423
	"/ shuffle that list
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2424
	list addLast:(list removeFirst).
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2425
	anyShuffle := true.
3745
3fd121f2e74e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3740
diff changeset
  2426
    ].
3fd121f2e74e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3740
diff changeset
  2427
    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
  2428
    anyShuffle ifFalse:[
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2429
	"/ wait for the scheduler to make some process runnable...
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2430
	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
  2431
    ].
2188
3814c1d74d2b integrated the timeSlicer
Claus Gittinger <cg@exept.de>
parents: 2155
diff changeset
  2432
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2433
    "Modified: / 04-08-1998 / 00:13:32 / cg"
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2434
    "Modified (format): / 20-02-2017 / 10:09:26 / stefan"
2188
3814c1d74d2b integrated the timeSlicer
Claus Gittinger <cg@exept.de>
parents: 2155
diff changeset
  2435
!
3814c1d74d2b integrated the timeSlicer
Claus Gittinger <cg@exept.de>
parents: 2155
diff changeset
  2436
3814c1d74d2b integrated the timeSlicer
Claus Gittinger <cg@exept.de>
parents: 2155
diff changeset
  2437
startTimeSlicing
2190
8afa4709d8a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2188
diff changeset
  2438
    "start preemptive scheduling (timeSlicing)"
8afa4709d8a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2188
diff changeset
  2439
8afa4709d8a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2188
diff changeset
  2440
    timeSliceProcess notNil ifTrue: [^ self].
8afa4709d8a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2188
diff changeset
  2441
14775
fa2e7d4afdef class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 14771
diff changeset
  2442
    timeSliceNeededSemaphore := Semaphore new name:'timeSlice needed'.
11590
f98b955212c2 timeSlicer cpu-load reduced; timeSlicer waits on a semaphore for something to slice.
Michael Beyl <mb@exept.de>
parents: 11585
diff changeset
  2443
2188
3814c1d74d2b integrated the timeSlicer
Claus Gittinger <cg@exept.de>
parents: 2155
diff changeset
  2444
    timeSliceProcess := [
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2445
	[
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2446
	    self timeSlicingLoop.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2447
	] ifCurtailed:[
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2448
	    timeSliceProcess := nil.
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2449
	    Logger info:'Processor: timeslicer finished'.
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2450
	]
2188
3814c1d74d2b integrated the timeSlicer
Claus Gittinger <cg@exept.de>
parents: 2155
diff changeset
  2451
    ] newProcess.
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2452
    timeSliceProcess
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2453
	priority:HighestPriority;
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2454
	name:'System: time slicer';
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2455
	restartable:true;
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2456
	beSystemProcess;
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2457
	resume.
2188
3814c1d74d2b integrated the timeSlicer
Claus Gittinger <cg@exept.de>
parents: 2155
diff changeset
  2458
3814c1d74d2b integrated the timeSlicer
Claus Gittinger <cg@exept.de>
parents: 2155
diff changeset
  2459
    "
2258
8894d33af5f6 reuse delays
Claus Gittinger <cg@exept.de>
parents: 2198
diff changeset
  2460
     Processor stopTimeSlicing.
8894d33af5f6 reuse delays
Claus Gittinger <cg@exept.de>
parents: 2198
diff changeset
  2461
     Processor startTimeSlicing.
2188
3814c1d74d2b integrated the timeSlicer
Claus Gittinger <cg@exept.de>
parents: 2155
diff changeset
  2462
    "
3814c1d74d2b integrated the timeSlicer
Claus Gittinger <cg@exept.de>
parents: 2155
diff changeset
  2463
13813
1194409a73dd changed: #startTimeSlicing
Claus Gittinger <cg@exept.de>
parents: 13577
diff changeset
  2464
    "Created: / 17-01-1997 / 16:42:02 / cg"
1194409a73dd changed: #startTimeSlicing
Claus Gittinger <cg@exept.de>
parents: 13577
diff changeset
  2465
    "Modified: / 03-11-2011 / 21:21:10 / cg"
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2466
    "Modified: / 15-08-2018 / 15:03:45 / Claus Gittinger"
2188
3814c1d74d2b integrated the timeSlicer
Claus Gittinger <cg@exept.de>
parents: 2155
diff changeset
  2467
!
3814c1d74d2b integrated the timeSlicer
Claus Gittinger <cg@exept.de>
parents: 2155
diff changeset
  2468
3814c1d74d2b integrated the timeSlicer
Claus Gittinger <cg@exept.de>
parents: 2155
diff changeset
  2469
stopTimeSlicing
2190
8afa4709d8a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2188
diff changeset
  2470
    "stop preemptive scheduling (timeSlicing)"
2188
3814c1d74d2b integrated the timeSlicer
Claus Gittinger <cg@exept.de>
parents: 2155
diff changeset
  2471
3814c1d74d2b integrated the timeSlicer
Claus Gittinger <cg@exept.de>
parents: 2155
diff changeset
  2472
    timeSliceProcess notNil ifTrue: [
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2473
	timeSliceProcess terminate.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2474
	timeSliceProcess := nil.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2475
	scheduledProcesses := nil.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2476
	timeSliceNeededSemaphore := nil.
2188
3814c1d74d2b integrated the timeSlicer
Claus Gittinger <cg@exept.de>
parents: 2155
diff changeset
  2477
    ]
3814c1d74d2b integrated the timeSlicer
Claus Gittinger <cg@exept.de>
parents: 2155
diff changeset
  2478
3814c1d74d2b integrated the timeSlicer
Claus Gittinger <cg@exept.de>
parents: 2155
diff changeset
  2479
    "
3814c1d74d2b integrated the timeSlicer
Claus Gittinger <cg@exept.de>
parents: 2155
diff changeset
  2480
     Processor stopTimeSlicing
3814c1d74d2b integrated the timeSlicer
Claus Gittinger <cg@exept.de>
parents: 2155
diff changeset
  2481
    "
3814c1d74d2b integrated the timeSlicer
Claus Gittinger <cg@exept.de>
parents: 2155
diff changeset
  2482
3790
629791828694 also keep track of scheduler processes, if
Claus Gittinger <cg@exept.de>
parents: 3787
diff changeset
  2483
    "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
  2484
    "Modified: / 27.8.1998 / 13:00:37 / cg"
3722
1114c2014bea added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents: 3718
diff changeset
  2485
!
1114c2014bea added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents: 3718
diff changeset
  2486
1114c2014bea added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents: 3718
diff changeset
  2487
supportDynamicPriorities
1114c2014bea added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents: 3718
diff changeset
  2488
    "return true, if dynamic priorities are enabled"
1114c2014bea added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents: 3718
diff changeset
  2489
1114c2014bea added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents: 3718
diff changeset
  2490
    ^ supportDynamicPriorities
1114c2014bea added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents: 3718
diff changeset
  2491
1114c2014bea added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents: 3718
diff changeset
  2492
    "Created: / 3.8.1998 / 22:05:15 / cg"
1114c2014bea added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents: 3718
diff changeset
  2493
    "Modified: / 3.8.1998 / 22:55:08 / cg"
1114c2014bea added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents: 3718
diff changeset
  2494
!
1114c2014bea added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents: 3718
diff changeset
  2495
1114c2014bea added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents: 3718
diff changeset
  2496
supportDynamicPriorities:aBoolean
1114c2014bea added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents: 3718
diff changeset
  2497
    "enable/disable dynamic priorities"
1114c2014bea added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents: 3718
diff changeset
  2498
1114c2014bea added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents: 3718
diff changeset
  2499
    supportDynamicPriorities := aBoolean.
1114c2014bea added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents: 3718
diff changeset
  2500
1114c2014bea added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents: 3718
diff changeset
  2501
    "
1114c2014bea added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents: 3718
diff changeset
  2502
     Processor supportDynamicPriorities:true
1114c2014bea added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents: 3718
diff changeset
  2503
     Processor supportDynamicPriorities:false
1114c2014bea added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents: 3718
diff changeset
  2504
    "
1114c2014bea added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents: 3718
diff changeset
  2505
1114c2014bea added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents: 3718
diff changeset
  2506
    "Modified: / 3.8.1998 / 22:54:52 / cg"
15687
7679c998f5ac class: ProcessorScheduler
Claus Gittinger <cg@exept.de>
parents: 15658
diff changeset
  2507
!
7679c998f5ac class: ProcessorScheduler
Claus Gittinger <cg@exept.de>
parents: 15658
diff changeset
  2508
7679c998f5ac class: ProcessorScheduler
Claus Gittinger <cg@exept.de>
parents: 15658
diff changeset
  2509
timeSlicingLoop
7679c998f5ac class: ProcessorScheduler
Claus Gittinger <cg@exept.de>
parents: 15658
diff changeset
  2510
    |myDelay t flipFlop|
7679c998f5ac class: ProcessorScheduler
Claus Gittinger <cg@exept.de>
parents: 15658
diff changeset
  2511
7679c998f5ac class: ProcessorScheduler
Claus Gittinger <cg@exept.de>
parents: 15658
diff changeset
  2512
    myDelay := Delay forMilliseconds:(t := TimeSliceInterval).
7679c998f5ac class: ProcessorScheduler
Claus Gittinger <cg@exept.de>
parents: 15658
diff changeset
  2513
    flipFlop := true.
7679c998f5ac class: ProcessorScheduler
Claus Gittinger <cg@exept.de>
parents: 15658
diff changeset
  2514
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2515
    Smalltalk verbose ifTrue:[ Logger info:'Processor: timeslicer started' ].
17412
ef9b82b8ce77 class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 17341
diff changeset
  2516
    [
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2517
	t ~~ TimeSliceInterval ifTrue:[
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2518
	    "/ interval changed -> need a new delay
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2519
	    myDelay delay:(t := TimeSliceInterval).
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2520
	].
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2521
	myDelay wait.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2522
	self slice.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2523
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2524
	"/ every other tick, recompute priorities.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2525
	flipFlop := flipFlop not.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2526
	flipFlop ifTrue:[
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2527
	    scheduledProcesses notNil ifTrue:[
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2528
		supportDynamicPriorities ifTrue:[
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2529
		    self recomputeDynamicPriorities.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2530
		].
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2531
		scheduledProcesses clearContents.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2532
	    ] ifFalse:[
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2533
		scheduledProcesses := IdentitySet new.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2534
	    ].
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2535
	].
17412
ef9b82b8ce77 class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 17341
diff changeset
  2536
    ] loop.
2188
3814c1d74d2b integrated the timeSlicer
Claus Gittinger <cg@exept.de>
parents: 2155
diff changeset
  2537
! !
3814c1d74d2b integrated the timeSlicer
Claus Gittinger <cg@exept.de>
parents: 2155
diff changeset
  2538
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2539
!ProcessorScheduler methodsFor:'semaphore signalling'!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2540
19063
35bf380262d6 #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 19007
diff changeset
  2541
disableFd:aFileDescriptor doSignal:doSignal
35bf380262d6 #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 19007
diff changeset
  2542
    "disable triggering of a semaphore for aFileDescriptor..
20643
cdc2a4259d4d #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20612
diff changeset
  2543
     If doSignal is true, the associated semaphore is signaled.
cdc2a4259d4d #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20612
diff changeset
  2544
     Answer a collection of semaphores that haven't been signaled."
19063
35bf380262d6 #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 19007
diff changeset
  2545
35bf380262d6 #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 19007
diff changeset
  2546
    |idx "{ Class: SmallInteger }"
20643
cdc2a4259d4d #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20612
diff changeset
  2547
     wasBlocked sema semaCollection|
19063
35bf380262d6 #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 19007
diff changeset
  2548
35bf380262d6 #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 19007
diff changeset
  2549
    wasBlocked := OperatingSystem blockInterrupts.
35bf380262d6 #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 19007
diff changeset
  2550
    useIOInterrupts ifTrue:[
20706
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  2551
	OperatingSystem disableIOInterruptsOn:aFileDescriptor.
19063
35bf380262d6 #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 19007
diff changeset
  2552
    ].
35bf380262d6 #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 19007
diff changeset
  2553
20643
cdc2a4259d4d #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20612
diff changeset
  2554
    idx := readFdArray indexOf:aFileDescriptor startingAt:1.
19063
35bf380262d6 #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 19007
diff changeset
  2555
    [idx ~~ 0] whileTrue:[
20706
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  2556
	readFdArray at:idx put:nil.
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  2557
	readCheckArray at:idx put:nil.
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  2558
	(sema := readSemaphoreArray at:idx) notNil ifTrue:[
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  2559
	    readSemaphoreArray at:idx put:nil.
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  2560
	    semaCollection isNil ifTrue:[semaCollection := Set new].
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  2561
	    semaCollection add:sema.
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  2562
	].
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  2563
	idx := readFdArray indexOf:aFileDescriptor startingAt:idx+1.
19063
35bf380262d6 #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 19007
diff changeset
  2564
    ].
20643
cdc2a4259d4d #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20612
diff changeset
  2565
    idx := writeFdArray indexOf:aFileDescriptor startingAt:1.
19063
35bf380262d6 #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 19007
diff changeset
  2566
    [idx ~~ 0] whileTrue:[
20706
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  2567
	writeFdArray at:idx put:nil.
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  2568
	writeCheckArray at:idx put:nil.
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  2569
	(sema := writeSemaphoreArray at:idx) notNil ifTrue:[
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  2570
	    writeSemaphoreArray at:idx put:nil.
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  2571
	    semaCollection isNil ifTrue:[semaCollection := Set new].
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  2572
	    semaCollection add:sema.
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  2573
	].
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  2574
	idx := writeFdArray indexOf:aFileDescriptor startingAt:idx+1.
19063
35bf380262d6 #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 19007
diff changeset
  2575
    ].
20643
cdc2a4259d4d #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20612
diff changeset
  2576
    idx := exceptFdArray indexOf:aFileDescriptor startingAt:1.
19063
35bf380262d6 #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 19007
diff changeset
  2577
    [idx ~~ 0] whileTrue:[
20706
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  2578
	exceptFdArray at:idx put:nil.
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  2579
	(sema := exceptSemaphoreArray at:idx) notNil ifTrue:[
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  2580
	    exceptSemaphoreArray at:idx put:nil.
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  2581
	    semaCollection isNil ifTrue:[semaCollection := Set new].
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  2582
	    semaCollection add:sema.
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  2583
	].
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  2584
	idx := exceptFdArray indexOf:aFileDescriptor startingAt:idx+1.
20643
cdc2a4259d4d #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20612
diff changeset
  2585
    ].
cdc2a4259d4d #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20612
diff changeset
  2586
cdc2a4259d4d #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20612
diff changeset
  2587
    semaCollection isNil ifTrue:[
20706
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  2588
	semaCollection := #().
20643
cdc2a4259d4d #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20612
diff changeset
  2589
    ] ifFalse:[
20706
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  2590
	doSignal ifTrue:[
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  2591
	    semaCollection do:[:eachSema|
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  2592
		eachSema signalForAll.
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  2593
		semaCollection := #().
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  2594
	    ].
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  2595
	].
19063
35bf380262d6 #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 19007
diff changeset
  2596
    ].
35bf380262d6 #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 19007
diff changeset
  2597
    wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
20643
cdc2a4259d4d #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 20612
diff changeset
  2598
    ^ semaCollection
19063
35bf380262d6 #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 19007
diff changeset
  2599
!
35bf380262d6 #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 19007
diff changeset
  2600
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2601
disableSemaphore:aSemaphore
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2602
    "disable triggering of a semaphore"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2603
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2604
    |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
  2605
     wasBlocked fd|
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2606
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2607
    wasBlocked := OperatingSystem blockInterrupts.
20052
4bd27ae52593 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19859
diff changeset
  2608
    idx := 0.
4bd27ae52593 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19859
diff changeset
  2609
    [idx := readSemaphoreArray identityIndexOf:aSemaphore startingAt:idx+1.
4bd27ae52593 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19859
diff changeset
  2610
     idx ~~ 0] whileTrue:[
20706
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  2611
	useIOInterrupts ifTrue:[
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  2612
	    fd := readFdArray at:idx.
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  2613
	    fd notNil ifTrue:[
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  2614
		OperatingSystem disableIOInterruptsOn:fd
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  2615
	    ].
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  2616
	].
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  2617
	readFdArray at:idx put:nil.
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  2618
	readSemaphoreArray at:idx put:nil.
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  2619
	readCheckArray at:idx put:nil.
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2620
    ].
20052
4bd27ae52593 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19859
diff changeset
  2621
    idx := 0.
4bd27ae52593 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19859
diff changeset
  2622
    [idx := writeSemaphoreArray identityIndexOf:aSemaphore startingAt:idx+1.
4bd27ae52593 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19859
diff changeset
  2623
     idx ~~ 0] whileTrue:[
20706
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  2624
	useIOInterrupts ifTrue:[
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  2625
	    fd := writeFdArray at:idx.
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  2626
	    fd notNil ifTrue:[
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  2627
		OperatingSystem disableIOInterruptsOn:fd
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  2628
	    ].
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  2629
	].
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  2630
	writeFdArray at:idx put:nil.
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  2631
	writeSemaphoreArray at:idx put:nil.
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  2632
	writeCheckArray at:idx put:nil.
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2633
    ].
20052
4bd27ae52593 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19859
diff changeset
  2634
    idx := 0.
4bd27ae52593 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19859
diff changeset
  2635
    [idx := exceptSemaphoreArray identityIndexOf:aSemaphore startingAt:idx+1.
4bd27ae52593 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19859
diff changeset
  2636
     idx ~~ 0] whileTrue:[
20706
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  2637
	exceptFdArray at:idx put:nil.
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  2638
	exceptSemaphoreArray at:idx put:nil.
18957
e0bb91eae748 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18941
diff changeset
  2639
    ].
20052
4bd27ae52593 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19859
diff changeset
  2640
    self removeTimeoutForSemaphore:aSemaphore.
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2641
    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
  2642
02f9aa61f71b ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
  2643
    "Modified: 4.8.1997 / 15:19:33 / cg"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2644
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2645
1683
f7fed00976ab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1681
diff changeset
  2646
signal:aSemaphore
f7fed00976ab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1681
diff changeset
  2647
    "arrange for a semaphore to be triggered as soon as possible.
f7fed00976ab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1681
diff changeset
  2648
     The actual signalling is performed slightly delayed, when the dispatcher
2618
6d314138ab88 commentary
Claus Gittinger <cg@exept.de>
parents: 2614
diff changeset
  2649
     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
  2650
     process continues to execute, even if the semaphore signalling would
6d314138ab88 commentary
Claus Gittinger <cg@exept.de>
parents: 2614
diff changeset
  2651
     make a higher prio process runnable.
6d314138ab88 commentary
Claus Gittinger <cg@exept.de>
parents: 2614
diff changeset
  2652
     This is provided as entry for primitive-code (external functions)
6d314138ab88 commentary
Claus Gittinger <cg@exept.de>
parents: 2614
diff changeset
  2653
     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
  2654
     suspended (i.e. it is called by __STX_SignalSemaphore()).
6d314138ab88 commentary
Claus Gittinger <cg@exept.de>
parents: 2614
diff changeset
  2655
     Normal smalltalk code should always send an appropriate message directly
6d314138ab88 commentary
Claus Gittinger <cg@exept.de>
parents: 2614
diff changeset
  2656
     to the semaphore (i.e. aSemaphore signal)."
1683
f7fed00976ab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1681
diff changeset
  2657
3917
fd02c3beb3d1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3916
diff changeset
  2658
    self signal:aSemaphore atMilliseconds:OperatingSystem getMillisecondTime.
fd02c3beb3d1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3916
diff changeset
  2659
fd02c3beb3d1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3916
diff changeset
  2660
    "Modified: / 9.11.1998 / 20:39:06 / cg"
1683
f7fed00976ab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1681
diff changeset
  2661
!
f7fed00976ab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1681
diff changeset
  2662
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2663
signal:aSemaphore after:secondsOrTimeDuration
16461
11b1345b869b class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16370
diff changeset
  2664
    "arrange for a semaphore to be triggered after aTimeDuration"
11b1345b869b class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16370
diff changeset
  2665
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2666
    |ms|
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2667
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2668
    secondsOrTimeDuration isTimeDuration ifTrue:[
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2669
	ms := secondsOrTimeDuration getMilliseconds.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2670
    ] ifFalse:[
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2671
	ms := (secondsOrTimeDuration * 1000) rounded.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2672
    ].
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2673
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2674
    self signal:aSemaphore afterMilliseconds:ms.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2675
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2676
    "Modified: / 04-03-2020 / 14:32:10 / Stefan Vogel"
16461
11b1345b869b class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16370
diff changeset
  2677
!
11b1345b869b class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16370
diff changeset
  2678
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2679
signal:aSemaphore afterMilliseconds:millis
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2680
    "arrange for a semaphore to be triggered after some milliseconds"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2681
3917
fd02c3beb3d1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3916
diff changeset
  2682
    |now then|
fd02c3beb3d1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3916
diff changeset
  2683
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2684
    now := OperatingSystem getMillisecondTime.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2685
    then := OperatingSystem millisecondTimeAdd:now and:millis rounded.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2686
    self signal:aSemaphore atMilliseconds:then.
3917
fd02c3beb3d1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3916
diff changeset
  2687
fd02c3beb3d1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3916
diff changeset
  2688
    "Modified: / 9.11.1998 / 20:39:27 / cg"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2689
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2690
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2691
signal:aSemaphore afterSeconds:seconds
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2692
    "arrange for a semaphore to be triggered after some seconds"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2693
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2694
    self signal:aSemaphore afterMilliseconds:(seconds * 1000)
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2695
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2696
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2697
signal:aSemaphore atMilliseconds:aMillisecondTime
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2698
    "arrange for a semaphore to be triggered at a specific millisecond time.
2618
6d314138ab88 commentary
Claus Gittinger <cg@exept.de>
parents: 2614
diff changeset
  2699
     If there is already a pending trigger time installed for that semaphore,
6d314138ab88 commentary
Claus Gittinger <cg@exept.de>
parents: 2614
diff changeset
  2700
     the time of the pending trigger is changed."
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2701
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2702
    |index "{ Class: SmallInteger }"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2703
     wasBlocked|
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2704
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2705
    wasBlocked := OperatingSystem blockInterrupts.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2706
    index := timeoutSemaphoreArray identityIndexOf:aSemaphore startingAt:1.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2707
    index ~~ 0 ifTrue:[
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2708
	timeoutArray at:index put:aMillisecondTime
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2709
    ] ifFalse:[
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2710
	index := timeoutArray identityIndexOf:nil startingAt:1.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2711
	index ~~ 0 ifTrue:[
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2712
	    timeoutSemaphoreArray at:index put:aSemaphore.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2713
	    timeoutArray at:index put:aMillisecondTime.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2714
	    timeoutActionArray at:index put:nil.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2715
	    timeoutProcessArray at:index put:nil
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2716
	] ifFalse:[
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2717
	    timeoutSemaphoreArray := timeoutSemaphoreArray copyWith:aSemaphore.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2718
	    timeoutArray := timeoutArray copyWith:aMillisecondTime.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2719
	    timeoutActionArray := timeoutActionArray copyWith:nil.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2720
	    timeoutProcessArray := timeoutProcessArray copyWith:nil
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2721
	].
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2722
    ].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2723
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2724
    anyTimeouts := true.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2725
    wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2726
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2727
18957
e0bb91eae748 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18941
diff changeset
  2728
signal:aSemaphore onException:aFileDescriptor
e0bb91eae748 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18941
diff changeset
  2729
    "arrange for a semaphore to be triggered when output on aFileDescriptor
e0bb91eae748 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18941
diff changeset
  2730
     is possible (i.e. can be written without blocking) or aBlock returns true.
e0bb91eae748 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18941
diff changeset
  2731
     The checkBlock will be evaluated by the scheduler from time to time
e0bb91eae748 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18941
diff changeset
  2732
     (i.e. every few milliseconds).
e0bb91eae748 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18941
diff changeset
  2733
     This checkBlock is required for poor windows, where a WaitForObject does
e0bb91eae748 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18941
diff changeset
  2734
     not know about sockets.
e0bb91eae748 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18941
diff changeset
  2735
     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
  2736
e0bb91eae748 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18941
diff changeset
  2737
    |idx "{ Class: SmallInteger }"
e0bb91eae748 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18941
diff changeset
  2738
     wasBlocked slot|
e0bb91eae748 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18941
diff changeset
  2739
e0bb91eae748 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18941
diff changeset
  2740
    wasBlocked := OperatingSystem blockInterrupts.
e0bb91eae748 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18941
diff changeset
  2741
e0bb91eae748 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18941
diff changeset
  2742
    "Here we assume, that for every triple (aSemaphore, aFileDescriptor, aBlock)
e0bb91eae748 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18941
diff changeset
  2743
     aSemphore is never nil, but one of aFileDescriptor, aBlock may be nil"
e0bb91eae748 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18941
diff changeset
  2744
e0bb91eae748 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18941
diff changeset
  2745
    aFileDescriptor isNil ifTrue:[
19850
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  2746
	idx := exceptSemaphoreArray identityIndexOf:aSemaphore or:nil.
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  2747
	idx == 0 ifTrue:[
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  2748
	    "aSemaphore is not registered yet, have to create a new slot"
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  2749
	    exceptFdArray := exceptFdArray copyWith:nil.
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  2750
	    exceptSemaphoreArray := exceptSemaphoreArray copyWith:aSemaphore.
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  2751
	] ifFalse:[
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  2752
	    slot := exceptSemaphoreArray at:idx.
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  2753
	    slot isNil ifTrue:[
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  2754
		exceptSemaphoreArray at:idx put:aSemaphore.
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  2755
	    ]
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  2756
	]
18957
e0bb91eae748 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18941
diff changeset
  2757
    ] ifFalse:[
19850
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  2758
	idx := exceptFdArray identityIndexOf:aFileDescriptor or:nil.
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  2759
	idx == 0 ifTrue:[
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  2760
	    "aFileDescriptor is not registered yet, have to create a new slot"
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  2761
	    exceptFdArray := exceptFdArray copyWith:aFileDescriptor.
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  2762
	    exceptSemaphoreArray := exceptSemaphoreArray copyWith:aSemaphore.
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  2763
	] ifFalse:[
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  2764
	    slot := exceptFdArray at:idx.
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  2765
	    slot isNil ifTrue:[
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  2766
		exceptFdArray at:idx put:aFileDescriptor.
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  2767
		exceptSemaphoreArray at:idx put:aSemaphore.
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  2768
	    ].
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  2769
	].
18957
e0bb91eae748 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18941
diff changeset
  2770
"/        (useIOInterrupts and:[slot isNil]) ifTrue:[
e0bb91eae748 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18941
diff changeset
  2771
"/            OperatingSystem enableIOInterruptsOn:aFileDescriptor
e0bb91eae748 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18941
diff changeset
  2772
"/        ].
e0bb91eae748 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18941
diff changeset
  2773
    ].
e0bb91eae748 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18941
diff changeset
  2774
    wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
e0bb91eae748 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18941
diff changeset
  2775
e0bb91eae748 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18941
diff changeset
  2776
    "Modified: 4.8.1997 / 15:21:49 / cg"
e0bb91eae748 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18941
diff changeset
  2777
!
e0bb91eae748 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18941
diff changeset
  2778
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2779
signal:aSemaphore onInput:aFileDescriptor
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2780
    "arrange for a semaphore to be triggered when input on aFileDescriptor
16461
11b1345b869b class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16370
diff changeset
  2781
     arrives. This will only happen, if the OS supports selecting on fileDescriptors.
11b1345b869b class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16370
diff changeset
  2782
     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
  2783
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2784
    self signal:aSemaphore onInput:aFileDescriptor orCheck:nil
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2785
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2786
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2787
signal:aSemaphore onInput:aFileDescriptor orCheck:aBlock
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2788
    "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
  2789
     arrives OR checkblock evaluates to true.
e9ea71d01445 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10497
diff changeset
  2790
     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
  2791
     (i.e. every few milliseconds).
10747
e9ea71d01445 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10497
diff changeset
  2792
     (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
  2793
      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
  2794
      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
  2795
     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
  2796
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2797
    |idx "{ Class: SmallInteger }"
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2798
     wasBlocked slot readCheckEntry|
1627
f95285226059 infoPrint for NT (no select)
Claus Gittinger <cg@exept.de>
parents: 1618
diff changeset
  2799
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2800
    wasBlocked := OperatingSystem blockInterrupts.
3116
e535e4e266dd more error handling;
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
  2801
16319
d38c34400bd0 class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16317
diff changeset
  2802
    "Here we assume, that for every triple (aSemaphore, aFileDescriptor, aBlock)
d38c34400bd0 class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16317
diff changeset
  2803
     aSemphore is never nil, but one of aFileDescriptor, aBlock may be nil"
d38c34400bd0 class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16317
diff changeset
  2804
6807
ba04d2e1a416 oops - hps lexer is not 8-bit clean
Claus Gittinger <cg@exept.de>
parents: 6619
diff changeset
  2805
    aFileDescriptor isNil ifTrue:[
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2806
	aBlock isNil ifTrue:[
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2807
	    wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2808
	    self error:'Signalling requested for nil fd and nil block'.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2809
	].
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2810
	idx := readSemaphoreArray identityIndexOf:aSemaphore or:nil.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2811
	idx == 0 ifTrue:[
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2812
	    "aSemaphore is not registered yet, have to create a new slot"
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2813
	    readFdArray := readFdArray copyWith:nil.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2814
	    readSemaphoreArray := readSemaphoreArray copyWith:aSemaphore.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2815
	    readCheckArray := readCheckArray copyWith:aBlock.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2816
	] ifFalse:[
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2817
	    slot := readSemaphoreArray at:idx.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2818
	    slot isNil ifTrue:[
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2819
		"aSemaphore is not registered yet, found an empty slot"
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2820
		readSemaphoreArray at:idx put:aSemaphore.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2821
		readCheckArray at:idx put:aBlock
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2822
	    ] ifFalse:[
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2823
		"/ someone has already registered aSemaphore.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2824
		"/ Check if it is the block changes...
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2825
		readCheckEntry := readCheckArray at:idx.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2826
		(readCheckEntry notNil
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2827
		 and:[readCheckEntry ~~ aBlock]) ifTrue:[
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2828
		    Logger info:'Processor: checkblock changed for read-check'.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2829
		    readCheckArray at:idx put:aBlock.
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2830
		].
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2831
	    ].
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2832
	]
16319
d38c34400bd0 class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16317
diff changeset
  2833
    ] ifFalse:[
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2834
	idx := readFdArray identityIndexOf:aFileDescriptor or:nil.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2835
	idx == 0 ifTrue:[
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2836
	    "aFileDescriptor is not registered yet, have to create a new slot"
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2837
	    readFdArray := readFdArray copyWith:aFileDescriptor.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2838
	    readSemaphoreArray := readSemaphoreArray copyWith:aSemaphore.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2839
	    readCheckArray := readCheckArray copyWith:aBlock.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2840
	] ifFalse:[
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2841
	    slot := readFdArray at:idx.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2842
	    slot isNil ifTrue:[
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2843
		"aFileDescriptor is not registered yet, found an empty slot"
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2844
		readFdArray at:idx put:aFileDescriptor.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2845
		readSemaphoreArray at:idx put:aSemaphore.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2846
		readCheckArray at:idx put:aBlock
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2847
	    ] ifFalse:[
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2848
		"/ someone has already registered aFileDescriptor.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2849
		"/ Check if it is the semaphore or block changes...
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2850
		(readSemaphoreArray at:idx) ~~ aSemaphore ifTrue:[
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2851
		    Logger warning:'Processor: sema changed for read-check'.
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2852
		    readSemaphoreArray at:idx put:aSemaphore.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2853
		].
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2854
		(readCheckArray at:idx) ~~ aBlock ifTrue:[
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2855
		    Logger info:'Processor: checkblock changed for read-check'.
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2856
		    readCheckArray at:idx put:aBlock.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2857
		].
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2858
	    ].
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2859
	].
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2860
	(useIOInterrupts and:[slot isNil]) ifTrue:[
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2861
	    OperatingSystem enableIOInterruptsOn:aFileDescriptor
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2862
	].
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2863
    ].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2864
    wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
2123
6f9cb1ed9db5 new infoMessage scheme
Claus Gittinger <cg@exept.de>
parents: 2116
diff changeset
  2865
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2866
    "Modified: / 04-08-1997 / 15:20:45 / cg"
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2867
    "Modified: / 20-05-2020 / 18:20:56 / Stefan Vogel"
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
5103
7b1f6c93b3aa checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5101
diff changeset
  2870
signal:aSemaphore onInputStream:aStream
10747
e9ea71d01445 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10497
diff changeset
  2871
    "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
  2872
     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
  2873
     otherwise, it will be polled every few milliseconds (MSDOS)."
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2874
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2875
    |fd|
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2876
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2877
    fd := aStream fileHandle.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2878
    fd isNil ifTrue:[
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2879
	aSemaphore signal.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2880
    ].
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2881
5101
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2882
    aStream canBeSelected ifTrue:[
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2883
	"/ can this stream be selected on ?
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2884
	self signal:aSemaphore onInput:fd orCheck:nil
5101
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2885
    ] ifFalse:[
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2886
	"/ nope - must poll ...
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2887
	self signal:aSemaphore onInput:nil orCheck:[aStream canReadWithoutBlocking]
5101
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2888
    ]
5107
1dc3079e8eaf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5103
diff changeset
  2889
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2890
    "Modified: / 14-12-1999 / 23:58:50 / cg"
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2891
    "Modified: / 04-03-2020 / 14:57:35 / Stefan Vogel"
5101
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2892
!
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2893
5103
7b1f6c93b3aa checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5101
diff changeset
  2894
signal:aSemaphore onOutput:aFileDescriptor
7b1f6c93b3aa checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5101
diff changeset
  2895
    "arrange for a semaphore to be triggered when output on aFileDescriptor
16461
11b1345b869b class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16370
diff changeset
  2896
     is possible without blocking.
11b1345b869b class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16370
diff changeset
  2897
     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
  2898
7b1f6c93b3aa checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5101
diff changeset
  2899
    self signal:aSemaphore onOutput:aFileDescriptor orCheck:nil
7b1f6c93b3aa checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5101
diff changeset
  2900
7b1f6c93b3aa checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5101
diff changeset
  2901
    "Created: / 14.12.1999 / 19:54:12 / cg"
7b1f6c93b3aa checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5101
diff changeset
  2902
!
7b1f6c93b3aa checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5101
diff changeset
  2903
5101
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2904
signal:aSemaphore onOutput:aFileDescriptor orCheck:aBlock
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2905
    "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
  2906
     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
  2907
     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
  2908
     (i.e. every few milliseconds).
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2909
     This checkBlock is required for poor windows, where a WaitForObject does
16461
11b1345b869b class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16370
diff changeset
  2910
     not know about sockets.
11b1345b869b class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16370
diff changeset
  2911
     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
  2912
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2913
    |idx "{ Class: SmallInteger }"
16319
d38c34400bd0 class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16317
diff changeset
  2914
     wasBlocked slot|
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2915
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2916
    wasBlocked := OperatingSystem blockInterrupts.
5101
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2917
16319
d38c34400bd0 class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16317
diff changeset
  2918
    "Here we assume, that for every triple (aSemaphore, aFileDescriptor, aBlock)
d38c34400bd0 class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16317
diff changeset
  2919
     aSemphore is never nil, but one of aFileDescriptor, aBlock may be nil"
d38c34400bd0 class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16317
diff changeset
  2920
5101
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2921
    aFileDescriptor isNil ifTrue:[
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2922
	idx := writeSemaphoreArray identityIndexOf:aSemaphore or:nil.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2923
	idx == 0 ifTrue:[
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2924
	    "aSemaphore is not registered yet, have to create a new slot"
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2925
	    writeFdArray := writeFdArray copyWith:nil.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2926
	    writeSemaphoreArray := writeSemaphoreArray copyWith:aSemaphore.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2927
	    writeCheckArray := writeCheckArray copyWith:aBlock.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2928
	] ifFalse:[
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2929
	    slot := writeSemaphoreArray at:idx.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2930
	    slot isNil ifTrue:[
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2931
		writeSemaphoreArray at:idx put:aSemaphore.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2932
		writeCheckArray at:idx put:aBlock
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2933
	    ] ifFalse:[
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2934
		"/ someone has already registered aSemaphore.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2935
		"/ Check if it is the block changes...
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2936
		(writeCheckArray at:idx) notNil ifTrue:[
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2937
		    (writeCheckArray at:idx) ~~ aBlock ifTrue:[
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2938
			Logger info:'Processor: checkblock changed for write-check'.
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2939
			writeCheckArray at:idx put:aBlock.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2940
		    ].
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2941
		].
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2942
	    ].
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2943
	]
16319
d38c34400bd0 class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16317
diff changeset
  2944
    ] ifFalse:[
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2945
	idx := writeFdArray identityIndexOf:aFileDescriptor or:nil.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2946
	idx == 0 ifTrue:[
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2947
	    "aFileDescriptor is not registered yet, and no empty slot is available; have to create a new slot"
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2948
	    writeFdArray := writeFdArray copyWith:aFileDescriptor.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2949
	    writeSemaphoreArray := writeSemaphoreArray copyWith:aSemaphore.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2950
	    writeCheckArray := writeCheckArray copyWith:aBlock.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2951
	] ifFalse:[
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2952
	    slot := writeFdArray at:idx.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2953
	    slot isNil ifTrue:[
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2954
		"aFileDescriptor is not yet registered, but there is an empty slot"
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2955
		writeFdArray at:idx put:aFileDescriptor.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2956
		writeSemaphoreArray at:idx put:aSemaphore.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2957
		writeCheckArray at:idx put:aBlock
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2958
	    ] ifFalse:[
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2959
		"/ someone has already registered aFileDescriptor.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2960
		"/ Check if it is the semaphore or block changes...
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2961
		(writeSemaphoreArray at:idx) ~~ aSemaphore ifTrue:[
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2962
		    Logger warning:'Processor: sema changed for write-check'.
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2963
		    writeSemaphoreArray at:idx put:aSemaphore.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2964
		].
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2965
		(writeCheckArray at:idx) ~~ aBlock ifTrue:[
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2966
		    Logger info:'Processor: checkblock changed for write-check'.
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2967
		    writeCheckArray at:idx put:aBlock.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2968
		].
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2969
	    ].
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2970
	].
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2971
	(useIOInterrupts and:[slot isNil]) ifTrue:[
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2972
	    OperatingSystem enableIOInterruptsOn:aFileDescriptor
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  2973
	].
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2974
    ].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2975
    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
  2976
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2977
    "Modified: / 04-08-1997 / 15:21:49 / cg"
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2978
    "Modified: / 20-05-2020 / 18:20:39 / Stefan Vogel"
5103
7b1f6c93b3aa checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5101
diff changeset
  2979
!
7b1f6c93b3aa checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5101
diff changeset
  2980
7b1f6c93b3aa checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5101
diff changeset
  2981
signal:aSemaphore onOutputStream:aStream
10747
e9ea71d01445 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10497
diff changeset
  2982
    "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
  2983
     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
  2984
     otherwise, it will be polled every few milliseconds (MSDOS)."
7b1f6c93b3aa checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5101
diff changeset
  2985
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2986
    |fd|
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2987
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2988
    fd := aStream fileHandle.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2989
    fd isNil ifTrue:[
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2990
	aSemaphore signal.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2991
    ].
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2992
5103
7b1f6c93b3aa checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5101
diff changeset
  2993
    aStream canBeSelected ifTrue:[
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2994
	"/ can this stream be selected on ?
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2995
	self signal:aSemaphore onOutput:fd orCheck:nil
5103
7b1f6c93b3aa checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5101
diff changeset
  2996
    ] ifFalse:[
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2997
	"/ nope - must poll ...
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  2998
	self signal:aSemaphore onOutput:nil orCheck:[aStream canWriteWithoutBlocking]
5103
7b1f6c93b3aa checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5101
diff changeset
  2999
    ]
5107
1dc3079e8eaf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5103
diff changeset
  3000
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3001
    "Modified: / 14-12-1999 / 23:59:19 / cg"
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3002
    "Modified: / 04-03-2020 / 14:58:05 / Stefan Vogel"
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
3650
523781600982 added #useIOInterrupts: to allow disabling this feature
Claus Gittinger <cg@exept.de>
parents: 3644
diff changeset
  3005
!ProcessorScheduler methodsFor:'special configuration'!
523781600982 added #useIOInterrupts: to allow disabling this feature
Claus Gittinger <cg@exept.de>
parents: 3644
diff changeset
  3006
523781600982 added #useIOInterrupts: to allow disabling this feature
Claus Gittinger <cg@exept.de>
parents: 3644
diff changeset
  3007
useIOInterrupts:aBoolean
523781600982 added #useIOInterrupts: to allow disabling this feature
Claus Gittinger <cg@exept.de>
parents: 3644
diff changeset
  3008
    "enable/disable the use of IO-interrupts.
523781600982 added #useIOInterrupts: to allow disabling this feature
Claus Gittinger <cg@exept.de>
parents: 3644
diff changeset
  3009
     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
  3010
     are polled in regular intervals.
523781600982 added #useIOInterrupts: to allow disabling this feature
Claus Gittinger <cg@exept.de>
parents: 3644
diff changeset
  3011
     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
  3012
     interrupt.
523781600982 added #useIOInterrupts: to allow disabling this feature
Claus Gittinger <cg@exept.de>
parents: 3644
diff changeset
  3013
     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
  3014
     (typically 2-7%).
10747
e9ea71d01445 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10497
diff changeset
  3015
     Notice:
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  3016
	some systems do not support IO-interrupts (or have a broken stdio-lib),
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  3017
	and this feature is always disabled;
3650
523781600982 added #useIOInterrupts: to allow disabling this feature
Claus Gittinger <cg@exept.de>
parents: 3644
diff changeset
  3018
     Also notice:
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  3019
	we found that in some Xlib-implementations, interrupted reads are not
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  3020
	handled correctly (especially in multi-headed applications), and this
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  3021
	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
  3022
10747
e9ea71d01445 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10497
diff changeset
  3023
     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
  3024
     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
  3025
523781600982 added #useIOInterrupts: to allow disabling this feature
Claus Gittinger <cg@exept.de>
parents: 3644
diff changeset
  3026
    OperatingSystem supportsIOInterrupts ifTrue:[
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  3027
	useIOInterrupts := aBoolean
3650
523781600982 added #useIOInterrupts: to allow disabling this feature
Claus Gittinger <cg@exept.de>
parents: 3644
diff changeset
  3028
    ].
523781600982 added #useIOInterrupts: to allow disabling this feature
Claus Gittinger <cg@exept.de>
parents: 3644
diff changeset
  3029
523781600982 added #useIOInterrupts: to allow disabling this feature
Claus Gittinger <cg@exept.de>
parents: 3644
diff changeset
  3030
    "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
  3031
! !
523781600982 added #useIOInterrupts: to allow disabling this feature
Claus Gittinger <cg@exept.de>
parents: 3644
diff changeset
  3032
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  3033
!ProcessorScheduler methodsFor:'timeout handling'!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  3034
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3035
addTimedBlock:aBlock after:timeDurationOrSeconds
16496
8b9c1ca54d42 class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16461
diff changeset
  3036
    "add the argument, aBlock to the list of time-scheduled-blocks; to be
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3037
     evaluated after timeDuration.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3038
     The process which installs this timed
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3039
     block will later be interrupted for execution of the block.
16496
8b9c1ca54d42 class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16461
diff changeset
  3040
     (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
  3041
      executing; if it is suspended, it will be resumed).
8b9c1ca54d42 class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16461
diff changeset
  3042
     The block will be removed from the timed-block list after evaluation
8b9c1ca54d42 class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16461
diff changeset
  3043
     (i.e. it will trigger only once).
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3044
     Returns an ID, which can be used in #removeTimeoutWithID:"
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3045
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3046
    |millis|
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3047
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3048
    millis := timeDurationOrSeconds isNumber
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3049
		ifTrue:[ (timeDurationOrSeconds * 1000) rounded ]
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3050
		ifFalse:[ timeDurationOrSeconds getMilliseconds ].
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3051
    ^ self addTimedBlock:aBlock for:activeProcess afterMilliseconds:millis
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3052
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3053
    "Modified (comment): / 20-07-2017 / 16:43:12 / cg"
16496
8b9c1ca54d42 class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16461
diff changeset
  3054
!
8b9c1ca54d42 class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16461
diff changeset
  3055
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  3056
addTimedBlock:aBlock afterMilliseconds:delta
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  3057
    "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
  3058
     evaluated after delta milliseconds. The process which installs this timed
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  3059
     block will be interrupted for execution of the block.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  3060
     (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
  3061
      executing; if it is suspended, it will be resumed).
10747
e9ea71d01445 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10497
diff changeset
  3062
     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
  3063
     (i.e. it will trigger only once).
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3064
     Returns an ID, which can be used in #removeTimeoutWithID:"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  3065
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  3066
    ^ self addTimedBlock:aBlock for:activeProcess afterMilliseconds:delta
1676
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  3067
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3068
    "Modified: / 23-09-1996 / 14:33:59 / cg"
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3069
    "Modified (comment): / 20-07-2017 / 16:43:17 / cg"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  3070
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  3071
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  3072
addTimedBlock:aBlock afterSeconds:delta
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  3073
    "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
  3074
     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
  3075
     block will be interrupted for execution of the block.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  3076
     (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
  3077
      executing; if it is suspended, it will be resumed).
10747
e9ea71d01445 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10497
diff changeset
  3078
     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
  3079
     (i.e. it will trigger only once).
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3080
     Returns an ID, which can be used in #removeTimeoutWithID:"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  3081
1676
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  3082
    ^ self addTimedBlock:aBlock for:activeProcess afterMilliseconds:(delta * 1000) rounded
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  3083
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3084
    "Modified: / 23-09-1996 / 14:34:04 / cg"
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3085
    "Modified (comment): / 20-07-2017 / 16:42:54 / cg"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  3086
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  3087
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  3088
addTimedBlock:aBlock atMilliseconds:aMillisecondTime
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  3089
    "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
  3090
     evaluated when the millisecondClock value passes aMillisecondTime.
10747
e9ea71d01445 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10497
diff changeset
  3091
     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
  3092
     execution of the block.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  3093
     (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
  3094
      executing; if it is suspended, it will be resumed).
10747
e9ea71d01445 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10497
diff changeset
  3095
     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
  3096
     (i.e. it will trigger only once).
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3097
     Returns an ID, which can be used in #removeTimeoutWithID:"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  3098
1676
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  3099
    ^ self addTimedBlock:aBlock for:activeProcess atMilliseconds:aMillisecondTime
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  3100
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3101
    "Modified: / 23-09-1996 / 14:34:09 / cg"
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3102
    "Modified (comment): / 20-07-2017 / 16:43:22 / cg"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  3103
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  3104
16496
8b9c1ca54d42 class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16461
diff changeset
  3105
addTimedBlock:aBlock for:aProcess after:timeDuration
8b9c1ca54d42 class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16461
diff changeset
  3106
    "add the argument, aBlock to the list of time-scheduled-blocks.
8b9c1ca54d42 class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16461
diff changeset
  3107
     to be evaluated after timeDuration. aProcess will be interrupted for
8b9c1ca54d42 class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16461
diff changeset
  3108
     execution of the block.
8b9c1ca54d42 class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16461
diff changeset
  3109
     (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
  3110
      executing; if it is suspended, it will be resumed).
8b9c1ca54d42 class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16461
diff changeset
  3111
     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
  3112
     (which is dangerous - the block should not raise any error conditions).
8b9c1ca54d42 class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16461
diff changeset
  3113
     The block will be removed from the timed-block list after evaluation
8b9c1ca54d42 class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16461
diff changeset
  3114
     (i.e. it will trigger only once).
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3115
     Returns an ID, which can be used in #removeTimeoutWithID:"
16496
8b9c1ca54d42 class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16461
diff changeset
  3116
8b9c1ca54d42 class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16461
diff changeset
  3117
    ^ self addTimedBlock:aBlock for:aProcess afterMilliseconds:timeDuration getMilliseconds
8b9c1ca54d42 class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16461
diff changeset
  3118
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3119
    "Modified: / 23-09-1996 / 14:34:18 / cg"
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3120
    "Modified (comment): / 20-07-2017 / 16:43:26 / cg"
16496
8b9c1ca54d42 class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16461
diff changeset
  3121
!
8b9c1ca54d42 class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16461
diff changeset
  3122
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3123
addTimedBlock:aBlock for:aProcessOrNil afterMilliseconds:delta
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  3124
    "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
  3125
     evaluated after delta milliseconds. The process specified by the argument,
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3126
     aProcessOrNil will be interrupted for execution of the block.
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  3127
     (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
  3128
      executing; if it is suspended, it will be resumed).
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3129
     If aProcessOrNil is nil, the block will be evaluated by the scheduler itself
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  3130
     (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
  3131
     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
  3132
     (i.e. it will trigger only once).
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3133
     Returns an ID, which can be used in #removeTimeoutWithID:"
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3134
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3135
    |now then|
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3136
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  3137
    now := OperatingSystem getMillisecondTime.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  3138
    then := OperatingSystem millisecondTimeAdd:now and:delta.
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3139
    ^ self addTimedBlock:aBlock for:aProcessOrNil atMilliseconds:then.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3140
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3141
    "Modified: / 18-07-2017 / 14:04:31 / cg"
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3142
    "Modified (comment): / 20-07-2017 / 16:43:29 / cg"
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3143
    "Modified: / 07-02-2018 / 17:25:56 / stefan"
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3144
    "Modified (comment): / 13-02-2019 / 23:38:11 / Claus Gittinger"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  3145
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  3146
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  3147
addTimedBlock:aBlock for:aProcess afterSeconds:delta
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  3148
    "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
  3149
     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
  3150
     execution of the block.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  3151
     (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
  3152
      executing; if it is suspended, it will be resumed).
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  3153
     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
  3154
     (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
  3155
     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
  3156
     (i.e. it will trigger only once).
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3157
     Returns an ID, which can be used in #removeTimeoutWithID:"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  3158
1676
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  3159
    ^ self addTimedBlock:aBlock for:aProcess afterMilliseconds:(delta * 1000) rounded
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  3160
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3161
    "Modified: / 23-09-1996 / 14:34:18 / cg"
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3162
    "Modified (comment): / 20-07-2017 / 16:43:32 / cg"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  3163
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  3164
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3165
addTimedBlock:aBlock for:aProcessOrNil atMilliseconds:aMillisecondTime
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3166
    "add the argument, aBlock to the list of time-scheduled-blocks;
20736
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  3167
     to be evaluated by aProcess when the millisecondClock value passes
10747
e9ea71d01445 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10497
diff changeset
  3168
     aMillisecondTime.
20736
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  3169
     If that block is already in the timeout list, its trigger-time is changed.
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3170
     The process specified by the argument, aProcess
20736
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  3171
     will be interrupted for execution of the block.
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3172
     If aProcessOrNil 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
  3173
     (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
  3174
     If the process is active at trigger time, the interrupt will occur in
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3175
     whatever method it is executing;
20736
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  3176
     if suspended at trigger time, it will be resumed.
10747
e9ea71d01445 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10497
diff changeset
  3177
     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
  3178
     (i.e. it will trigger only once).
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3179
     Returns an ID, which can be used in #removeTimeoutWithID:"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  3180
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  3181
    |index "{ Class: SmallInteger }"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  3182
     wasBlocked|
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  3183
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3184
    "/ self assert:(aBlock isBlockOrMessageSend).
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3185
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  3186
    wasBlocked := OperatingSystem blockInterrupts.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  3187
    index := timeoutActionArray identityIndexOf:aBlock startingAt:1.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  3188
    index ~~ 0 ifTrue:[
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3189
	timeoutArray at:index put:aMillisecondTime
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  3190
    ] ifFalse:[
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3191
	index := timeoutArray indexOf:nil.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3192
	index ~~ 0 ifTrue:[
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3193
	    timeoutArray at:index put:aMillisecondTime.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3194
	    timeoutActionArray at:index put:aBlock.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3195
	    timeoutSemaphoreArray at:index put:nil.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3196
	    timeoutProcessArray at:index put:aProcessOrNil
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3197
	] ifFalse:[
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3198
	    timeoutArray := timeoutArray copyWith:aMillisecondTime.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3199
	    timeoutActionArray := timeoutActionArray copyWith:aBlock.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3200
	    timeoutSemaphoreArray := timeoutSemaphoreArray copyWith:nil.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3201
	    timeoutProcessArray := timeoutProcessArray copyWith:aProcessOrNil.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3202
	    index := timeoutArray size.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3203
	].
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  3204
    ].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  3205
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  3206
    anyTimeouts := true.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  3207
    wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
1676
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  3208
    ^ index
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  3209
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3210
    "Modified: / 23-09-1996 / 14:34:23 / cg"
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3211
    "Modified (comment): / 20-07-2017 / 16:43:36 / cg"
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3212
    "Modified (comment): / 13-02-2019 / 23:38:38 / Claus Gittinger"
1676
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  3213
!
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  3214
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  3215
addTimeoutFunctionCall:anExternalFunction for:aProcess afterMilliseconds:delta with:argument
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  3216
    "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
  3217
     after some millisecond-Delay.
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  3218
     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
  3219
     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
  3220
     in this processes context.
10747
e9ea71d01445 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10497
diff changeset
  3221
     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
  3222
     (i.e. it will trigger only once).
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3223
     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
  3224
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  3225
    |now then wasBlocked id|
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  3226
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  3227
    wasBlocked := OperatingSystem blockInterrupts.
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  3228
    now := OperatingSystem getMillisecondTime.
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  3229
    then := OperatingSystem millisecondTimeAdd:now and:delta.
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  3230
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  3231
    id := self
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  3232
	addTimeoutFunctionCall:anExternalFunction
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  3233
	for:aProcess
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  3234
	atMilliseconds:then
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  3235
	with:argument.
1676
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  3236
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  3237
    wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  3238
    ^ id
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  3239
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3240
    "Created: / 23-09-1996 / 14:28:27 / cg"
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3241
    "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
  3242
!
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  3243
1681
56d8d1d96d95 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1680
diff changeset
  3244
addTimeoutFunctionCall:anExternalFunction for:aProcess atMilliseconds:milliTime with:argument
1676
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  3245
    "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
  3246
     at some millisecond-time.
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  3247
     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
  3248
     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
  3249
     in this processes context.
10747
e9ea71d01445 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10497
diff changeset
  3250
     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
  3251
     (i.e. it will trigger only once).
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3252
     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
  3253
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  3254
    |action|
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  3255
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  3256
    action := [anExternalFunction callWith:argument].
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  3257
    ^ self
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  3258
	addTimedBlock:action
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  3259
	for:aProcess
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  3260
	atMilliseconds:milliTime.
1676
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  3261
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3262
    "Created: / 23-09-1996 / 14:29:30 / cg"
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3263
    "Modified (comment): / 20-07-2017 / 16:43:42 / cg"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  3264
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  3265
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  3266
evaluateTimeouts
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  3267
    "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
  3268
16210
3f0d3162e40b class: ProcessorScheduler
Claus Gittinger <cg@exept.de>
parents: 16206
diff changeset
  3269
    |sema now aTime block blocksAndProcessesToEvaluate
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  3270
     firstBlockToEvaluate firstProcess
16231
88589c89be48 class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16210
diff changeset
  3271
     n "{ Class: SmallInteger }"
15657
ffad68df93ca class: ProcessorScheduler
Claus Gittinger <cg@exept.de>
parents: 15634
diff changeset
  3272
     indexOfLastTimeout "{ Class: SmallInteger }"
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3273
     halfSize "{ Class: SmallInteger }" process wasBlocked|
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3274
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3275
    anyTimeouts ifFalse:[
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3276
	^ self
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3277
    ].
11164
8cbff6ed574f #timeToNextTimeout - handling of negative time deltas
Stefan Vogel <sv@exept.de>
parents: 10748
diff changeset
  3278
    anyTimeouts := false.
19858
5146a1f4779f oops compilable
Claus Gittinger <cg@exept.de>
parents: 19853
diff changeset
  3279
    indexOfLastTimeout := 0.
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  3280
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  3281
    "have to collect the blocks first, then evaluate them.
16210
3f0d3162e40b class: ProcessorScheduler
Claus Gittinger <cg@exept.de>
parents: 16206
diff changeset
  3282
     This avoids problems due to newly inserted blocks."
3f0d3162e40b class: ProcessorScheduler
Claus Gittinger <cg@exept.de>
parents: 16206
diff changeset
  3283
3f0d3162e40b class: ProcessorScheduler
Claus Gittinger <cg@exept.de>
parents: 16206
diff changeset
  3284
    "/ notice: the code looks uglier than seems to be required;
3f0d3162e40b class: ProcessorScheduler
Claus Gittinger <cg@exept.de>
parents: 16206
diff changeset
  3285
    "/ 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
  3286
    "/ is found in the loops below.
16231
88589c89be48 class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16210
diff changeset
  3287
    "/ 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
  3288
    "/ 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
  3289
    "/ 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
  3290
    "/ 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
  3291
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3292
    wasBlocked := OperatingSystem blockInterrupts.
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  3293
    now := OperatingSystem getMillisecondTime.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  3294
    n := timeoutArray size.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  3295
    1 to:n do:[:index |
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3296
	aTime := timeoutArray at:index.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3297
	aTime notNil ifTrue:[
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3298
	    (OperatingSystem millisecondTime:now isAfter:aTime) ifTrue:[
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3299
		"this one should be triggered"
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3300
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3301
		sema := timeoutSemaphoreArray at:index.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3302
		sema notNil ifTrue:[
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3303
		    timeoutSemaphoreArray at:index put:nil.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3304
		    timedActionCounter := (timedActionCounter + 1) bitAnd:SmallInteger maxVal.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3305
		    sema signalOnceWithoutReschedule.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3306
		] ifFalse:[
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3307
		    "to support pure-events"
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3308
		    block := timeoutActionArray at:index.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3309
		    block notNil ifTrue:[
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3310
"/                        RecentHomeMethods isNil ifTrue:[
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3311
"/                            RecentHomeMethods := OrderedCollection new.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3312
"/                        ].
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3313
"/                        RecentHomeMethods add:block homeMethod.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3314
"/                        RecentHomeMethods size > 30 ifTrue:[ RecentHomeMethods removeFirst ].
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3315
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3316
			"/ usually (>99%), there is only one single timeout action to call;
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3317
			"/ avoid creation of an OrderedCollection
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3318
			firstBlockToEvaluate isNil ifTrue:[
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3319
			    firstBlockToEvaluate := block.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3320
			    firstProcess := timeoutProcessArray at:index.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3321
			] ifFalse:[
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3322
			    blocksAndProcessesToEvaluate isNil ifTrue:[
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3323
				blocksAndProcessesToEvaluate := OrderedCollection
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3324
								    with:firstBlockToEvaluate
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3325
								    with:firstProcess
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3326
								    with:block
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3327
								    with:(timeoutProcessArray at:index).
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3328
			    ] ifFalse:[
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3329
				blocksAndProcessesToEvaluate
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3330
				    add:block;
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3331
				    add:(timeoutProcessArray at:index).
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3332
			    ].
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3333
			].
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3334
			timeoutActionArray at:index put:nil.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3335
			timeoutProcessArray at:index put:nil.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3336
		    ]
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3337
		].
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3338
		timeoutArray at:index put:nil.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3339
	    ] ifFalse:[
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3340
		"there are still pending timeouts"
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3341
		anyTimeouts := true.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3342
		indexOfLastTimeout := index.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3343
	    ]
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3344
	]
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  3345
    ].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  3346
16231
88589c89be48 class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16210
diff changeset
  3347
    "shrink the arrays, if they are 50% free"
15657
ffad68df93ca class: ProcessorScheduler
Claus Gittinger <cg@exept.de>
parents: 15634
diff changeset
  3348
    n > 20 ifTrue:[
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3349
	halfSize := n // 2.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3350
	(indexOfLastTimeout ~~ 0 and:[indexOfLastTimeout < halfSize]) ifTrue:[
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3351
	    timeoutArray := timeoutArray copyTo:halfSize.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3352
	    timeoutSemaphoreArray := timeoutSemaphoreArray copyTo:halfSize.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3353
	    timeoutActionArray := timeoutActionArray copyTo:halfSize.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3354
	    timeoutProcessArray := timeoutProcessArray copyTo:halfSize.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3355
	].
15657
ffad68df93ca class: ProcessorScheduler
Claus Gittinger <cg@exept.de>
parents: 15634
diff changeset
  3356
    ].
ffad68df93ca class: ProcessorScheduler
Claus Gittinger <cg@exept.de>
parents: 15634
diff changeset
  3357
19850
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  3358
    "/ 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
  3359
    "/ above code avoided the creation of an OrderedCollection
16210
3f0d3162e40b class: ProcessorScheduler
Claus Gittinger <cg@exept.de>
parents: 16206
diff changeset
  3360
    blocksAndProcessesToEvaluate isNil ifTrue:[
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3361
	firstBlockToEvaluate notNil ifTrue:[
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3362
	    timedActionCounter := (timedActionCounter + 1) bitAnd:SmallInteger maxVal.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3363
	    (firstProcess isNil or:[firstProcess == scheduler or:[PureEventDriven]]) ifTrue:[
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3364
		firstBlockToEvaluate value.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3365
%{
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3366
		if (__immediateInterrupt__) {
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3367
		    /* should never happen */
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3368
		    console_fprintf(stderr, "VM [warning]: immediateInterrupt is enabled after timeout block\n");
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3369
		    // __debugBreakPoint__();
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3370
		    // __dumpObject__(firstBlockToEvaluate, __LINE__,__FILE__);
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3371
		    __immediateInterrupt__ = 0;
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3372
		}
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3373
%}.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3374
	    ] ifFalse:[
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3375
		firstProcess isDead ifTrue:[
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3376
		    "/ a timedBlock for a process which has already terminated
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3377
		    "/ issue a warning and do not execute it.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3378
		    "/ (executing here may be dangerous, since it would run at scheduler priority here,
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3379
		    "/  and thereby could block the whole smalltalk system.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3380
		    "/  For this reason is it IGNORED here.)
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3381
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3382
		    "/ Could handle it in timeoutProcess, but we don't,
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3383
		    "/ because otherwise timeouts might be reissued forever...
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3384
		    "/      (timeoutHandlerProcess notNil and:[timeoutHandlerProcess isDead not]) ifTrue:[
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3385
		    "/          timeoutHandlerProcess interruptWith:block.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3386
		    "/      ] ifFalse:[
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3387
		    Smalltalk isDebuggableApp ifTrue:[
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3388
			"Do not bother customers with information for Developers"
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3389
			Logger warning:'Processor: cannot evaluate timedBlock (%1) for dead process: ''%2'''
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3390
			       with:firstBlockToEvaluate with:firstProcess name.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3391
		    ].
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3392
		    "/      ].
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3393
		] ifFalse:[
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3394
		    firstProcess interruptWith:firstBlockToEvaluate
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3395
		]
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3396
	    ]
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3397
	].
16210
3f0d3162e40b class: ProcessorScheduler
Claus Gittinger <cg@exept.de>
parents: 16206
diff changeset
  3398
    ] ifFalse:[
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3399
	n := blocksAndProcessesToEvaluate size.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3400
	1 to:n by:2 do:[:index |
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3401
	    block := blocksAndProcessesToEvaluate at:index.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3402
	    process := blocksAndProcessesToEvaluate at:index+1.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3403
	    (process isNil or:[process == scheduler or:[PureEventDriven]]) ifTrue:[
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3404
		block value.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3405
%{
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3406
		if (__immediateInterrupt__) {
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3407
		    /* should never happen */
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3408
		    console_fprintf(stderr, "VM [warning]: immediateInterrupt is enabled after timeout block\n");
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3409
		    // __debugBreakPoint__();
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3410
		    // __dumpObject__(block, __LINE__,__FILE__);
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3411
		    __immediateInterrupt__ = 0;
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3412
		}
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3413
%}.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3414
		timedActionCounter := (timedActionCounter + 1) bitAnd:SmallInteger maxVal.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3415
	    ] ifFalse:[
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3416
		process isDead ifTrue:[
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3417
		    "/ a timedBlock for a process which has already terminated
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3418
		    "/ issue a warning and do not execute it.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3419
		    "/ (executing here may be dangerous, since it would run at scheduler priority here,
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3420
		    "/  and thereby could block the whole smalltalk system.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3421
		    "/  For this reason is it IGNORED here.)
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3423
		    "/ Could handle it in timeoutProcess, but we don't,
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3424
		    "/ because otherwise timeouts might be reissued forever...
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3425
		    "/      (timeoutHandlerProcess notNil and:[timeoutHandlerProcess isDead not]) ifTrue:[
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3426
		    "/          timeoutHandlerProcess interruptWith:block.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3427
		    "/      ] ifFalse:[
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3428
		    Smalltalk isDebuggableApp ifTrue:[
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3429
			"Do not bother customers with information for Developers"
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3430
			Logger warning:'Processor: cannot evaluate timedBlock (%1) for dead process: ''%2'''
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3431
			       with:block printString with:process name.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3432
		    ].
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3433
		    "/      ].
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3434
		] ifFalse:[
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3435
		    timedActionCounter := (timedActionCounter + 1) bitAnd:SmallInteger maxVal.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3436
		    process interruptWith:block
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3437
		]
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3438
	    ]
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3439
	]
16210
3f0d3162e40b class: ProcessorScheduler
Claus Gittinger <cg@exept.de>
parents: 16206
diff changeset
  3440
    ].
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3441
    wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3442
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3443
    "Modified: / 03-05-2018 / 17:09:01 / stefan"
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3444
    "Modified: / 15-05-2020 / 14:13:37 / Stefan Vogel"
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3445
    "Modified: / 20-06-2020 / 00:05:19 / cg"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  3446
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  3447
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  3448
removeTimedBlock:aBlock
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3449
    "remove the argument, aBlock from the list of time-scheduled blocks.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3450
     If aBlock is not found in the list, no error is raised."
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  3451
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  3452
    |index "{ Class: SmallInteger }"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  3453
     wasBlocked|
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  3454
3916
cec84c84864c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3862
diff changeset
  3455
    aBlock isNil ifTrue:[^ self].
cec84c84864c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3862
diff changeset
  3456
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  3457
    wasBlocked := OperatingSystem blockInterrupts.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  3458
    index := timeoutActionArray identityIndexOf:aBlock startingAt:1.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  3459
    (index ~~ 0) ifTrue:[
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  3460
	timeoutArray at:index put:nil.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  3461
	timeoutActionArray at:index put:nil.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  3462
	timeoutSemaphoreArray at:index put:nil.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  3463
	timeoutProcessArray at:index put:nil.
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  3464
    ].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  3465
    wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3466
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3467
    "Modified (comment): / 08-02-2018 / 16:47:48 / stefan"
1676
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  3468
!
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  3469
20052
4bd27ae52593 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19859
diff changeset
  3470
removeTimeoutForSemaphore:aSemaphore
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3471
    "remove all the timeOuts that signals aSemaphore
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3472
     from the list of time-scheduled actions.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3473
     If aSemaphore is not found in the list, no error is raised."
20052
4bd27ae52593 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19859
diff changeset
  3474
4bd27ae52593 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19859
diff changeset
  3475
    |index "{ Class: SmallInteger }"
4bd27ae52593 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19859
diff changeset
  3476
     wasBlocked|
4bd27ae52593 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19859
diff changeset
  3477
4bd27ae52593 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19859
diff changeset
  3478
    wasBlocked := OperatingSystem blockInterrupts.
4bd27ae52593 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19859
diff changeset
  3479
4bd27ae52593 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19859
diff changeset
  3480
    index := 0.
20736
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  3481
    [
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3482
	index := timeoutSemaphoreArray identityIndexOf:aSemaphore startingAt:index+1.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3483
	index ~~ 0
20736
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  3484
    ] whileTrue:[
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3485
	timeoutArray at:index put:nil.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3486
	timeoutSemaphoreArray at:index put:nil.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3487
	timeoutActionArray at:index put:nil.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3488
	timeoutProcessArray at:index put:nil.
20052
4bd27ae52593 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19859
diff changeset
  3489
    ].
4bd27ae52593 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19859
diff changeset
  3490
4bd27ae52593 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19859
diff changeset
  3491
    wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3492
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3493
    "Modified (comment): / 08-02-2018 / 16:47:27 / stefan"
20052
4bd27ae52593 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19859
diff changeset
  3494
!
4bd27ae52593 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19859
diff changeset
  3495
1680
b90690d9d6c5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1679
diff changeset
  3496
removeTimeoutWithID:anID
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3497
    <resource: #obsolete>
1676
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  3498
    "remove the timeOut with anID (as returned by #addTimedBlock)
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3499
     from the list of time-scheduled-blocks.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3500
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3501
     DANGER: do not use.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3502
	     Use #removeTimedBlock: or or #removeTimeoutForSemaphore: or #removeTimeoutWithID:object: instead, which are safe.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3503
	     If you keep an outdated timeoutID and remove it later,
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3504
	     the wrong timeout which re-uses the same id may be removed!!"
1676
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  3505
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  3506
    |index "{ Class: SmallInteger }"
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  3507
     wasBlocked|
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  3508
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  3509
    index := anID.
1680
b90690d9d6c5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1679
diff changeset
  3510
    (index > 0) ifTrue:[
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  3511
	wasBlocked := OperatingSystem blockInterrupts.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  3512
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  3513
	timeoutArray at:index put:nil.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  3514
	timeoutActionArray at:index put:nil.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  3515
	timeoutSemaphoreArray at:index put:nil.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  3516
	timeoutProcessArray at:index put:nil.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  3517
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  3518
	wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
1680
b90690d9d6c5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1679
diff changeset
  3519
    ]
1676
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  3520
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3521
    "Created: / 23-09-1996 / 14:32:33 / cg"
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3522
    "Modified (comment): / 08-02-2018 / 16:51:56 / stefan"
9437
432a4a06934f + timeoutHandlerProcess
ca
parents: 9295
diff changeset
  3523
!
432a4a06934f + timeoutHandlerProcess
ca
parents: 9295
diff changeset
  3524
18774
a262834431c7 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18673
diff changeset
  3525
removeTimeoutWithID:anID object:aBlockOrSemaphore
a262834431c7 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18673
diff changeset
  3526
    "remove the timeOut with anID (as returned by #addTimedBlock)
a262834431c7 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18673
diff changeset
  3527
     from the list of time-scheduled-blocks.
a262834431c7 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18673
diff changeset
  3528
     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
  3529
     or for the semphore."
a262834431c7 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18673
diff changeset
  3530
a262834431c7 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18673
diff changeset
  3531
    |index "{ Class: SmallInteger }"
a262834431c7 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18673
diff changeset
  3532
     wasBlocked|
a262834431c7 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18673
diff changeset
  3533
a262834431c7 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18673
diff changeset
  3534
    index := anID.
18776
b068b9fe6667 Fix last change
Stefan Vogel <sv@exept.de>
parents: 18775
diff changeset
  3535
    (anID notNil and:[index > 0]) ifTrue:[
19850
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  3536
	wasBlocked := OperatingSystem blockInterrupts.
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  3537
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  3538
	(aBlockOrSemaphore notNil
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  3539
	  and:[(timeoutActionArray at:index ifAbsent:[]) ~~ aBlockOrSemaphore
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  3540
	  and:[(timeoutSemaphoreArray at:index ifAbsent:[]) ~~ aBlockOrSemaphore]]) ifTrue:[
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3541
	    Logger warning:'Processor: trying to remove stale timeout id - ignored'.
19850
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  3542
	] ifFalse:[
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  3543
	    timeoutArray at:index put:nil.
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  3544
	    timeoutActionArray at:index put:nil.
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  3545
	    timeoutSemaphoreArray at:index put:nil.
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  3546
	    timeoutProcessArray at:index put:nil.
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  3547
	].
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  3548
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  3549
	wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
18774
a262834431c7 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18673
diff changeset
  3550
    ]
a262834431c7 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18673
diff changeset
  3551
!
a262834431c7 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18673
diff changeset
  3552
9437
432a4a06934f + timeoutHandlerProcess
ca
parents: 9295
diff changeset
  3553
timeoutHandlerProcess
9452
921f2690dfe6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9450
diff changeset
  3554
    (timeoutHandlerProcess isNil or:[timeoutHandlerProcess isDead]) ifTrue:[
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  3555
	timeoutHandlerProcess :=
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  3556
		[
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  3557
		    [
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  3558
			self timeoutHandlerProcessLoop.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  3559
		    ] ensure:[
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  3560
			timeoutHandlerProcess := nil
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  3561
		    ].
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  3562
		] newProcess.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  3563
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  3564
	timeoutHandlerProcess
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  3565
	    priority:TimingPriority;
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3566
	    name:'System: timeout handler';
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  3567
	    beSystemProcess;
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  3568
	    resume.
9437
432a4a06934f + timeoutHandlerProcess
ca
parents: 9295
diff changeset
  3569
    ].
432a4a06934f + timeoutHandlerProcess
ca
parents: 9295
diff changeset
  3570
    ^ timeoutHandlerProcess.
9450
cc3954feef43 timeoutHandler clearing
Claus Gittinger <cg@exept.de>
parents: 9437
diff changeset
  3571
9452
921f2690dfe6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9450
diff changeset
  3572
    "Modified: / 20-07-2006 / 09:52:27 / cg"
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3573
    "Modified: / 15-08-2018 / 15:03:40 / Claus Gittinger"
9437
432a4a06934f + timeoutHandlerProcess
ca
parents: 9295
diff changeset
  3574
!
432a4a06934f + timeoutHandlerProcess
ca
parents: 9295
diff changeset
  3575
432a4a06934f + timeoutHandlerProcess
ca
parents: 9295
diff changeset
  3576
timeoutHandlerProcessLoop
10489
e55d1a27d02b Mark timeoutHandlerProcess as system process
Stefan Vogel <sv@exept.de>
parents: 10435
diff changeset
  3577
    "The timeoutHandlerProcess does nothing but wait.
19850
c30c21be7440 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19083
diff changeset
  3578
     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
  3579
     (i.e. it will always just wait forever, and perform timeout actions
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3580
      for others in its interrupt handler)."
14775
fa2e7d4afdef class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 14771
diff changeset
  3581
20887
65afdf8260e3 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 20884
diff changeset
  3582
    |mySema|
65afdf8260e3 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 20884
diff changeset
  3583
65afdf8260e3 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 20884
diff changeset
  3584
    mySema := Semaphore new name:'timeoutHandler'.
16538
1a94d96f14d9 class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16514
diff changeset
  3585
    [
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3586
	[
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3587
	    mySema wait.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3588
	] on:Exception do:[:ex|
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3589
	    "/ an error occurred in one of the timeout actions.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3590
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3591
	    "ignore errors, but tell the user"
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3592
	    InfoPrinting == true ifTrue:[
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3593
		Logger warning:'Processor: error while handling timeouts in TimeoutHandlerProcess: ''%1''' with:ex description.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3594
		thisContext fullPrintAll.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3595
	    ].
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3596
	].
16538
1a94d96f14d9 class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16514
diff changeset
  3597
    ] loop.
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3598
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3599
    "Modified (comment): / 23-02-2019 / 09:18:28 / Claus Gittinger"
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3600
!
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3601
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3602
timeoutList
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3603
    "return (a copy of) the list of current timeouts; only for debugging (i.e. for the monitor).
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3604
     The info is a pair where the first element is the current time (in OS-milliseconds)
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3605
     and the second element is a collection of timeouts which are valid at this time."
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3606
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3607
    |info wasBlocked now|
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3608
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3609
    wasBlocked := OperatingSystem blockInterrupts.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3610
    now := OperatingSystem getMillisecondTime.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3611
    info := OrderedCollection new.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3612
    1 to:timeoutActionArray size do:[:i |
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3613
	|time|
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3614
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3615
	time := timeoutArray at:i.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3616
	time notNil ifTrue:[
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3617
	    info add:((SmallDictionary new:4)
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3618
		at:'time' put:time;
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3619
		at:'action' put:(timeoutActionArray at:i);
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3620
		at:'sema' put:(timeoutSemaphoreArray at:i);
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3621
		at:'process' put:(timeoutProcessArray at:i);
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3622
		yourself)
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3623
	]
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3624
    ].
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3625
    wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3626
    ^ { now . info }
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3627
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3628
    "
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3629
     Processor timeoutList
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3630
    "
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3631
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3632
    "Modified: / 05-02-2020 / 15:31:39 / Stefan Vogel"
10
claus
parents: 3
diff changeset
  3633
! !
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3634
6619
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
  3635
!ProcessorScheduler methodsFor:'wait hooks'!
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
  3636
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
  3637
addPreWaitAction:aBlock
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
  3638
    "add the argument, aBlock to the list of preWait-actions.
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
  3639
     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
  3640
     (i.e. the OS-wait for next event or timeout).
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
  3641
     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
  3642
     to force unflushed output to be sent out in regular intervals)"
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
  3643
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
  3644
    |wasBlocked|
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
  3645
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
  3646
    wasBlocked := OperatingSystem blockInterrupts.
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
  3647
    preWaitActions isNil ifTrue:[
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  3648
	preWaitActions := OrderedCollection new
6619
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
  3649
    ].
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
  3650
    preWaitActions add:aBlock.
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
  3651
    wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
  3652
!
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
  3653
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
  3654
removePreWaitAction:aBlock
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
  3655
    "remove the argument, aBlock from the list of preWait-actions."
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
  3656
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
  3657
    |wasBlocked|
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
  3658
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
  3659
    wasBlocked := OperatingSystem blockInterrupts.
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
  3660
    preWaitActions notNil ifTrue:[
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
  3661
       preWaitActions removeIdentical:aBlock ifAbsent:nil
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
  3662
    ].
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
  3663
    wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
  3664
! !
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
  3665
10
claus
parents: 3
diff changeset
  3666
!ProcessorScheduler methodsFor:'waiting'!
claus
parents: 3
diff changeset
  3667
20722
0eeb9a61979f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20713
diff changeset
  3668
checkForEndOfDispatch
20736
56ec188751e7 #UI_ENHANCEMENT by cg
Claus Gittinger <cg@exept.de>
parents: 20726
diff changeset
  3669
    |wasBlocked|
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3670
20722
0eeb9a61979f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20713
diff changeset
  3671
    exitWhenNoMoreUserProcesses ifTrue:[
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3672
	"/ check if there are any processes at all
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3673
	"/ stop dispatching if there is none
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3674
	"/ (and anyTimeouts is false, which means that no timeout blocks are present)
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3675
	"/ and no readSemaphores are present (which means that noone is waiting for input)
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3676
	"/ and no writeSemaphores are present
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3677
	wasBlocked := OperatingSystem blockInterrupts.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3678
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3679
	"/ 'scheduled: ' _errorPrint. self anyScheduledWindowGroupAtAll asString _errorPrintCR.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3680
	"/ 'anyUserProcess: ' _errorPrint. self anyUserProcessAtAll asString _errorPrintCR.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3681
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3682
	self anyScheduledWindowGroupAtAll ifFalse:[
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3683
	    self anyUserProcessAtAll ifFalse:[
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3684
		Smalltalk verbose ifTrue:[
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3685
		    Logger info:'Processor: end of dispatch'.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3686
		].
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3687
		dispatching := false.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3688
"/                MiniInspector basicNew printInstVarsOf:self.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3689
"/                quiescentProcessLists infoPrintCR.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3690
"/                MiniDebugger enter:thisContext withMessage:'about to exit' mayProceed:true.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3691
	    ].
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3692
	].
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3693
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3694
	wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
20722
0eeb9a61979f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20713
diff changeset
  3695
    ].
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3696
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3697
    "Modified: / 01-08-2017 / 17:16:54 / stefan"
20722
0eeb9a61979f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20713
diff changeset
  3698
!
0eeb9a61979f #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 20713
diff changeset
  3699
7510
46a848d466b5 select: wake up readFDs if readable only;
Claus Gittinger <cg@exept.de>
parents: 7495
diff changeset
  3700
checkForIOWithTimeout:millis
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  3701
    "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
  3702
     hard wait for either input to arrive, or output to be possible
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3703
     or a timeout to occur.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3704
     Answer true, if processes have possibly been woken uo, false otherwise."
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3705
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3706
    |nReady index sema actionBlock wasBlocked err fd readyIndex
18957
e0bb91eae748 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18941
diff changeset
  3707
     newProcessMaybeReady fdOrPid exceptArray|
2116
1bcb6ee86fca fixed pending sigChild problem;
Claus Gittinger <cg@exept.de>
parents: 2111
diff changeset
  3708
7493
5c67c45b11cb New select for fair scheduling (not giving low filedescriptors
Stefan Vogel <sv@exept.de>
parents: 7264
diff changeset
  3709
    newProcessMaybeReady := false.
14943
141d20b16378 class: ProcessorScheduler
Claus Gittinger <cg@exept.de>
parents: 14780
diff changeset
  3710
    readableResultFdArray size < readFdArray size ifTrue:[
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3711
	readableResultFdArray := Array new:(40 max:readFdArray size).
14943
141d20b16378 class: ProcessorScheduler
Claus Gittinger <cg@exept.de>
parents: 14780
diff changeset
  3712
    ].
141d20b16378 class: ProcessorScheduler
Claus Gittinger <cg@exept.de>
parents: 14780
diff changeset
  3713
    writableResultFdArray size < writeFdArray size ifTrue:[
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3714
	writableResultFdArray := Array new:(40 max:writeFdArray size).
14943
141d20b16378 class: ProcessorScheduler
Claus Gittinger <cg@exept.de>
parents: 14780
diff changeset
  3715
    ].
7510
46a848d466b5 select: wake up readFDs if readable only;
Claus Gittinger <cg@exept.de>
parents: 7495
diff changeset
  3716
18957
e0bb91eae748 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18941
diff changeset
  3717
    exceptArray := exceptFdArray.
e0bb91eae748 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18941
diff changeset
  3718
16858
39f5a709a6ff class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16857
diff changeset
  3719
    OperatingSystem isMSWINDOWSlike ifTrue:[
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3720
	"/ This code checks for OS subprocess termination.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3721
	"/ Only in Win32 - via a WaitForMultipleObjects in select...
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3722
	"/ Unix waits for SIGCHLD instead.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3723
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3724
	|hasPids|
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3725
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3726
	hasPids := false.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3727
	osChildExitActions keysDo:[:eachPid|
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3728
	    eachPid address = 0 ifTrue:[
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3729
		Logger warning:'Processor: remove 0-handle pid: %1' with:eachPid.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3730
		osChildExitActions safeRemoveKey:eachPid.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3731
	    ] ifFalse:[
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3732
		hasPids := true.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3733
	    ].
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3734
	].
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3735
	hasPids ifTrue:[
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3736
	    exceptArray := (exceptArray upTo:nil), osChildExitActions keys asArray.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3737
	    "/'exceptArray: ' print. exceptArray printCR.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3738
	].
16338
b8defcce7efc class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16322
diff changeset
  3739
    ].
b8defcce7efc class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16322
diff changeset
  3740
18957
e0bb91eae748 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18941
diff changeset
  3741
    exceptResultFdArray size < exceptArray size ifTrue:[
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3742
	exceptResultFdArray := Array new:(40 max:exceptArray size).
18957
e0bb91eae748 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18941
diff changeset
  3743
    ].
e0bb91eae748 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18941
diff changeset
  3744
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3745
    "/ must enable interrupts, to be able to get out of a
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3746
    "/ long wait (especially, to handle sigChild in the meantime)
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3747
    wasBlocked := OperatingSystem unblockInterrupts.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3748
7510
46a848d466b5 select: wake up readFDs if readable only;
Claus Gittinger <cg@exept.de>
parents: 7495
diff changeset
  3749
    nReady := OperatingSystem
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3750
		selectOnAnyReadable:readFdArray
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3751
		writable:writeFdArray
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3752
		exception:exceptArray
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3753
		readableInto:readableResultFdArray
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3754
		writableInto:writableResultFdArray
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3755
		exceptionInto:exceptResultFdArray
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3756
		withTimeOut:millis.
1061
61012b7bed9c protect myself against invalid fd's in readFdArray/writeFdArray
Claus Gittinger <cg@exept.de>
parents: 1042
diff changeset
  3757
2116
1bcb6ee86fca fixed pending sigChild problem;
Claus Gittinger <cg@exept.de>
parents: 2111
diff changeset
  3758
    wasBlocked ifTrue:[
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3759
	OperatingSystem blockInterrupts.
2116
1bcb6ee86fca fixed pending sigChild problem;
Claus Gittinger <cg@exept.de>
parents: 2111
diff changeset
  3760
    ].
1bcb6ee86fca fixed pending sigChild problem;
Claus Gittinger <cg@exept.de>
parents: 2111
diff changeset
  3761
11836
0d70352a70bc Avoid blocking in PipeStream (e.g. when doing a CVS checkin)
Stefan Vogel <sv@exept.de>
parents: 11622
diff changeset
  3762
    nReady <= 0 ifTrue:[
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3763
	"/ either still nothing to do,
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3764
	"/ or error (which should not happen)
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3765
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3766
	(nReady ~~ 0 and:[(err := OperatingSystem lastErrorSymbol) notNil]) ifTrue:[
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3767
	    err == #EBADF ifTrue:[
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3768
		"/ mhmh - one of the fd's given to me is corrupt.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3769
		"/ find out which one .... and remove it
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3770
		self removeCorruptedFds
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3771
	    ] ifFalse:[
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3772
		err == #ENOENT ifTrue:[
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3773
		    Logger warning:'Processor: ENOENT in select; rd=%1 wr=%2' with:readFdArray with:writeFdArray.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3774
		] ifFalse:[
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3775
		    Logger warning:'Processor: error in select: %1' with:err.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3776
		]
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3777
	    ].
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3778
	].
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3779
	^ false.    "/ no process woke up
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3780
    ].
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3781
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3782
    readyIndex := 1.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3783
    [nReady > 0
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3784
     and:[readyIndex <= readableResultFdArray size
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3785
     and:[(fd := readableResultFdArray at:readyIndex) notNil]]
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3786
    ] whileTrue:[
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3787
	index := readFdArray identityIndexOf:fd.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3788
	index ~~ 0 ifTrue:[
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3789
	    actionBlock := readCheckArray at:index.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3790
	    sema := readSemaphoreArray at:index.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3791
	    sema notNil ifTrue:[
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3792
		sema signalOnce.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3793
		newProcessMaybeReady := true.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3794
		actionBlock isNil ifTrue:[
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3795
		    "before May 2014 we disabled the sema in the caller after wakeup.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3796
		     This caused ST/X to consume 100% cpu, when the caller didn't read
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3797
		     the data (e.g. because his process was stopped)."
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3798
		    "disable possible write side and timeouts as well"
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3799
		    self disableSemaphore:sema.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3800
		].
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3801
	    ].
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3802
	    (actionBlock notNil and:[actionBlock value]) ifTrue:[
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3803
		newProcessMaybeReady := true.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3804
	    ].
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3805
	].
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3806
	nReady := nReady - 1.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3807
	readyIndex := readyIndex + 1.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3808
    ].
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3809
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3810
    readyIndex := 1.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3811
    [nReady > 0
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3812
      and:[ readyIndex <= writableResultFdArray size
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3813
      and:[ (fd := writableResultFdArray at:readyIndex) notNil ]]
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3814
    ] whileTrue:[
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3815
	index := writeFdArray identityIndexOf:fd.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3816
	index ~~ 0 ifTrue:[
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3817
	    actionBlock := writeCheckArray at:index.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3818
	    sema := writeSemaphoreArray at:index.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3819
	    sema notNil ifTrue:[
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3820
		sema signalOnce.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3821
		newProcessMaybeReady := true.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3822
		actionBlock isNil ifTrue:[
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3823
		    "now this is a one shot operation - see the input above"
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3824
		    "disable possible read side and timeouts as well"
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3825
		    self disableSemaphore:sema.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3826
		].
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3827
	    ].
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3828
	    (actionBlock notNil and:[actionBlock value]) ifTrue:[
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3829
		newProcessMaybeReady := true.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3830
	    ].
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3831
	].
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3832
	nReady := nReady - 1.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3833
	readyIndex := readyIndex + 1.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3834
    ].
18957
e0bb91eae748 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18941
diff changeset
  3835
e0bb91eae748 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18941
diff changeset
  3836
"/'except result got: ' print. exceptArray printCR. exceptResultFdArray printCR.
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3837
    readyIndex := 1.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3838
    [nReady > 0
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3839
     and:[ readyIndex <= exceptResultFdArray size
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3840
     and:[ (fdOrPid := exceptResultFdArray at:readyIndex) notNil ]]
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3841
    ] whileTrue:[
18957
e0bb91eae748 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18941
diff changeset
  3842
"/'except got: ' print. fdOrPid printCR.
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3843
	index := exceptFdArray identityIndexOf:fdOrPid.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3844
	index ~~ 0 ifTrue:[
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3845
	    "fdOrPid is a filedescriptor"
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3846
	    sema := exceptSemaphoreArray at:index.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3847
	    sema notNil ifTrue:[
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3848
		sema signalOnce.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3849
		newProcessMaybeReady := true.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3850
		"disable possible read/write side and timeouts as well"
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3851
		self disableSemaphore:sema.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3852
	    ].
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3853
	] ifFalse:[
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3854
	    "fdOrPid is probably a pid"
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3855
	    actionBlock := osChildExitActions removeKey:fdOrPid ifAbsent:nil.
18957
e0bb91eae748 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18941
diff changeset
  3856
"/'pid signaled: ' print. fdOrPid printCR.
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3857
	    actionBlock notNil ifTrue:[
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3858
		|osProcessStatus|
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3859
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3860
		osProcessStatus := OperatingSystem childProcessWait:false pid:fdOrPid.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3861
		(osProcessStatus notNil and:[osProcessStatus pid = fdOrPid]) ifTrue:[
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3862
		    actionBlock value:osProcessStatus.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3863
		    newProcessMaybeReady := true.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3864
		].
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3865
	    ].
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3866
	].
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3867
	nReady := nReady - 1.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3868
	readyIndex := readyIndex + 1.
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  3869
    ].
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3870
7493
5c67c45b11cb New select for fair scheduling (not giving low filedescriptors
Stefan Vogel <sv@exept.de>
parents: 7264
diff changeset
  3871
    ^ 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
  3872
10233
4006fa954217 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9991
diff changeset
  3873
    "Modified: / 12-04-1996 / 09:31:22 / stefan"
10269
c9eae9f888c7 changed #checkForIOWithTimeout:
Claus Gittinger <cg@exept.de>
parents: 10268
diff changeset
  3874
    "Modified: / 07-12-2006 / 19:48:17 / cg"
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3875
    "Modified (comment): / 20-05-2020 / 18:16:25 / Stefan Vogel"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  3876
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  3877
10
claus
parents: 3
diff changeset
  3878
ioInterrupt
1787
32632b6f969d remember threadSwitch:from: idea for later implementation;
Claus Gittinger <cg@exept.de>
parents: 1783
diff changeset
  3879
    "{ Pragma: +returnable }"
32632b6f969d remember threadSwitch:from: idea for later implementation;
Claus Gittinger <cg@exept.de>
parents: 1783
diff changeset
  3880
10747
e9ea71d01445 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10497
diff changeset
  3881
    "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
  3882
     what to do now.
be7402f74d94 hide timerInterrupt & ioInterrupt contexts when switching
Claus Gittinger <cg@exept.de>
parents: 1780
diff changeset
  3883
     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
  3884
     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
  3885
     of whichever process is currently running."
10
claus
parents: 3
diff changeset
  3886
804
264d440a67a0 Fixes when useIOInterrupts == true.
Stefan Vogel <sv@exept.de>
parents: 786
diff changeset
  3887
    gotIOInterrupt := true.
2966
856dfc8a294a lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2962
diff changeset
  3888
    activeProcess ~~ scheduler ifTrue:[
20706
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  3889
	interruptCounter := interruptCounter + 1 bitAnd:SmallInteger maxVal.
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  3890
	interruptedProcess := activeProcess.
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  3891
	self threadSwitch:scheduler
2966
856dfc8a294a lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2962
diff changeset
  3892
    ]
804
264d440a67a0 Fixes when useIOInterrupts == true.
Stefan Vogel <sv@exept.de>
parents: 786
diff changeset
  3893
264d440a67a0 Fixes when useIOInterrupts == true.
Stefan Vogel <sv@exept.de>
parents: 786
diff changeset
  3894
    "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
  3895
    "Modified: 4.8.1997 / 14:23:08 / cg"
10
claus
parents: 3
diff changeset
  3896
!
claus
parents: 3
diff changeset
  3897
1086
7b0641a2e1ef nicer message
Claus Gittinger <cg@exept.de>
parents: 1061
diff changeset
  3898
removeCorruptedFds
10747
e9ea71d01445 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10497
diff changeset
  3899
    "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
  3900
     fileDescriptor. May happen, if someone does a readWait/writeWait on a
e9ea71d01445 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10497
diff changeset
  3901
     socket connection, which somehow got corrupted
2280
aca71c89f32c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2269
diff changeset
  3902
     (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
  3903
     Without special care, all following selects would immediately return with
1086
7b0641a2e1ef nicer message
Claus Gittinger <cg@exept.de>
parents: 1061
diff changeset
  3904
     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
  3905
     (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
  3906
      readFdArray/writeFdArray in the debugger)"
7b0641a2e1ef nicer message
Claus Gittinger <cg@exept.de>
parents: 1061
diff changeset
  3907
7b0641a2e1ef nicer message
Claus Gittinger <cg@exept.de>
parents: 1061
diff changeset
  3908
    readFdArray keysAndValuesDo:[:idx :fd |
20706
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  3909
	|result sema|
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  3910
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  3911
	fd notNil ifTrue:[
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  3912
	    result := OperatingSystem
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  3913
			selectOnAnyReadable:(Array with:fd) writable:nil exception:nil
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  3914
			   readableInto:nil writableInto:nil exceptionInto:nil
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  3915
			   withTimeOut:0.
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  3916
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  3917
	    result < 0 ifTrue:[
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3918
		Logger info:'Processor: removing invalid read-select fileDescriptor: %1 idx: %2' with:fd with:idx.
20706
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  3919
		readFdArray at:idx put:nil.
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  3920
		readCheckArray at:idx put:nil.
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  3921
		(sema := readSemaphoreArray at:idx) notNil ifTrue:[
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  3922
		    readSemaphoreArray at:idx put:nil.
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  3923
		    self removeTimeoutForSemaphore:sema.
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  3924
		    sema signalForAll.
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  3925
		].
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  3926
	    ]
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  3927
	].
1086
7b0641a2e1ef nicer message
Claus Gittinger <cg@exept.de>
parents: 1061
diff changeset
  3928
    ].
7b0641a2e1ef nicer message
Claus Gittinger <cg@exept.de>
parents: 1061
diff changeset
  3929
7b0641a2e1ef nicer message
Claus Gittinger <cg@exept.de>
parents: 1061
diff changeset
  3930
    writeFdArray keysAndValuesDo:[:idx :fd |
20706
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  3931
	|result sema|
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  3932
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  3933
	fd notNil ifTrue:[
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  3934
	    result := OperatingSystem
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  3935
			selectOnAnyReadable:nil writable:(Array with:fd) exception:nil
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  3936
			   readableInto:nil writableInto:nil exceptionInto:nil
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  3937
			   withTimeOut:0.
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  3938
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  3939
	    result < 0 ifTrue:[
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3940
		Logger info:'Processor: removing invalid write-select fileDescriptor: %1 idx: %2' with:fd with:idx.
20706
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  3941
		writeFdArray at:idx put:nil.
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  3942
		writeCheckArray at:idx put:nil.
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  3943
		(sema := writeSemaphoreArray at:idx) notNil ifTrue:[
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  3944
		    writeSemaphoreArray at:idx put:nil.
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  3945
		    self removeTimeoutForSemaphore:sema.
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  3946
		    sema signalForAll.
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  3947
		].
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  3948
	    ]
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  3949
	]
1086
7b0641a2e1ef nicer message
Claus Gittinger <cg@exept.de>
parents: 1061
diff changeset
  3950
    ].
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
  3951
18957
e0bb91eae748 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18941
diff changeset
  3952
    exceptFdArray keysAndValuesDo:[:idx :fd |
20706
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  3953
	|result sema|
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  3954
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  3955
	fd notNil ifTrue:[
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  3956
	    result := OperatingSystem
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  3957
			selectOnAnyReadable:nil writable:nil exception:(Array with:fd)
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  3958
			   readableInto:nil writableInto:nil exceptionInto:nil
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  3959
			   withTimeOut:0.
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  3960
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  3961
	    result < 0 ifTrue:[
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3962
		Logger info:'Processor: removing invalid exception-select fileDescriptor: %1 idx: %2' with:fd with:idx.
20706
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  3963
		exceptFdArray at:idx put:nil.
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  3964
		(sema := exceptSemaphoreArray at:idx) notNil ifTrue:[
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  3965
		    exceptSemaphoreArray at:idx put:nil.
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  3966
		    self removeTimeoutForSemaphore:sema.
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  3967
		    sema signalForAll.
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  3968
		].
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  3969
	    ]
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  3970
	]
18957
e0bb91eae748 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18941
diff changeset
  3971
    ].
e0bb91eae748 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18941
diff changeset
  3972
e0bb91eae748 #FEATURE
Stefan Vogel <sv@exept.de>
parents: 18941
diff changeset
  3973
16858
39f5a709a6ff class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16857
diff changeset
  3974
    OperatingSystem isMSWINDOWSlike ifTrue:[
20706
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  3975
	"/
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  3976
	"/ win32 does a WaitForMultipleObjects in select...
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  3977
	"/ unix waits for SIGCHLD
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  3978
	"/
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  3979
	osChildExitActions keysDo:[:eachPid |
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3980
	    |result|
20706
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  3981
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  3982
	    eachPid notNil ifTrue:[
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  3983
		result := OperatingSystem
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  3984
			    selectOnAnyReadable:nil writable:nil exception:(Array with:eachPid)
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  3985
			       readableInto:nil writableInto:nil exceptionInto:nil
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  3986
			       withTimeOut:0.
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  3987
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  3988
		result < 0 ifTrue:[
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3989
		    Logger info:'Processor: removing invalid exception-select pid: %1' with:eachPid.
20706
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  3990
		    osChildExitActions safeRemoveKey:eachPid.
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  3991
		]
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  3992
	    ]
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  3993
	].
16338
b8defcce7efc class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16322
diff changeset
  3994
    ].
b8defcce7efc class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 16322
diff changeset
  3995
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3996
    "Modified: / 12-04-1996 / 09:32:58 / stefan"
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3997
    "Modified: / 27-01-1997 / 20:09:27 / cg"
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  3998
    "Modified (format): / 05-02-2020 / 16:21:48 / Stefan Vogel"
1086
7b0641a2e1ef nicer message
Claus Gittinger <cg@exept.de>
parents: 1061
diff changeset
  3999
!
7b0641a2e1ef nicer message
Claus Gittinger <cg@exept.de>
parents: 1061
diff changeset
  4000
750
f4ed622893ce added schedulerInterrupt - for soon to come semaSignal primitive function
Claus Gittinger <cg@exept.de>
parents: 699
diff changeset
  4001
schedulerInterrupt
f4ed622893ce added schedulerInterrupt - for soon to come semaSignal primitive function
Claus Gittinger <cg@exept.de>
parents: 699
diff changeset
  4002
    "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
  4003
     what to do now."
f4ed622893ce added schedulerInterrupt - for soon to come semaSignal primitive function
Claus Gittinger <cg@exept.de>
parents: 699
diff changeset
  4004
2966
856dfc8a294a lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2962
diff changeset
  4005
    activeProcess ~~ scheduler ifTrue:[
20706
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  4006
	interruptCounter := interruptCounter + 1 bitAnd:SmallInteger maxVal.
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  4007
	interruptedProcess := activeProcess.
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  4008
	self threadSwitch:scheduler
2966
856dfc8a294a lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2962
diff changeset
  4009
    ]
750
f4ed622893ce added schedulerInterrupt - for soon to come semaSignal primitive function
Claus Gittinger <cg@exept.de>
parents: 699
diff changeset
  4010
!
f4ed622893ce added schedulerInterrupt - for soon to come semaSignal primitive function
Claus Gittinger <cg@exept.de>
parents: 699
diff changeset
  4011
10
claus
parents: 3
diff changeset
  4012
timeToNextTimeout
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  4013
    "return the positive delta-T (in milliseconds) to the next timeout,
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  4014
     or nil if there is none"
10
claus
parents: 3
diff changeset
  4015
231
fd0e55e352f8 cleanup
claus
parents: 217
diff changeset
  4016
    |aTime now delta minDelta n "{ Class: SmallInteger }"|
10
claus
parents: 3
diff changeset
  4017
claus
parents: 3
diff changeset
  4018
    "find next timeout. since there are usually not many, just search.
302
1f76060d58a4 *** empty log message ***
claus
parents: 271
diff changeset
  4019
     If there were many, the list should be kept sorted ... keeping deltas
10
claus
parents: 3
diff changeset
  4020
     to next (as in Unix kernel)"
claus
parents: 3
diff changeset
  4021
231
fd0e55e352f8 cleanup
claus
parents: 217
diff changeset
  4022
    n := timeoutArray size.
10
claus
parents: 3
diff changeset
  4023
    1 to:n do:[:index |
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  4024
	aTime := timeoutArray at:index.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  4025
	aTime notNil ifTrue:[
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  4026
	    now isNil ifTrue:[
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  4027
		now := OperatingSystem getMillisecondTime.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  4028
	    ].
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  4029
	    delta := OperatingSystem millisecondTimeDeltaBetween:aTime and:now.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  4030
	    delta <= 0 ifTrue:[
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  4031
		"timeout is due"
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  4032
		^ 0.
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  4033
	    ].
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  4034
	    minDelta isNil ifTrue:[
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  4035
		minDelta := delta
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  4036
	    ] ifFalse:[
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  4037
		minDelta := minDelta min:delta
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  4038
	    ]
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  4039
	]
15634
9ace007bd248 class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 15581
diff changeset
  4040
    ].
9ace007bd248 class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 15581
diff changeset
  4041
    minDelta isNil ifTrue:[
18295
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  4042
	"this is safe, since always called with interruptsBlocked"
17324d5bb9cc fixed max process id setup
Claus Gittinger <cg@exept.de>
parents: 17412
diff changeset
  4043
	anyTimeouts := false.
10
claus
parents: 3
diff changeset
  4044
    ].
claus
parents: 3
diff changeset
  4045
claus
parents: 3
diff changeset
  4046
    ^ minDelta
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  4047
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  4048
    "Modified (format): / 20-05-2020 / 17:27:04 / Stefan Vogel"
10
claus
parents: 3
diff changeset
  4049
!
claus
parents: 3
diff changeset
  4050
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  4051
timerInterrupt
1787
32632b6f969d remember threadSwitch:from: idea for later implementation;
Claus Gittinger <cg@exept.de>
parents: 1783
diff changeset
  4052
    "{ Pragma: +returnable }"
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  4053
    <resource: #skipInDebuggersWalkBack>
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  4054
1787
32632b6f969d remember threadSwitch:from: idea for later implementation;
Claus Gittinger <cg@exept.de>
parents: 1783
diff changeset
  4055
10747
e9ea71d01445 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10497
diff changeset
  4056
    "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
  4057
     what to do now.
be7402f74d94 hide timerInterrupt & ioInterrupt contexts when switching
Claus Gittinger <cg@exept.de>
parents: 1780
diff changeset
  4058
     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
  4059
     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
  4060
     of whichever process is currently running."
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  4061
2966
856dfc8a294a lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2962
diff changeset
  4062
    activeProcess ~~ scheduler ifTrue:[
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  4063
	"/ avoid largeIntegers
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  4064
	interruptCounter := (interruptCounter + 1) bitAnd:SmallInteger maxVal.
20706
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  4065
	interruptedProcess := activeProcess.
009b8269bd08 we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents: 20643
diff changeset
  4066
	self threadSwitch:scheduler
2966
856dfc8a294a lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2962
diff changeset
  4067
    ]
1783
be7402f74d94 hide timerInterrupt & ioInterrupt contexts when switching
Claus Gittinger <cg@exept.de>
parents: 1780
diff changeset
  4068
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  4069
    "Modified: / 18-10-1996 / 20:35:54 / cg"
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  4070
    "Modified: / 21-02-2019 / 10:06:11 / Claus Gittinger"
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  4071
    "Modified (format): / 22-02-2019 / 09:53:13 / Claus Gittinger"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  4072
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  4073
10
claus
parents: 3
diff changeset
  4074
waitForEventOrTimeout
44
b262907c93ea *** empty log message ***
claus
parents: 42
diff changeset
  4075
    "entered when no process is runnable - wait for either input on
b262907c93ea *** empty log message ***
claus
parents: 42
diff changeset
  4076
     any file descriptors to arrive or a timeout to happen.
b262907c93ea *** empty log message ***
claus
parents: 42
diff changeset
  4077
     If it makes sense, do some background garbage collection.
b262907c93ea *** empty log message ***
claus
parents: 42
diff changeset
  4078
     The idle actions are a leftover from previous ST/X releases and will
93
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
  4079
     vanish (installing a low-prio process has the same effect)."
44
b262907c93ea *** empty log message ***
claus
parents: 42
diff changeset
  4080
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  4081
    |millisToNextTimeout doingGC dT|
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  4082
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  4083
    [ "/... while
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  4084
	anyTimeouts ifTrue:[
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  4085
	    millisToNextTimeout := self timeToNextTimeout.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  4086
	    millisToNextTimeout == 0 ifTrue:[
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  4087
		^ self    "a timeout is due - hurry up checking"
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  4088
	    ].
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  4089
	].
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  4090
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  4091
	"
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  4092
	 if it's worth doing, collect a bit of garbage;
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  4093
	 but not, if a backgroundCollector is active
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  4094
	"
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  4095
	ObjectMemory backgroundCollectorRunning ifTrue:[
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  4096
	    doingGC := false
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  4097
	] ifFalse:[
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  4098
	    doingGC := ObjectMemory gcStepIfUseful.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  4099
	].
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  4100
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  4101
	"then do idle actions"
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  4102
	(idleActions notNil and:[idleActions notEmpty]) ifTrue:[
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  4103
	    idleActions do:[:eachIdleBlock |
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  4104
		eachIdleBlock value.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  4105
	    ].
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  4106
	    ^ self  "maybe an idleAction has woken up a process. go back checking"
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  4107
	].
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  4108
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  4109
	(doingGC and:[self checkForIOWithTimeout:0]) ifTrue:[
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  4110
	    ^ self  "a process possibly has been woken up, go back checking"
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  4111
	].
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  4112
	doingGC
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  4113
    ] whileTrue.
10
claus
parents: 3
diff changeset
  4114
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
  4115
    exitWhenNoMoreUserProcesses ifTrue:[
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  4116
	"/ check if there are any processes at all
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  4117
	"/ stop dispatching if there is none
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  4118
	"/ (and anyTimeouts is false, which means that no timeout blocks are present)
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  4119
	"/ and no readSemaphores are present (which means that noone is waiting for input)
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  4120
	"/ and no writeSemaphores are present
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  4121
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  4122
	"/ cg: changed to only check when a process terminated
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  4123
	"/ self checkForEndOfDispatch.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  4124
	dispatching ifFalse:[
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  4125
	    ^ self
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  4126
	].
6619
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
  4127
    ].
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
  4128
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
  4129
    preWaitActions notNil ifTrue:[
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  4130
	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
  4131
    ].
10
claus
parents: 3
diff changeset
  4132
1627
f95285226059 infoPrint for NT (no select)
Claus Gittinger <cg@exept.de>
parents: 1618
diff changeset
  4133
    "/
f95285226059 infoPrint for NT (no select)
Claus Gittinger <cg@exept.de>
parents: 1618
diff changeset
  4134
    "/ absolutely nothing to do - simply wait
f95285226059 infoPrint for NT (no select)
Claus Gittinger <cg@exept.de>
parents: 1618
diff changeset
  4135
    "/
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  4136
    useIOInterrupts ifTrue:[
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  4137
	dT := 999999.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  4138
    ] ifFalse:[
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  4139
	dT := EventPollingInterval.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  4140
	OperatingSystem supportsSelect ifFalse:[
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  4141
	    "SCO instant ShitStation has a bug here,
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  4142
	     waiting always 1 sec in the select - therefore we delay a bit and
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  4143
	     return - effectively polling in 20ms cycles
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  4144
	    "
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  4145
	    (self checkForIOWithTimeout:0) ifTrue:[
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  4146
		^ self  "go back checking"
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  4147
	    ].
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  4148
	    OperatingSystem millisecondDelay:dT.
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  4149
	    ^ self
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  4150
	].
10
claus
parents: 3
diff changeset
  4151
    ].
claus
parents: 3
diff changeset
  4152
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  4153
    millisToNextTimeout isNil ifTrue:[
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  4154
	millisToNextTimeout := dT.
3745
3fd121f2e74e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3740
diff changeset
  4155
    ] ifFalse:[
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  4156
	millisToNextTimeout := millisToNextTimeout min:dT.
3745
3fd121f2e74e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3740
diff changeset
  4157
    ].
3fd121f2e74e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3740
diff changeset
  4158
25422
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  4159
    self checkForIOWithTimeout:millisToNextTimeout
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  4160
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  4161
    "Modified: / 14-12-1995 / 13:37:46 / stefan"
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  4162
    "Modified: / 18-07-1996 / 20:42:17 / cg"
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  4163
    "Modified (comment): / 13-02-2017 / 20:29:22 / cg"
3b02b0f1f647 Cherry-picked `Semaphore`, `EventSemaphore, `Process` and `ProcessorScheduler`
Jan Vrany <jan.vrany@labware.com>
parents: 23107
diff changeset
  4164
    "Modified (format): / 20-05-2020 / 17:34:35 / Stefan Vogel"
10
claus
parents: 3
diff changeset
  4165
! !
claus
parents: 3
diff changeset
  4166
1783
be7402f74d94 hide timerInterrupt & ioInterrupt contexts when switching
Claus Gittinger <cg@exept.de>
parents: 1780
diff changeset
  4167
!ProcessorScheduler class methodsFor:'documentation'!
10
claus
parents: 3
diff changeset
  4168
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  4169
version
18620
b4e9f25d6ce6 preparations for lined index list in WeakArray
Claus Gittinger <cg@exept.de>
parents: 18295
diff changeset
  4170
    ^ '$Header$'
12717
594a44c45567 changed: #vmResumeInterrupt:
Stefan Vogel <sv@exept.de>
parents: 11836
diff changeset
  4171
!
594a44c45567 changed: #vmResumeInterrupt:
Stefan Vogel <sv@exept.de>
parents: 11836
diff changeset
  4172
594a44c45567 changed: #vmResumeInterrupt:
Stefan Vogel <sv@exept.de>
parents: 11836
diff changeset
  4173
version_CVS
18620
b4e9f25d6ce6 preparations for lined index list in WeakArray
Claus Gittinger <cg@exept.de>
parents: 18295
diff changeset
  4174
    ^ '$Header$'
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4175
! !
6939
6f6ea7b0a5ab stopping an suspended process fix
Claus Gittinger <cg@exept.de>
parents: 6807
diff changeset
  4176
14771
c85f3f394aae class: ProcessorScheduler
Stefan Vogel <sv@exept.de>
parents: 14442
diff changeset
  4177
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  4178
ProcessorScheduler initialize!