ProcessorScheduler.st
author Claus Gittinger <cg@exept.de>
Wed, 06 Dec 2006 18:45:11 +0100
changeset 10233 4006fa954217
parent 9991 a03847e11498
child 10267 217ead693f29
permissions -rw-r--r--
*** empty log message ***
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
159
514c749165c3 *** empty log message ***
claus
parents: 144
diff changeset
     3
	      All Rights Reserved
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
     4
a27a279701f8 Initial revision
claus
parents:
diff changeset
     5
 This software is furnished under a license and may be used
a27a279701f8 Initial revision
claus
parents:
diff changeset
     6
 only in accordance with the terms of that license and with the
a27a279701f8 Initial revision
claus
parents:
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
a27a279701f8 Initial revision
claus
parents:
diff changeset
     8
 be provided or otherwise made available to, or used by, any
a27a279701f8 Initial revision
claus
parents:
diff changeset
     9
 other person.  No title to or ownership of the software is
a27a279701f8 Initial revision
claus
parents:
diff changeset
    10
 hereby transferred.
a27a279701f8 Initial revision
claus
parents:
diff changeset
    11
"
5396
92bf7d0b1b66 Fix typo.
Stefan Vogel <sv@exept.de>
parents: 5389
diff changeset
    12
"{ Package: 'stx:libbasic' }"
92bf7d0b1b66 Fix typo.
Stefan Vogel <sv@exept.de>
parents: 5389
diff changeset
    13
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    14
Object subclass:#ProcessorScheduler
2280
aca71c89f32c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2269
diff changeset
    15
	instanceVariableNames:'quiescentProcessLists scheduler zombie activeProcess
aca71c89f32c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2269
diff changeset
    16
		activeProcessId currentPriority readFdArray readSemaphoreArray
5103
7b1f6c93b3aa checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5101
diff changeset
    17
		readCheckArray writeFdArray writeSemaphoreArray writeCheckArray
7b1f6c93b3aa checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5101
diff changeset
    18
		timeoutArray timeoutActionArray timeoutProcessArray
7b1f6c93b3aa checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5101
diff changeset
    19
		timeoutSemaphoreArray idleActions anyTimeouts dispatching
7b1f6c93b3aa checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5101
diff changeset
    20
		interruptedProcess useIOInterrupts gotIOInterrupt
7b1f6c93b3aa checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5101
diff changeset
    21
		osChildExitActions gotChildSignalInterrupt
7b1f6c93b3aa checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5101
diff changeset
    22
		exitWhenNoMoreUserProcesses suspendScheduler timeSliceProcess
9437
432a4a06934f + timeoutHandlerProcess
ca
parents: 9295
diff changeset
    23
		supportDynamicPriorities scheduledProcesses preWaitActions
432a4a06934f + timeoutHandlerProcess
ca
parents: 9295
diff changeset
    24
		timeoutHandlerProcess'
768
20434b8239f3 stefans modalBox changes (no more polling)
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
    25
	classVariableNames:'KnownProcesses KnownProcessIds PureEventDriven
752
0259dd855289 new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents: 750
diff changeset
    26
		UserSchedulingPriority UserInterruptPriority TimingPriority
1679
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
    27
		HighestPriority SchedulingPriority MaxNumberOfProcesses
2626
4194d370d46f made event polling interval a variable
Claus Gittinger <cg@exept.de>
parents: 2625
diff changeset
    28
		InvalidProcessSignal TimeSlicingPriorityLimit TimeSliceInterval
4194d370d46f made event polling interval a variable
Claus Gittinger <cg@exept.de>
parents: 2625
diff changeset
    29
		EventPollingInterval'
768
20434b8239f3 stefans modalBox changes (no more polling)
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
    30
	poolDictionaries:''
20434b8239f3 stefans modalBox changes (no more polling)
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
    31
	category:'Kernel-Processes'
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    32
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
    33
1783
be7402f74d94 hide timerInterrupt & ioInterrupt contexts when switching
Claus Gittinger <cg@exept.de>
parents: 1780
diff changeset
    34
!ProcessorScheduler class methodsFor:'documentation'!
88
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    35
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    36
copyright
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    37
"
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    38
 COPYRIGHT (c) 1993 by Claus Gittinger
159
514c749165c3 *** empty log message ***
claus
parents: 144
diff changeset
    39
	      All Rights Reserved
88
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    40
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    41
 This software is furnished under a license and may be used
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    42
 only in accordance with the terms of that license and with the
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    43
 inclusion of the above copyright notice.   This software may not
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    44
 be provided or otherwise made available to, or used by, any
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    45
 other person.  No title to or ownership of the software is
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    46
 hereby transferred.
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    47
"
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    48
!
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    49
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    50
documentation
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    51
"
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    52
    This class has only one instance, which is bound to the global
2193
Claus Gittinger <cg@exept.de>
parents: 2191
diff changeset
    53
    'Processor' (well, on future multiprocessor systems, things may look
Claus Gittinger <cg@exept.de>
parents: 2191
diff changeset
    54
    different ... ;-). It is responsible for scheduling among the smalltalk
88
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    55
    processes (threads; not to confuse with heavy weight unix processes).
93
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
    56
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
    57
    Scheduling is fully done in smalltalk (the always runnable scheduler-
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
    58
    process, running at highest priority does this).
2193
Claus Gittinger <cg@exept.de>
parents: 2191
diff changeset
    59
    See the 'scheduling' documentation.
Claus Gittinger <cg@exept.de>
parents: 2191
diff changeset
    60
231
fd0e55e352f8 cleanup
claus
parents: 217
diff changeset
    61
    The main VM primitive to support this is found in threadSwitch, which passes
93
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
    62
    control to another process (usually selected by the scheduler).
159
514c749165c3 *** empty log message ***
claus
parents: 144
diff changeset
    63
    Thus it is possible to modify the schedulers policy and implementation
514c749165c3 *** empty log message ***
claus
parents: 144
diff changeset
    64
    at the smalltalk level.
93
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
    65
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
    66
    Notice: Smalltalk/X can (still) be compiled & configured without
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
    67
    process support. This non-process mode is called 'pureEventDriven' mode
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
    68
    and is useful to quickly port ST/X to systems, where these facilities
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
    69
    are either not needed (server applications), or are difficult to
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
    70
    implement (threads require some assembler support functions). 
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
    71
    To allow pureEvent mode, kludges are built into some places in the
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
    72
    system, where either a process is forked, or a timeout is used instead 
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
    73
    (for examples, see ProcessMonitor or MemoryMonitor).
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
    74
335
claus
parents: 326
diff changeset
    75
    This pure-event mode may not be supported in the future 
2193
Claus Gittinger <cg@exept.de>
parents: 2191
diff changeset
    76
    (actually, it is no longer maintained, so dont run the system without Processes).
93
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
    77
6619
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
    78
    [instance variables:]
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
    79
        quiescentProcessLists           - list of waiting processes
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
    80
        scheduler                       - the scheduler process itself
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
    81
        zombie                          - internal temporary (recently died process)
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
    82
        activeProcess                   - the current process
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
    83
        activeProcessId                 - the current processes id
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
    84
        currentPriority                 - the current processes priority
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
    85
        readFdArray                     - fd-sema-checkBlock triple-association
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
    86
        readSemaphoreArray                (stupid historic 3-separate arrays for hi-speed-optimization reasons)
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
    87
        readCheckArray 
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
    88
        writeFdArray                    - fd-sema-checkBlock triple-association
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
    89
        writeSemaphoreArray               (stupid historic 3-separate arrays for hi-speed-optimization reasons)
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
    90
        writeCheckArray
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
    91
        timeoutArray                    - time-action-process-sema quadruple-association
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
    92
        timeoutActionArray                (stupid historic 3-separate arrays for hi-speed-optimization reasons)
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
    93
        timeoutProcessArray 
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
    94
        timeoutSemaphoreArray 
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
    95
        idleActions                     - actions to be executed when idle
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
    96
        preWaitActions                  - actions to be executed BEFORE going into an OS-wait
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
    97
        anyTimeouts                     - flag if any timeouts are pending
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
    98
        dispatching                     - flag if dispatch process is running (i.e. NOT initializing)
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
    99
        interruptedProcess              - the currently interrupted process.
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
   100
        useIOInterrupts                 - flag if the OS supports I/O interrupts and if they are used (to get me out of an OS wait)
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
   101
        gotIOInterrupt                  - flag if I came out of a wait due to an I/O interrupt
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
   102
        osChildExitActions              - OS chid process actions
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
   103
        gotChildSignalInterrupt         - flag if I came out of a wait due to an OS child interrupt
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
   104
        exitWhenNoMoreUserProcesses     - flag which controls if ST/X should exit when the last process dies (for standalone apps)
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
   105
        suspendScheduler                - internal use
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
   106
        timeSliceProcess                - the timeSlicer process
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
   107
        supportDynamicPriorities        - flag if dynamic priorities should be supported by the timeSlicer
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
   108
        scheduledProcesses              - list of scheduled processes for the timeSlicers dynamic prio handling
369
claus
parents: 362
diff changeset
   109
1273
f8449f53a6a3 commentary
Claus Gittinger <cg@exept.de>
parents: 1177
diff changeset
   110
    [class variables:]
93
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   111
6619
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
   112
        KnownProcesses          <WeakArray>     all known processes
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
   113
        KnownProcessIds         <Collection>    and their IDs
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
   114
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
   115
        PureEventDriven         <Boolean>       true, if no process support
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
   116
                                                is available
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
   117
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
   118
        UserSchedulingPriority  <Integer>       the priority at which normal
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
   119
                                                user interfaces run
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
   120
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
   121
        UserInterruptPriority                   the priority at which user-
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
   122
                                                interrupts (Cntl-C) processing
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
   123
                                                takes place. Processes with
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
   124
                                                a greater or equal priority are
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
   125
                                                not interruptable.
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
   126
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
   127
        TimingPriority                          the priority used for timing.
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
   128
                                                Processes with a greater or
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
   129
                                                equal priority are not interrupted
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
   130
                                                by timers.
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
   131
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
   132
        HighestPriority                         The highest allowed prio for processes
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
   133
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
   134
        SchedulingPriority                      The priority of the scheduler (must
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
   135
                                                me higher than any other).
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
   136
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
   137
        MaxNumberOfProcesses                    if non-nil, no more than this
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
   138
                                                number of processes are allowed
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
   139
                                                (for debugging)
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
   140
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
   141
        TimeSliceInterval                       for preemptive priority scheduling only:
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
   142
                                                the time interval in millis, at which processes
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
   143
                                                are timesliced
2534
6ac73e757c70 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2499
diff changeset
   144
                                                
6619
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
   145
        TimeSlicingPriorityLimit                for preemptive priority scheduling only:
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
   146
                                                processes are only timesliced, if running 
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
   147
                                                at or below this priority.
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
   148
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
   149
        EventPollingInterval                    for systems which do not support select on
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
   150
                                                a fileDescriptor: the polling interval in millis.
2626
4194d370d46f made event polling interval a variable
Claus Gittinger <cg@exept.de>
parents: 2625
diff changeset
   151
759
908363ce8a32 interest is written with one 'r' (shame on me)
Claus Gittinger <cg@exept.de>
parents: 752
diff changeset
   152
    most interesting methods:
93
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   153
6619
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
   154
        Processor>>suspend:                  (see also Process>>suspend)
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
   155
        Processor>>resume:                   (see also Process>>resume)
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
   156
        Processor>>terminate:                (see also Process>>terminate)
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
   157
        Processor>>yield 
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
   158
        Processor>>changePriority:for:       (see also Process>>priority:
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
   159
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
   160
        Processor>>signal:afterSeconds:      (see also Delay>>forSeconds:)
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
   161
        Processor>>signal:afterMilliseconds: (see also Delay>>forMilliseconds:)
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
   162
        Processor>>signal:onInput:           (see also ExternalStream>>readWait)
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
   163
        Processor>>signal:onOutput:          (see also ExternalStream>>writeWait)
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
   164
        Processor>>disableSemaphore:
1273
f8449f53a6a3 commentary
Claus Gittinger <cg@exept.de>
parents: 1177
diff changeset
   165
f8449f53a6a3 commentary
Claus Gittinger <cg@exept.de>
parents: 1177
diff changeset
   166
f8449f53a6a3 commentary
Claus Gittinger <cg@exept.de>
parents: 1177
diff changeset
   167
    [see also:]
6619
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
   168
        Process
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
   169
        Delay Semaphore SemaphoreSet SharedQueue
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
   170
        WindowGroup
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
   171
        (``Working with processes'': programming/processes.html)
1294
e26bbb61f6b2 documentation
Claus Gittinger <cg@exept.de>
parents: 1273
diff changeset
   172
e26bbb61f6b2 documentation
Claus Gittinger <cg@exept.de>
parents: 1273
diff changeset
   173
    [author:]
6619
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
   174
        Claus Gittinger
88
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
   175
"
2193
Claus Gittinger <cg@exept.de>
parents: 2191
diff changeset
   176
!
Claus Gittinger <cg@exept.de>
parents: 2191
diff changeset
   177
Claus Gittinger <cg@exept.de>
parents: 2191
diff changeset
   178
scheduling
Claus Gittinger <cg@exept.de>
parents: 2191
diff changeset
   179
"
Claus Gittinger <cg@exept.de>
parents: 2191
diff changeset
   180
    By default, the scheduler does 'non preemptive priority scheduling'; 
Claus Gittinger <cg@exept.de>
parents: 2191
diff changeset
   181
Claus Gittinger <cg@exept.de>
parents: 2191
diff changeset
   182
    this means, that the highest priority runnable process 
Claus Gittinger <cg@exept.de>
parents: 2191
diff changeset
   183
    is choosen and allowed to run, until it either gives back the CPU (via #yield),
Claus Gittinger <cg@exept.de>
parents: 2191
diff changeset
   184
    or suspends (i.e. waiting for I/O, the time or a semaphore),
Claus Gittinger <cg@exept.de>
parents: 2191
diff changeset
   185
    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
   186
    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
   187
    (i.e. signalling a semaphore), by a timer or by IO availability.
2193
Claus Gittinger <cg@exept.de>
parents: 2191
diff changeset
   188
Claus Gittinger <cg@exept.de>
parents: 2191
diff changeset
   189
    If another process is runnable at the same priority, it will not
Claus Gittinger <cg@exept.de>
parents: 2191
diff changeset
   190
    be given CPU-time, unless one of the above happens.
Claus Gittinger <cg@exept.de>
parents: 2191
diff changeset
   191
Claus Gittinger <cg@exept.de>
parents: 2191
diff changeset
   192
    The consequence is, that a user process running at (say) priority 8,
Claus Gittinger <cg@exept.de>
parents: 2191
diff changeset
   193
    may block other user processes at the same priority, if it does heavy
Claus Gittinger <cg@exept.de>
parents: 2191
diff changeset
   194
    processing, or loops.
3650
523781600982 added #useIOInterrupts: to allow disabling this feature
Claus Gittinger <cg@exept.de>
parents: 3644
diff changeset
   195
    (the event handling which is responsible to care for userInterrupts, 
523781600982 added #useIOInterrupts: to allow disabling this feature
Claus Gittinger <cg@exept.de>
parents: 3644
diff changeset
   196
     is running at a much higher priority, 
523781600982 added #useIOInterrupts: to allow disabling this feature
Claus Gittinger <cg@exept.de>
parents: 3644
diff changeset
   197
     so that interrupting the process should always be possible).
2193
Claus Gittinger <cg@exept.de>
parents: 2191
diff changeset
   198
Claus Gittinger <cg@exept.de>
parents: 2191
diff changeset
   199
Claus Gittinger <cg@exept.de>
parents: 2191
diff changeset
   200
    The scheduler also supports 'timesliced priority scheduling', which is enabled
Claus Gittinger <cg@exept.de>
parents: 2191
diff changeset
   201
    via the #startTimeSlicing message (and disabled by #stopTimeSlicing).
Claus Gittinger <cg@exept.de>
parents: 2191
diff changeset
   202
    In this mode, the highest priority running process is suspended in regular intervals
Claus Gittinger <cg@exept.de>
parents: 2191
diff changeset
   203
    (the TimeSliceInterval) IFF there is another runnable process with the same priority.
Claus Gittinger <cg@exept.de>
parents: 2191
diff changeset
   204
    I.e. the top highest priority processes are timeshared.
Claus Gittinger <cg@exept.de>
parents: 2191
diff changeset
   205
    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
   206
    lower priority process will only run, IFF all higher prio processes are waiting for an
Claus Gittinger <cg@exept.de>
parents: 2191
diff changeset
   207
    event.
Claus Gittinger <cg@exept.de>
parents: 2191
diff changeset
   208
    Timeslicing will not be done for processes running above TimeSlicingPriorityLimit, which
Claus Gittinger <cg@exept.de>
parents: 2191
diff changeset
   209
    allows for critical processes to run unaffected to completion.
Claus Gittinger <cg@exept.de>
parents: 2191
diff changeset
   210
Claus Gittinger <cg@exept.de>
parents: 2191
diff changeset
   211
    WARNING:
5101
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
   212
	timesliced priority scheduling is an experimental feature. There is no warranty,
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
   213
	(at the moment), that the system runs reliable in this mode.
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
   214
	The problem is, that shared collections may now be easily modified by other
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
   215
	processes, running at the same time. 
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
   216
	The class library has being investigated for such possible trouble spots 
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
   217
	(we have eliminated many weak spots, and added critical regions at many places,
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
   218
	 but cannot guarantee that all of them have been found so far ...)
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
   219
	We found that many existing public domain programs are not prepared for
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
   220
	being interrupted by a same-prio process and therefore may corrupt their
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
   221
	data. If in doubt, disable this fefature.
2193
Claus Gittinger <cg@exept.de>
parents: 2191
diff changeset
   222
Claus Gittinger <cg@exept.de>
parents: 2191
diff changeset
   223
    We think, that the timeSlicer is a useful add-on and that the system is fit enough
Claus Gittinger <cg@exept.de>
parents: 2191
diff changeset
   224
    for it to be evaluated, therefore, its included. 
Claus Gittinger <cg@exept.de>
parents: 2191
diff changeset
   225
    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
   226
523781600982 added #useIOInterrupts: to allow disabling this feature
Claus Gittinger <cg@exept.de>
parents: 3644
diff changeset
   227
    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
   228
5101
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
   229
	- disable timeSlicing (in the launchers misc-settings menu)
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
   230
	- open a workSpace
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
   231
	- in the workspace, evaluate:
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
   232
		[true] whileTrue:[1000 factorial]
3650
523781600982 added #useIOInterrupts: to allow disabling this feature
Claus Gittinger <cg@exept.de>
parents: 3644
diff changeset
   233
523781600982 added #useIOInterrupts: to allow disabling this feature
Claus Gittinger <cg@exept.de>
parents: 3644
diff changeset
   234
    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
   235
    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
   236
    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
   237
    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
   238
523781600982 added #useIOInterrupts: to allow disabling this feature
Claus Gittinger <cg@exept.de>
parents: 3644
diff changeset
   239
    Now, stop the factorial-loop, enable timeSlicing, and try again.
523781600982 added #useIOInterrupts: to allow disabling this feature
Claus Gittinger <cg@exept.de>
parents: 3644
diff changeset
   240
    You will notice, that other windows react - although possibly a bit slower, 
523781600982 added #useIOInterrupts: to allow disabling this feature
Claus Gittinger <cg@exept.de>
parents: 3644
diff changeset
   241
    since the CPU is now divided equally among the runnable processes (timeSliced).
2193
Claus Gittinger <cg@exept.de>
parents: 2191
diff changeset
   242
"
88
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
   243
! !
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
   244
1783
be7402f74d94 hide timerInterrupt & ioInterrupt contexts when switching
Claus Gittinger <cg@exept.de>
parents: 1780
diff changeset
   245
!ProcessorScheduler class methodsFor:'initialization'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   246
a27a279701f8 Initial revision
claus
parents:
diff changeset
   247
initialize
44
b262907c93ea *** empty log message ***
claus
parents: 42
diff changeset
   248
    "class setup: create the one-and-only instance of myself and
b262907c93ea *** empty log message ***
claus
parents: 42
diff changeset
   249
     setup some priority values."
b262907c93ea *** empty log message ***
claus
parents: 42
diff changeset
   250
2193
Claus Gittinger <cg@exept.de>
parents: 2191
diff changeset
   251
    TimeSliceInterval := 50.
2626
4194d370d46f made event polling interval a variable
Claus Gittinger <cg@exept.de>
parents: 2625
diff changeset
   252
    EventPollingInterval := 20.
2193
Claus Gittinger <cg@exept.de>
parents: 2191
diff changeset
   253
93
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   254
    UserSchedulingPriority := 8.
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   255
    UserInterruptPriority := 24.
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   256
    TimingPriority := 16.
2190
8afa4709d8a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2188
diff changeset
   257
    TimeSlicingPriorityLimit := 26.
8afa4709d8a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2188
diff changeset
   258
    HighestPriority := 30.
93
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   259
    SchedulingPriority := 31.
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   260
1679
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   261
    InvalidProcessSignal isNil ifTrue:[
7097
23529d6e866e Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents: 7076
diff changeset
   262
        InvalidProcessSignal := Error newSignalMayProceed:true.
23529d6e866e Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents: 7076
diff changeset
   263
        InvalidProcessSignal nameClass:self message:#invalidProcessSignal.
23529d6e866e Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents: 7076
diff changeset
   264
        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
   265
    ].
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   266
159
514c749165c3 *** empty log message ***
claus
parents: 144
diff changeset
   267
    Processor isNil ifTrue:[
7097
23529d6e866e Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents: 7076
diff changeset
   268
        "create the one and only processor"
23529d6e866e Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents: 7076
diff changeset
   269
23529d6e866e Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents: 7076
diff changeset
   270
        Processor := self basicNew initialize.
10
claus
parents: 3
diff changeset
   271
    ].
77
6c38ca59927f *** empty log message ***
claus
parents: 76
diff changeset
   272
6c38ca59927f *** empty log message ***
claus
parents: 76
diff changeset
   273
    "
6c38ca59927f *** empty log message ***
claus
parents: 76
diff changeset
   274
     allow configurations without processes
2129
e03cd7bc3475 newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents: 2123
diff changeset
   275
     (but such configurations are no longer distributed)
77
6c38ca59927f *** empty log message ***
claus
parents: 76
diff changeset
   276
    "
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   277
    PureEventDriven := self threadsAvailable not.
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   278
    PureEventDriven ifTrue:[
7097
23529d6e866e Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents: 7076
diff changeset
   279
        'Processor [error]: no process support - running event driven' errorPrintCR
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   280
    ].
1086
7b0641a2e1ef nicer message
Claus Gittinger <cg@exept.de>
parents: 1061
diff changeset
   281
1679
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   282
    "Modified: 23.9.1996 / 14:24:50 / stefan"
2129
e03cd7bc3475 newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents: 2123
diff changeset
   283
    "Modified: 10.1.1997 / 18:03:03 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   284
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   285
1783
be7402f74d94 hide timerInterrupt & ioInterrupt contexts when switching
Claus Gittinger <cg@exept.de>
parents: 1780
diff changeset
   286
!ProcessorScheduler class methodsFor:'instance creation'!
10
claus
parents: 3
diff changeset
   287
claus
parents: 3
diff changeset
   288
new
claus
parents: 3
diff changeset
   289
    "there is (currently) only one processor ..."
claus
parents: 3
diff changeset
   290
159
514c749165c3 *** empty log message ***
claus
parents: 144
diff changeset
   291
    self error:'only one processor is allowed in the system'
10
claus
parents: 3
diff changeset
   292
! !
claus
parents: 3
diff changeset
   293
1783
be7402f74d94 hide timerInterrupt & ioInterrupt contexts when switching
Claus Gittinger <cg@exept.de>
parents: 1780
diff changeset
   294
!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
   295
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   296
invalidProcessSignal
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   297
    ^ InvalidProcessSignal
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   298
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   299
    "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
   300
! !
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   301
1783
be7402f74d94 hide timerInterrupt & ioInterrupt contexts when switching
Claus Gittinger <cg@exept.de>
parents: 1780
diff changeset
   302
!ProcessorScheduler class methodsFor:'instance release'!
10
claus
parents: 3
diff changeset
   303
2091
c11bb3e29a1b Use dependent mechamism of WeakArray instead of #watcher.
Stefan Vogel <sv@exept.de>
parents: 1981
diff changeset
   304
update:something with:aParameter from:changedObject
159
514c749165c3 *** empty log message ***
claus
parents: 144
diff changeset
   305
    "some Process has been garbage collected 
335
claus
parents: 326
diff changeset
   306
     - terminate the underlying thread. 
claus
parents: 326
diff changeset
   307
     Usually this does not happen; instead, the process terminates itself 
claus
parents: 326
diff changeset
   308
     by sending #terminate."
10
claus
parents: 3
diff changeset
   309
claus
parents: 3
diff changeset
   310
    |id sz "{ Class: SmallInteger }"|
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   311
2091
c11bb3e29a1b Use dependent mechamism of WeakArray instead of #watcher.
Stefan Vogel <sv@exept.de>
parents: 1981
diff changeset
   312
    something == #ElementExpired ifTrue:[
2534
6ac73e757c70 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2499
diff changeset
   313
	sz := KnownProcessIds size.
6ac73e757c70 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2499
diff changeset
   314
	1 to:sz do:[:index |
6ac73e757c70 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2499
diff changeset
   315
	    "/ (KnownProcesses at:index) isNil ifTrue:[
6ac73e757c70 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2499
diff changeset
   316
	    (KnownProcesses at:index) == 0 ifTrue:[
6ac73e757c70 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2499
diff changeset
   317
		id := KnownProcessIds at:index.
6ac73e757c70 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2499
diff changeset
   318
		id notNil ifTrue:[
6ac73e757c70 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2499
diff changeset
   319
		    'Processor [warning]: terminating thread ' errorPrint.
6ac73e757c70 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2499
diff changeset
   320
		    id errorPrint.
6ac73e757c70 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2499
diff changeset
   321
		    ' (no longer refd)' errorPrintCR.
6ac73e757c70 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2499
diff changeset
   322
6ac73e757c70 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2499
diff changeset
   323
		    self threadDestroy:id.
6ac73e757c70 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2499
diff changeset
   324
		    KnownProcessIds at:index put:nil.
6ac73e757c70 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2499
diff changeset
   325
		].
6ac73e757c70 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2499
diff changeset
   326
		KnownProcesses at:index put:nil.
6ac73e757c70 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2499
diff changeset
   327
	    ]
6ac73e757c70 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2499
diff changeset
   328
	]
10
claus
parents: 3
diff changeset
   329
    ]
2091
c11bb3e29a1b Use dependent mechamism of WeakArray instead of #watcher.
Stefan Vogel <sv@exept.de>
parents: 1981
diff changeset
   330
c11bb3e29a1b Use dependent mechamism of WeakArray instead of #watcher.
Stefan Vogel <sv@exept.de>
parents: 1981
diff changeset
   331
    "Created: 7.1.1997 / 16:45:42 / stefan"
2137
3e210d26d0d8 *PrintNL eliminated
Claus Gittinger <cg@exept.de>
parents: 2129
diff changeset
   332
    "Modified: 10.1.1997 / 19:10:48 / cg"
10
claus
parents: 3
diff changeset
   333
! !
claus
parents: 3
diff changeset
   334
1783
be7402f74d94 hide timerInterrupt & ioInterrupt contexts when switching
Claus Gittinger <cg@exept.de>
parents: 1780
diff changeset
   335
!ProcessorScheduler class methodsFor:'primitive process primitives'!
10
claus
parents: 3
diff changeset
   336
339
claus
parents: 337
diff changeset
   337
threadCreate:aProcess withId:id
159
514c749165c3 *** empty log message ***
claus
parents: 144
diff changeset
   338
    "physical creation of a process.
10
claus
parents: 3
diff changeset
   339
     (warning: low level entry, no administration done).
339
claus
parents: 337
diff changeset
   340
     This may raise an exception, if a VM process could not be created."
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   341
369
claus
parents: 362
diff changeset
   342
    MaxNumberOfProcesses notNil ifTrue:[
5101
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
   343
	KnownProcessIds size >= MaxNumberOfProcesses ifTrue:[
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
   344
	    (KnownProcessIds count:[:el | el notNil]) >= MaxNumberOfProcesses ifTrue:[
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
   345
		"
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
   346
		 the number of processes has reached the (soft) limit.
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
   347
		 This limit prevents runaway programs from creating too many
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
   348
		 processes. If you continue in the debugger, the process will be
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
   349
		 created as usual. If you dont want this, abort or terminate.
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
   350
		"
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
   351
		self error:'too many processes'.
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
   352
	    ]
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
   353
	]
369
claus
parents: 362
diff changeset
   354
    ].
claus
parents: 362
diff changeset
   355
claus
parents: 362
diff changeset
   356
%{
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   357
    int tid;
a27a279701f8 Initial revision
claus
parents:
diff changeset
   358
    extern int __threadCreate();
a27a279701f8 Initial revision
claus
parents:
diff changeset
   359
339
claus
parents: 337
diff changeset
   360
    tid = __threadCreate(aProcess, 
5101
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
   361
			 0   /* stackSize: no longer needed */, 
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
   362
			 __isSmallInteger(id) ? __intVal(id)     /* assign id */
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
   363
					      : -1              /* let VM assign one */  );
339
claus
parents: 337
diff changeset
   364
    if (tid) {
8913
b9498d27a554 64bit; mkSmallInteger
Claus Gittinger <cg@exept.de>
parents: 8675
diff changeset
   365
	RETURN ( __mkSmallInteger(tid));
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   366
    }
a27a279701f8 Initial revision
claus
parents:
diff changeset
   367
%}
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   368
.
69
4564b6328136 *** empty log message ***
claus
parents: 59
diff changeset
   369
    "
4564b6328136 *** empty log message ***
claus
parents: 59
diff changeset
   370
     arrive here, if creation of process in VM failed.
159
514c749165c3 *** empty log message ***
claus
parents: 144
diff changeset
   371
     This may happen, if the VM does not support more processes,
514c749165c3 *** empty log message ***
claus
parents: 144
diff changeset
   372
     or if it ran out of memory, when allocating internal data
514c749165c3 *** empty log message ***
claus
parents: 144
diff changeset
   373
     structures.
69
4564b6328136 *** empty log message ***
claus
parents: 59
diff changeset
   374
    "
115
11be294044b6 added changePriority
claus
parents: 93
diff changeset
   375
    ^ ObjectMemory allocationFailureSignal raise.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   376
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   377
a27a279701f8 Initial revision
claus
parents:
diff changeset
   378
threadDestroy:id
a27a279701f8 Initial revision
claus
parents:
diff changeset
   379
    "physical destroy other process ...
a27a279701f8 Initial revision
claus
parents:
diff changeset
   380
     (warning: low level entry, no administration done)"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   381
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   382
%{  /* NOCONTEXT */
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   383
253
30daee717a53 *** empty log message ***
claus
parents: 243
diff changeset
   384
    if (__isSmallInteger(id)) {
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1092
diff changeset
   385
	__threadDestroy(__intVal(id));
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   386
    }
a27a279701f8 Initial revision
claus
parents:
diff changeset
   387
%}
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   388
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   389
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   390
threadInterrupt:id
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   391
    "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
   392
     threadSwitcher, to let the process perform a #interrupt when its set to
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   393
     run the next time. The process itself can decide how to react on this 
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   394
     interrupt (currently, it looks for interruptBlocks to evaluate)."
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   395
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   396
%{  /* NOCONTEXT */
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   397
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   398
    if (__isSmallInteger(id)) {
9437
432a4a06934f + timeoutHandlerProcess
ca
parents: 9295
diff changeset
   399
        __threadInterrupt(__intVal(id));
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   400
    }
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   401
%}
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   402
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   403
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   404
threadsAvailable
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   405
    "return true, if the runtime system supports threads (i.e. processes);
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   406
     false otherwise."
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   407
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   408
%{  /* NOCONTEXT */
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   409
    RETURN (__threadsAvailable());
5406
4a6995b61c0e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5396
diff changeset
   410
%}.
4a6995b61c0e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5396
diff changeset
   411
    ^ true
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   412
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   413
1783
be7402f74d94 hide timerInterrupt & ioInterrupt contexts when switching
Claus Gittinger <cg@exept.de>
parents: 1780
diff changeset
   414
!ProcessorScheduler class methodsFor:'queries'!
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   415
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   416
isPureEventDriven
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   417
    "this is temporary - (maybe not :-).
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   418
     you can run ST/X either with or without processes.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   419
     Without, there is conceptionally a single process handling all
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   420
     outside events and timeouts. This has some negative implications
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   421
     (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
   422
     assembler support - i.e. quick portability.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   423
     The PureEvent flag will automatically be set if the runtime system
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   424
     does not support threads - otherwise, it can be set manually
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   425
     (from rc-file).
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   426
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   427
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   428
    ^ PureEventDriven
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   429
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   430
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   431
knownProcesses
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   432
    "return a collection of all (living) processes in the system"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   433
1780
1b3a4ddc5b94 changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents: 1683
diff changeset
   434
    ^ KnownProcesses select:[:p | p notNil and:[p ~~ 0]]
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
maxNumberOfProcesses
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   438
    "return the limit on the number of processes;
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   439
     the default is nil (i.e. unlimited)."
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   440
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   441
    ^ MaxNumberOfProcesses
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   442
!
10
claus
parents: 3
diff changeset
   443
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   444
maxNumberOfProcesses:aNumber
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   445
    "set the limit on the number of processes.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   446
     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
   447
     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
   448
     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
   449
     processes is unlimited."
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
    MaxNumberOfProcesses := aNumber
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   452
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   453
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   454
processDriven
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   455
    "turn on process driven mode"
10
claus
parents: 3
diff changeset
   456
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   457
    PureEventDriven := false
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   458
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   459
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   460
pureEventDriven
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   461
    "turn on pure-event driven mode - no processes, single dispatch loop"
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
    PureEventDriven := true
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   464
! !
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   465
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   466
!ProcessorScheduler methodsFor:'I/O event actions'!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   467
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   468
disableFd:aFileDescriptor
5101
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
   469
    "obsolete event support: disable block events on aFileDescriptor.
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   470
     This is a leftover support for pure-event systems and may vanish."
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   471
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   472
    |idx "{Class: SmallInteger }" 
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   473
     wasBlocked|
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   474
93
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   475
    wasBlocked := OperatingSystem blockInterrupts.
5101
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
   476
    useIOInterrupts ifTrue:[
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
   477
	OperatingSystem disableIOInterruptsOn:aFileDescriptor
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
   478
    ].
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
   479
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   480
    idx := readFdArray identityIndexOf:aFileDescriptor startingAt:1.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   481
    idx ~~ 0 ifTrue:[
5101
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
   482
	readFdArray at:idx put:nil.
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
   483
	readCheckArray at:idx put:nil.
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
   484
	readSemaphoreArray at:idx put:nil
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
   485
    ].
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
   486
    idx := writeFdArray identityIndexOf:aFileDescriptor startingAt:1.
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
   487
    idx ~~ 0 ifTrue:[
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
   488
	writeFdArray at:idx put:nil.
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
   489
	writeCheckArray at:idx put:nil.
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
   490
	writeSemaphoreArray at:idx put:nil
93
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   491
    ].
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   492
    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
   493
02f9aa61f71b ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   494
    "Modified: 4.8.1997 / 15:16:00 / cg"
24
20cfbafcd0a3 *** empty log message ***
claus
parents: 13
diff changeset
   495
!
20cfbafcd0a3 *** empty log message ***
claus
parents: 13
diff changeset
   496
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   497
enableIOAction:aBlock onInput:aFileDescriptor
5101
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
   498
    "obsolete event support: arrange for aBlock to be
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   499
     evaluated when input on aFileDescriptor arrives. 
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   500
     This is a leftover support for pure-event systems and may vanish."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   501
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   502
    |idx "{Class: SmallInteger }"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   503
     wasBlocked|
10
claus
parents: 3
diff changeset
   504
3116
e535e4e266dd more error handling;
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   505
    aFileDescriptor < 0 ifTrue:[
e535e4e266dd more error handling;
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   506
	'Processor [warning]: ignored invalid fd for IO action.' errorPrintCR.
e535e4e266dd more error handling;
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   507
	thisContext fullPrintAll.
e535e4e266dd more error handling;
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   508
	^ self
e535e4e266dd more error handling;
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   509
    ].
e535e4e266dd more error handling;
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
   510
93
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   511
    wasBlocked := OperatingSystem blockInterrupts.
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   512
    (readFdArray identityIndexOf:aFileDescriptor startingAt:1) == 0 ifTrue:[
5101
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
   513
	idx := readFdArray identityIndexOf:nil startingAt:1.
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
   514
	idx ~~ 0 ifTrue:[
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
   515
	    readFdArray at:idx put:aFileDescriptor.
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
   516
	    readCheckArray at:idx put:aBlock.
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
   517
	    readSemaphoreArray at:idx put:nil
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
   518
	] ifFalse:[
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
   519
	    readFdArray := readFdArray copyWith:aFileDescriptor.
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
   520
	    readCheckArray := readCheckArray copyWith:aBlock.
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
   521
	    readSemaphoreArray := readSemaphoreArray copyWith:nil.
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
   522
	].
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
   523
	useIOInterrupts ifTrue:[
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
   524
	    OperatingSystem enableIOInterruptsOn:aFileDescriptor
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
   525
	].
2831
02f9aa61f71b ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   526
93
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   527
    ].
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   528
    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
   529
02f9aa61f71b ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   530
    "Modified: 4.8.1997 / 15:17:28 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   531
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   532
a27a279701f8 Initial revision
claus
parents:
diff changeset
   533
!ProcessorScheduler methodsFor:'accessing'!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   534
69
4564b6328136 *** empty log message ***
claus
parents: 59
diff changeset
   535
activePriority
4564b6328136 *** empty log message ***
claus
parents: 59
diff changeset
   536
    "return the priority of the currently running process.
159
514c749165c3 *** empty log message ***
claus
parents: 144
diff changeset
   537
     GNU-ST & ST-80 compatibility; this is the same as currentPriority"
69
4564b6328136 *** empty log message ***
claus
parents: 59
diff changeset
   538
4564b6328136 *** empty log message ***
claus
parents: 59
diff changeset
   539
    ^ currentPriority
4564b6328136 *** empty log message ***
claus
parents: 59
diff changeset
   540
!
4564b6328136 *** empty log message ***
claus
parents: 59
diff changeset
   541
25
e34a6267c79b *** empty log message ***
claus
parents: 24
diff changeset
   542
activeProcess
10
claus
parents: 3
diff changeset
   543
    "return the currently running process"
claus
parents: 3
diff changeset
   544
25
e34a6267c79b *** empty log message ***
claus
parents: 24
diff changeset
   545
    ^ activeProcess
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   546
25
e34a6267c79b *** empty log message ***
claus
parents: 24
diff changeset
   547
    "Processor activeProcess"
181
ef3ccf27e2e0 interrupted process now kept for monitor
claus
parents: 161
diff changeset
   548
!
ef3ccf27e2e0 interrupted process now kept for monitor
claus
parents: 161
diff changeset
   549
2262
4c4d810f006f semaphore names
Claus Gittinger <cg@exept.de>
parents: 2258
diff changeset
   550
activeProcessId
4c4d810f006f semaphore names
Claus Gittinger <cg@exept.de>
parents: 2258
diff changeset
   551
    "return the currently running process's ID.
4c4d810f006f semaphore names
Claus Gittinger <cg@exept.de>
parents: 2258
diff changeset
   552
     The same as returned by 'Processor activeProcess id';
4c4d810f006f semaphore names
Claus Gittinger <cg@exept.de>
parents: 2258
diff changeset
   553
     added for to avoid another send in semaphores debugging support."
4c4d810f006f semaphore names
Claus Gittinger <cg@exept.de>
parents: 2258
diff changeset
   554
4c4d810f006f semaphore names
Claus Gittinger <cg@exept.de>
parents: 2258
diff changeset
   555
    ^ activeProcessId
4c4d810f006f semaphore names
Claus Gittinger <cg@exept.de>
parents: 2258
diff changeset
   556
!
4c4d810f006f semaphore names
Claus Gittinger <cg@exept.de>
parents: 2258
diff changeset
   557
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   558
currentPriority
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   559
    "return the priority of the currently running process"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   560
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   561
    ^ currentPriority
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   562
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   563
    "Processor currentPriority"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   564
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   565
181
ef3ccf27e2e0 interrupted process now kept for monitor
claus
parents: 161
diff changeset
   566
interruptedProcess
ef3ccf27e2e0 interrupted process now kept for monitor
claus
parents: 161
diff changeset
   567
    "returns the process which was interrupted by the active one"
ef3ccf27e2e0 interrupted process now kept for monitor
claus
parents: 161
diff changeset
   568
ef3ccf27e2e0 interrupted process now kept for monitor
claus
parents: 161
diff changeset
   569
    ^ interruptedProcess
7046
b7ae8faff2ac Access method for scheduler
Stefan Vogel <sv@exept.de>
parents: 6990
diff changeset
   570
!
b7ae8faff2ac Access method for scheduler
Stefan Vogel <sv@exept.de>
parents: 6990
diff changeset
   571
b7ae8faff2ac Access method for scheduler
Stefan Vogel <sv@exept.de>
parents: 6990
diff changeset
   572
scheduler
b7ae8faff2ac Access method for scheduler
Stefan Vogel <sv@exept.de>
parents: 6990
diff changeset
   573
    "return the scheduling process"
b7ae8faff2ac Access method for scheduler
Stefan Vogel <sv@exept.de>
parents: 6990
diff changeset
   574
b7ae8faff2ac Access method for scheduler
Stefan Vogel <sv@exept.de>
parents: 6990
diff changeset
   575
    ^ scheduler
10
claus
parents: 3
diff changeset
   576
! !
claus
parents: 3
diff changeset
   577
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   578
!ProcessorScheduler methodsFor:'background processing'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   579
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   580
addIdleBlock:aBlock
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   581
    "add the argument, aBlock to the list of idle-actions.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   582
     Idle blocks are evaluated whenever no other process is runnable,
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   583
     and no events are pending.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   584
     Use of idle blocks is not recommended, use a low priority processes 
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   585
     instead, which has the same effect. Idle blcoks are still included
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   586
     to support background actions in pure-event systems, where no processes 
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   587
     are available.
6619
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
   588
     ATTENTION: Support for idle-blocks may vanish."
10
claus
parents: 3
diff changeset
   589
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   590
    |wasBlocked|
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   591
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   592
    wasBlocked := OperatingSystem blockInterrupts.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   593
    idleActions isNil ifTrue:[
6619
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
   594
        idleActions := OrderedCollection new
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   595
    ].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   596
    idleActions add:aBlock.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   597
    wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   598
!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   599
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   600
removeIdleBlock:aBlock
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   601
    "remove the argument, aBlock from the list of idle-blocks.
6619
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
   602
     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
   603
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   604
    |wasBlocked|
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   605
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   606
    wasBlocked := OperatingSystem blockInterrupts.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   607
    idleActions notNil ifTrue:[
3969
0f30268b10c3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3967
diff changeset
   608
       idleActions removeIdentical:aBlock ifAbsent:nil
10
claus
parents: 3
diff changeset
   609
    ].
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   610
    wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
2353
ce92d04c41cc use removeIdentical
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   611
ce92d04c41cc use removeIdentical
Claus Gittinger <cg@exept.de>
parents: 2333
diff changeset
   612
    "Modified: 1.2.1997 / 12:09:46 / cg"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   613
! !
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   614
10
claus
parents: 3
diff changeset
   615
!ProcessorScheduler methodsFor:'dispatching'!
claus
parents: 3
diff changeset
   616
claus
parents: 3
diff changeset
   617
dispatch
93
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   618
     "It handles timeouts and switches to the highest prio runnable process"
44
b262907c93ea *** empty log message ***
claus
parents: 42
diff changeset
   619
829
fc386319f41c removed external function defs (soon no longer allowed)
Claus Gittinger <cg@exept.de>
parents: 827
diff changeset
   620
    |any millis pri p nActions "{ Class: SmallInteger }"
3745
3fd121f2e74e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3740
diff changeset
   621
     checkBlock sema wasBlocked|
3fd121f2e74e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3740
diff changeset
   622
3fd121f2e74e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3740
diff changeset
   623
    wasBlocked := OperatingSystem blockInterrupts.
10
claus
parents: 3
diff changeset
   624
93
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   625
    "
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   626
     handle all timeout actions
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   627
    "
27
d98f9dd437f7 *** empty log message ***
claus
parents: 25
diff changeset
   628
    anyTimeouts ifTrue:[
7510
46a848d466b5 select: wake up readFDs if readable only;
Claus Gittinger <cg@exept.de>
parents: 7495
diff changeset
   629
        self evaluateTimeouts
10
claus
parents: 3
diff changeset
   630
    ].
claus
parents: 3
diff changeset
   631
231
fd0e55e352f8 cleanup
claus
parents: 217
diff changeset
   632
    "first do a quick check for semaphores using checkActions - this is needed for
302
1f76060d58a4 *** empty log message ***
claus
parents: 271
diff changeset
   633
     devices like the X-connection, where some events might be in the event
2618
6d314138ab88 commentary
Claus Gittinger <cg@exept.de>
parents: 2614
diff changeset
   634
     queue but the sockets input queue is empty. 
5101
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
   635
     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
   636
     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
   637
     sockets and pipes (sigh)
93
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   638
    "
10
claus
parents: 3
diff changeset
   639
    any := false.
231
fd0e55e352f8 cleanup
claus
parents: 217
diff changeset
   640
    nActions := readCheckArray size.
10
claus
parents: 3
diff changeset
   641
    1 to:nActions do:[:index |
7510
46a848d466b5 select: wake up readFDs if readable only;
Claus Gittinger <cg@exept.de>
parents: 7495
diff changeset
   642
        checkBlock := readCheckArray at:index.
46a848d466b5 select: wake up readFDs if readable only;
Claus Gittinger <cg@exept.de>
parents: 7495
diff changeset
   643
        (checkBlock notNil and:[checkBlock value]) ifTrue:[
46a848d466b5 select: wake up readFDs if readable only;
Claus Gittinger <cg@exept.de>
parents: 7495
diff changeset
   644
            sema := readSemaphoreArray at:index.
46a848d466b5 select: wake up readFDs if readable only;
Claus Gittinger <cg@exept.de>
parents: 7495
diff changeset
   645
            sema notNil ifTrue:[
46a848d466b5 select: wake up readFDs if readable only;
Claus Gittinger <cg@exept.de>
parents: 7495
diff changeset
   646
                sema signalOnce.
46a848d466b5 select: wake up readFDs if readable only;
Claus Gittinger <cg@exept.de>
parents: 7495
diff changeset
   647
            ].
46a848d466b5 select: wake up readFDs if readable only;
Claus Gittinger <cg@exept.de>
parents: 7495
diff changeset
   648
            any := true.
46a848d466b5 select: wake up readFDs if readable only;
Claus Gittinger <cg@exept.de>
parents: 7495
diff changeset
   649
        ]
5101
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
   650
    ].
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
   651
    nActions := writeCheckArray size.
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
   652
    1 to:nActions do:[:index |
7510
46a848d466b5 select: wake up readFDs if readable only;
Claus Gittinger <cg@exept.de>
parents: 7495
diff changeset
   653
        checkBlock := writeCheckArray at:index.
46a848d466b5 select: wake up readFDs if readable only;
Claus Gittinger <cg@exept.de>
parents: 7495
diff changeset
   654
        (checkBlock notNil and:[checkBlock value]) ifTrue:[
46a848d466b5 select: wake up readFDs if readable only;
Claus Gittinger <cg@exept.de>
parents: 7495
diff changeset
   655
            sema := writeSemaphoreArray at:index.
46a848d466b5 select: wake up readFDs if readable only;
Claus Gittinger <cg@exept.de>
parents: 7495
diff changeset
   656
            sema notNil ifTrue:[
46a848d466b5 select: wake up readFDs if readable only;
Claus Gittinger <cg@exept.de>
parents: 7495
diff changeset
   657
                sema signalOnce.
46a848d466b5 select: wake up readFDs if readable only;
Claus Gittinger <cg@exept.de>
parents: 7495
diff changeset
   658
            ].
46a848d466b5 select: wake up readFDs if readable only;
Claus Gittinger <cg@exept.de>
parents: 7495
diff changeset
   659
            any := true.
46a848d466b5 select: wake up readFDs if readable only;
Claus Gittinger <cg@exept.de>
parents: 7495
diff changeset
   660
        ]
10
claus
parents: 3
diff changeset
   661
    ].
claus
parents: 3
diff changeset
   662
231
fd0e55e352f8 cleanup
claus
parents: 217
diff changeset
   663
    "now, someone might be runnable ..."
10
claus
parents: 3
diff changeset
   664
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   665
    p := self highestPriorityRunnableProcess.
10
claus
parents: 3
diff changeset
   666
    p isNil ifTrue:[
7510
46a848d466b5 select: wake up readFDs if readable only;
Claus Gittinger <cg@exept.de>
parents: 7495
diff changeset
   667
        "/ no one runnable, hard wait for event or timeout
46a848d466b5 select: wake up readFDs if readable only;
Claus Gittinger <cg@exept.de>
parents: 7495
diff changeset
   668
46a848d466b5 select: wake up readFDs if readable only;
Claus Gittinger <cg@exept.de>
parents: 7495
diff changeset
   669
        self waitForEventOrTimeout.
46a848d466b5 select: wake up readFDs if readable only;
Claus Gittinger <cg@exept.de>
parents: 7495
diff changeset
   670
46a848d466b5 select: wake up readFDs if readable only;
Claus Gittinger <cg@exept.de>
parents: 7495
diff changeset
   671
        "/ check for OS process termination
46a848d466b5 select: wake up readFDs if readable only;
Claus Gittinger <cg@exept.de>
parents: 7495
diff changeset
   672
        gotChildSignalInterrupt ifTrue:[
46a848d466b5 select: wake up readFDs if readable only;
Claus Gittinger <cg@exept.de>
parents: 7495
diff changeset
   673
            gotChildSignalInterrupt := false.
46a848d466b5 select: wake up readFDs if readable only;
Claus Gittinger <cg@exept.de>
parents: 7495
diff changeset
   674
            self handleChildSignalInterrupt
46a848d466b5 select: wake up readFDs if readable only;
Claus Gittinger <cg@exept.de>
parents: 7495
diff changeset
   675
        ].
46a848d466b5 select: wake up readFDs if readable only;
Claus Gittinger <cg@exept.de>
parents: 7495
diff changeset
   676
        wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
46a848d466b5 select: wake up readFDs if readable only;
Claus Gittinger <cg@exept.de>
parents: 7495
diff changeset
   677
        ^ self
10
claus
parents: 3
diff changeset
   678
    ].
claus
parents: 3
diff changeset
   679
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   680
    pri := p priority.
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   681
302
1f76060d58a4 *** empty log message ***
claus
parents: 271
diff changeset
   682
    "
1f76060d58a4 *** empty log message ***
claus
parents: 271
diff changeset
   683
     want to give control to the process p.
10
claus
parents: 3
diff changeset
   684
     If the switched-to processes priority is lower than the
claus
parents: 3
diff changeset
   685
     userSchedulingPriority, we have to make certain, that the 
claus
parents: 3
diff changeset
   686
     next input or timer will bring us back for a reschedule.
claus
parents: 3
diff changeset
   687
     This is done by enabling ioInterrupts for all file descriptors.
302
1f76060d58a4 *** empty log message ***
claus
parents: 271
diff changeset
   688
     If ioInterrupts are not available (OS does not support them), 
1f76060d58a4 *** empty log message ***
claus
parents: 271
diff changeset
   689
     we schedule a timer interrupt to interrupt us after 1/20s of a second
1f76060d58a4 *** empty log message ***
claus
parents: 271
diff changeset
   690
     - effectively polling the filedescriptors 20 times a second.
1f76060d58a4 *** empty log message ***
claus
parents: 271
diff changeset
   691
     (which is bad, since low prio processes will be hurt in performance)
1f76060d58a4 *** empty log message ***
claus
parents: 271
diff changeset
   692
     Therefore, dont let benchmarks run with low prio ...
1f76060d58a4 *** empty log message ***
claus
parents: 271
diff changeset
   693
231
fd0e55e352f8 cleanup
claus
parents: 217
diff changeset
   694
     Higher prio processes must be suspended, 
302
1f76060d58a4 *** empty log message ***
claus
parents: 271
diff changeset
   695
     same prio ones must yield or suspend to get back control
1f76060d58a4 *** empty log message ***
claus
parents: 271
diff changeset
   696
    "
10
claus
parents: 3
diff changeset
   697
93
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   698
"
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   699
 uncommenting this will make timeouts interrupt the current process
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   700
 (i.e. as if the interrupt runs at TimingPrio); 
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   701
 if left commented, they are handled at UserSchedulingPrio.
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   702
 this will all change, when timeouts are removed and all is process driven
231
fd0e55e352f8 cleanup
claus
parents: 217
diff changeset
   703
 (a future version will have a process running to handle a timeout queue)
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   704
"
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   705
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   706
"
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   707
    pri < TimingPriority ifTrue:[
7510
46a848d466b5 select: wake up readFDs if readable only;
Claus Gittinger <cg@exept.de>
parents: 7495
diff changeset
   708
        anyTimeouts ifTrue:[
46a848d466b5 select: wake up readFDs if readable only;
Claus Gittinger <cg@exept.de>
parents: 7495
diff changeset
   709
            millis := self timeToNextTimeout.
46a848d466b5 select: wake up readFDs if readable only;
Claus Gittinger <cg@exept.de>
parents: 7495
diff changeset
   710
            millis == 0 ifTrue:[
46a848d466b5 select: wake up readFDs if readable only;
Claus Gittinger <cg@exept.de>
parents: 7495
diff changeset
   711
                wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
46a848d466b5 select: wake up readFDs if readable only;
Claus Gittinger <cg@exept.de>
parents: 7495
diff changeset
   712
                ^ self
46a848d466b5 select: wake up readFDs if readable only;
Claus Gittinger <cg@exept.de>
parents: 7495
diff changeset
   713
            ]
46a848d466b5 select: wake up readFDs if readable only;
Claus Gittinger <cg@exept.de>
parents: 7495
diff changeset
   714
        ]
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   715
    ].
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   716
"
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   717
93
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   718
    "
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   719
     if the process to run has a lower than UserInterruptPriority,
302
1f76060d58a4 *** empty log message ***
claus
parents: 271
diff changeset
   720
     arrange for an interrupt to occur on I/O.
231
fd0e55e352f8 cleanup
claus
parents: 217
diff changeset
   721
     This is done by enabling IO-signals (if the OS supports them)
93
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   722
     or by installing a poll-interrupt after 50ms (if the OS does not).
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   723
    "
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   724
    pri < UserInterruptPriority ifTrue:[
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   725
    
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   726
"comment out this if above is uncommented"
7510
46a848d466b5 select: wake up readFDs if readable only;
Claus Gittinger <cg@exept.de>
parents: 7495
diff changeset
   727
        anyTimeouts ifTrue:[
46a848d466b5 select: wake up readFDs if readable only;
Claus Gittinger <cg@exept.de>
parents: 7495
diff changeset
   728
            millis := self timeToNextTimeout.
46a848d466b5 select: wake up readFDs if readable only;
Claus Gittinger <cg@exept.de>
parents: 7495
diff changeset
   729
            millis == 0 ifTrue:[
46a848d466b5 select: wake up readFDs if readable only;
Claus Gittinger <cg@exept.de>
parents: 7495
diff changeset
   730
                wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
46a848d466b5 select: wake up readFDs if readable only;
Claus Gittinger <cg@exept.de>
parents: 7495
diff changeset
   731
                ^ self
46a848d466b5 select: wake up readFDs if readable only;
Claus Gittinger <cg@exept.de>
parents: 7495
diff changeset
   732
            ].
46a848d466b5 select: wake up readFDs if readable only;
Claus Gittinger <cg@exept.de>
parents: 7495
diff changeset
   733
        ].
93
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   734
"---"
10
claus
parents: 3
diff changeset
   735
7510
46a848d466b5 select: wake up readFDs if readable only;
Claus Gittinger <cg@exept.de>
parents: 7495
diff changeset
   736
        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
   737
"/            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
   738
"/                (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
   739
"/                    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
   740
"/                ].
02f9aa61f71b ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
   741
"/            ].
7510
46a848d466b5 select: wake up readFDs if readable only;
Claus Gittinger <cg@exept.de>
parents: 7495
diff changeset
   742
        ] ifFalse:[
46a848d466b5 select: wake up readFDs if readable only;
Claus Gittinger <cg@exept.de>
parents: 7495
diff changeset
   743
            millis notNil ifTrue:[
46a848d466b5 select: wake up readFDs if readable only;
Claus Gittinger <cg@exept.de>
parents: 7495
diff changeset
   744
                millis := millis min:EventPollingInterval
46a848d466b5 select: wake up readFDs if readable only;
Claus Gittinger <cg@exept.de>
parents: 7495
diff changeset
   745
            ] ifFalse:[
46a848d466b5 select: wake up readFDs if readable only;
Claus Gittinger <cg@exept.de>
parents: 7495
diff changeset
   746
                millis := EventPollingInterval
46a848d466b5 select: wake up readFDs if readable only;
Claus Gittinger <cg@exept.de>
parents: 7495
diff changeset
   747
            ]
46a848d466b5 select: wake up readFDs if readable only;
Claus Gittinger <cg@exept.de>
parents: 7495
diff changeset
   748
        ]
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   749
    ].
10
claus
parents: 3
diff changeset
   750
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   751
    millis notNil ifTrue:[
7510
46a848d466b5 select: wake up readFDs if readable only;
Claus Gittinger <cg@exept.de>
parents: 7495
diff changeset
   752
        "schedule a clock interrupt after millis milliseconds"
46a848d466b5 select: wake up readFDs if readable only;
Claus Gittinger <cg@exept.de>
parents: 7495
diff changeset
   753
        OperatingSystem enableTimer:millis rounded.
10
claus
parents: 3
diff changeset
   754
    ].
claus
parents: 3
diff changeset
   755
3722
1114c2014bea added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents: 3718
diff changeset
   756
    scheduledProcesses notNil ifTrue:[
7510
46a848d466b5 select: wake up readFDs if readable only;
Claus Gittinger <cg@exept.de>
parents: 7495
diff changeset
   757
        scheduledProcesses add:p
3722
1114c2014bea added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents: 3718
diff changeset
   758
    ].
1114c2014bea added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents: 3718
diff changeset
   759
231
fd0e55e352f8 cleanup
claus
parents: 217
diff changeset
   760
    "
fd0e55e352f8 cleanup
claus
parents: 217
diff changeset
   761
     now let the process run - will come back here by reschedule
fd0e55e352f8 cleanup
claus
parents: 217
diff changeset
   762
     from ioInterrupt or timerInterrupt ... (running at max+1)
fd0e55e352f8 cleanup
claus
parents: 217
diff changeset
   763
    "
10
claus
parents: 3
diff changeset
   764
    self threadSwitch:p.
claus
parents: 3
diff changeset
   765
804
264d440a67a0 Fixes when useIOInterrupts == true.
Stefan Vogel <sv@exept.de>
parents: 786
diff changeset
   766
    "... when we arrive here, we are back on stage.
7510
46a848d466b5 select: wake up readFDs if readable only;
Claus Gittinger <cg@exept.de>
parents: 7495
diff changeset
   767
         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
   768
    "
10
claus
parents: 3
diff changeset
   769
claus
parents: 3
diff changeset
   770
    millis notNil ifTrue:[
7510
46a848d466b5 select: wake up readFDs if readable only;
Claus Gittinger <cg@exept.de>
parents: 7495
diff changeset
   771
        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
   772
    ].
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
   773
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
   774
    "/ 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
   775
    gotChildSignalInterrupt ifTrue:[
7510
46a848d466b5 select: wake up readFDs if readable only;
Claus Gittinger <cg@exept.de>
parents: 7495
diff changeset
   776
        gotChildSignalInterrupt := false.
46a848d466b5 select: wake up readFDs if readable only;
Claus Gittinger <cg@exept.de>
parents: 7495
diff changeset
   777
        self handleChildSignalInterrupt
804
264d440a67a0 Fixes when useIOInterrupts == true.
Stefan Vogel <sv@exept.de>
parents: 786
diff changeset
   778
    ].
264d440a67a0 Fixes when useIOInterrupts == true.
Stefan Vogel <sv@exept.de>
parents: 786
diff changeset
   779
264d440a67a0 Fixes when useIOInterrupts == true.
Stefan Vogel <sv@exept.de>
parents: 786
diff changeset
   780
    "/ check for new input
264d440a67a0 Fixes when useIOInterrupts == true.
Stefan Vogel <sv@exept.de>
parents: 786
diff changeset
   781
3745
3fd121f2e74e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3740
diff changeset
   782
    OperatingSystem unblockInterrupts.
3fd121f2e74e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3740
diff changeset
   783
804
264d440a67a0 Fixes when useIOInterrupts == true.
Stefan Vogel <sv@exept.de>
parents: 786
diff changeset
   784
    (gotIOInterrupt or:[useIOInterrupts not]) ifTrue:[
7510
46a848d466b5 select: wake up readFDs if readable only;
Claus Gittinger <cg@exept.de>
parents: 7495
diff changeset
   785
        gotIOInterrupt := false.
46a848d466b5 select: wake up readFDs if readable only;
Claus Gittinger <cg@exept.de>
parents: 7495
diff changeset
   786
        self checkForIOWithTimeout:0.
3745
3fd121f2e74e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3740
diff changeset
   787
    ].
3fd121f2e74e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3740
diff changeset
   788
3fd121f2e74e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3740
diff changeset
   789
    wasBlocked ifTrue:[OperatingSystem blockInterrupts].
768
20434b8239f3 stefans modalBox changes (no more polling)
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
   790
3722
1114c2014bea added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents: 3718
diff changeset
   791
    "Modified: / 12.4.1996 / 10:14:18 / stefan"
1114c2014bea added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents: 3718
diff changeset
   792
    "Modified: / 3.8.1998 / 21:54:01 / cg"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   793
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   794
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   795
dispatchLoop
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   796
    "central dispatch loop; the scheduler process is always staying in
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   797
     this method, looping forever."
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   798
806
409a8c189e01 also handle termination of the scheduler process
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
   799
    |dispatchAction handlerAction ignoredSignals|
786
789e2f20de44 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 780
diff changeset
   800
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   801
    "avoid confusion if entered twice"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   802
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   803
    dispatching == true ifTrue:[^ self].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   804
    dispatching := true.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   805
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
   806
    "/ 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
   807
    "/ 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
   808
    "/ (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
   809
    "/  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
   810
786
789e2f20de44 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 780
diff changeset
   811
    dispatchAction := [self dispatch].
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
   812
806
409a8c189e01 also handle termination of the scheduler process
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
   813
    handlerAction := [:ex |
8523
f15feab27431 use class based exceptions
Stefan Vogel <sv@exept.de>
parents: 8504
diff changeset
   814
                        ('Processor [info]: ignored signal (', ex signal printString, ')') infoPrintCR.
f15feab27431 use class based exceptions
Stefan Vogel <sv@exept.de>
parents: 8504
diff changeset
   815
                        ex return
f15feab27431 use class based exceptions
Stefan Vogel <sv@exept.de>
parents: 8504
diff changeset
   816
                     ].
806
409a8c189e01 also handle termination of the scheduler process
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
   817
409a8c189e01 also handle termination of the scheduler process
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
   818
    ignoredSignals := SignalSet 
8523
f15feab27431 use class based exceptions
Stefan Vogel <sv@exept.de>
parents: 8504
diff changeset
   819
                        with:TerminateProcessRequest
8675
ceef81bb2d0c AbortOperationRequest is now a subclass (and child-Exception) of.
Stefan Vogel <sv@exept.de>
parents: 8600
diff changeset
   820
                        with:AbortAllOperationRequest.
786
789e2f20de44 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 780
diff changeset
   821
789e2f20de44 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 780
diff changeset
   822
    "/
789e2f20de44 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 780
diff changeset
   823
    "/ I made this an extra call to dispatch; this allows recompilation
789e2f20de44 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 780
diff changeset
   824
    "/  of the dispatch-handling code in the running system.
789e2f20de44 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 780
diff changeset
   825
    "/
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
   826
    [dispatching] whileTrue:[
8523
f15feab27431 use class based exceptions
Stefan Vogel <sv@exept.de>
parents: 8504
diff changeset
   827
        ignoredSignals handle:handlerAction 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
   828
    ].
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
   829
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
   830
    "/ 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
   831
    "/ 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
   832
    "/ 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
   833
2137
3e210d26d0d8 *PrintNL eliminated
Claus Gittinger <cg@exept.de>
parents: 2129
diff changeset
   834
    'Processor [info]: finish dispatch (no more processes)' infoPrintCR.
964
6d87e84d86ac in standAloneMode: exit dispatch if last process dies and no more sema/timer waits are pending
Claus Gittinger <cg@exept.de>
parents: 840
diff changeset
   835
6214
145efcef27b6 terminateProcess request now class-based
Claus Gittinger <cg@exept.de>
parents: 6044
diff changeset
   836
    "Modified: / 23.9.1996 / 14:19:56 / stefan"
145efcef27b6 terminateProcess request now class-based
Claus Gittinger <cg@exept.de>
parents: 6044
diff changeset
   837
    "Modified: / 17.11.2001 / 11:10:23 / cg"
964
6d87e84d86ac in standAloneMode: exit dispatch if last process dies and no more sema/timer waits are pending
Claus Gittinger <cg@exept.de>
parents: 840
diff changeset
   838
!
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
   839
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
   840
exitWhenNoMoreUserProcesses:aBoolean
2193
Claus Gittinger <cg@exept.de>
parents: 2191
diff changeset
   841
    "set/clear the flag, which controls if the scheduler should exit and return
Claus Gittinger <cg@exept.de>
parents: 2191
diff changeset
   842
     when the last user process finishes (and therefore exit the smalltalk system). 
Claus Gittinger <cg@exept.de>
parents: 2191
diff changeset
   843
     A userProcess is defined as a process with a non-zero processGroup.
Claus Gittinger <cg@exept.de>
parents: 2191
diff changeset
   844
     This flag is typically set for standAlone operation, to terminate the (Unix-) 
Claus Gittinger <cg@exept.de>
parents: 2191
diff changeset
   845
     process, when the last thread terminates."
Claus Gittinger <cg@exept.de>
parents: 2191
diff changeset
   846
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
   847
    exitWhenNoMoreUserProcesses := aBoolean
827
3eb3911cb63e Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents: 807
diff changeset
   848
! !
806
409a8c189e01 also handle termination of the scheduler process
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
   849
6434
f23d12900e18 category rename
Claus Gittinger <cg@exept.de>
parents: 6421
diff changeset
   850
!ProcessorScheduler methodsFor:'initialization'!
3522
291ec553ac33 restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents: 3312
diff changeset
   851
291ec553ac33 restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents: 3312
diff changeset
   852
initialize
291ec553ac33 restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents: 3312
diff changeset
   853
    "initialize the one-and-only ProcessorScheduler"
291ec553ac33 restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents: 3312
diff changeset
   854
291ec553ac33 restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents: 3312
diff changeset
   855
    |nPrios "{ Class: SmallInteger }"
291ec553ac33 restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents: 3312
diff changeset
   856
     p l|
291ec553ac33 restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents: 3312
diff changeset
   857
291ec553ac33 restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents: 3312
diff changeset
   858
    KnownProcesses isNil ifTrue:[
6376
6a3ce5694cc9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6260
diff changeset
   859
	KnownProcesses := WeakArray new:30.
6a3ce5694cc9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6260
diff changeset
   860
	KnownProcesses addDependent:self class.
6a3ce5694cc9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6260
diff changeset
   861
	KnownProcessIds := OrderedCollection new.
3522
291ec553ac33 restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents: 3312
diff changeset
   862
    ].
291ec553ac33 restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents: 3312
diff changeset
   863
291ec553ac33 restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents: 3312
diff changeset
   864
    "
291ec553ac33 restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents: 3312
diff changeset
   865
     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
   866
    "
291ec553ac33 restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents: 3312
diff changeset
   867
    nPrios := SchedulingPriority.
291ec553ac33 restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents: 3312
diff changeset
   868
    quiescentProcessLists := Array new:nPrios.
3967
5e0053fdbf52 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3917
diff changeset
   869
5e0053fdbf52 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3917
diff changeset
   870
    readFdArray := Array new:5.
5e0053fdbf52 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3917
diff changeset
   871
    readCheckArray := Array new:5.
5e0053fdbf52 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3917
diff changeset
   872
    readSemaphoreArray := Array new:5.
5e0053fdbf52 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3917
diff changeset
   873
    writeFdArray := Array new:3.
5101
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
   874
    writeCheckArray := Array new:3.
3967
5e0053fdbf52 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3917
diff changeset
   875
    writeSemaphoreArray := Array new:3.
5e0053fdbf52 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3917
diff changeset
   876
    timeoutArray := Array new:5.
5e0053fdbf52 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3917
diff changeset
   877
    timeoutSemaphoreArray := Array new:5.
5e0053fdbf52 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3917
diff changeset
   878
    timeoutActionArray := Array new:5.
5e0053fdbf52 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3917
diff changeset
   879
    timeoutProcessArray := Array new:5.
5e0053fdbf52 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3917
diff changeset
   880
3522
291ec553ac33 restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents: 3312
diff changeset
   881
    anyTimeouts := false.
291ec553ac33 restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents: 3312
diff changeset
   882
    dispatching := false.
4042
526c79cadbf8 preserve the exitWhenNoMoreUserProcesses flag setting
Claus Gittinger <cg@exept.de>
parents: 4036
diff changeset
   883
    exitWhenNoMoreUserProcesses isNil ifTrue:[
6376
6a3ce5694cc9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6260
diff changeset
   884
	exitWhenNoMoreUserProcesses := false. "/ mhmh - how about true ?
4042
526c79cadbf8 preserve the exitWhenNoMoreUserProcesses flag setting
Claus Gittinger <cg@exept.de>
parents: 4036
diff changeset
   885
    ].
3522
291ec553ac33 restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents: 3312
diff changeset
   886
    useIOInterrupts := OperatingSystem supportsIOInterrupts.
291ec553ac33 restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents: 3312
diff changeset
   887
    gotIOInterrupt := false.
291ec553ac33 restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents: 3312
diff changeset
   888
    osChildExitActions := Dictionary new.
291ec553ac33 restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents: 3312
diff changeset
   889
    gotChildSignalInterrupt := false.
291ec553ac33 restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents: 3312
diff changeset
   890
291ec553ac33 restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents: 3312
diff changeset
   891
    "
291ec553ac33 restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents: 3312
diff changeset
   892
     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
   893
     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
   894
     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
   895
     for a runnable process.
291ec553ac33 restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents: 3312
diff changeset
   896
    "
291ec553ac33 restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents: 3312
diff changeset
   897
    currentPriority := SchedulingPriority.
291ec553ac33 restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents: 3312
diff changeset
   898
    p := Process basicNew.
291ec553ac33 restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents: 3312
diff changeset
   899
    p setId:0 state:#run.
291ec553ac33 restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents: 3312
diff changeset
   900
    p setPriority:currentPriority.
291ec553ac33 restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents: 3312
diff changeset
   901
    p name:'scheduler'.
4879
a4fc6ad599f6 checkin from browser
ca
parents: 4715
diff changeset
   902
    p beSystemProcess.
3522
291ec553ac33 restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents: 3312
diff changeset
   903
291ec553ac33 restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents: 3312
diff changeset
   904
    scheduler := activeProcess := p.
291ec553ac33 restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents: 3312
diff changeset
   905
    activeProcessId := 0.
291ec553ac33 restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents: 3312
diff changeset
   906
291ec553ac33 restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents: 3312
diff changeset
   907
    quiescentProcessLists at:currentPriority put:(l := LinkedList new).
291ec553ac33 restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents: 3312
diff changeset
   908
    l add:p.
291ec553ac33 restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents: 3312
diff changeset
   909
291ec553ac33 restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents: 3312
diff changeset
   910
    "
291ec553ac33 restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents: 3312
diff changeset
   911
     let me handle IO and timer interrupts
291ec553ac33 restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents: 3312
diff changeset
   912
    "
5406
4a6995b61c0e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5396
diff changeset
   913
    useIOInterrupts ifTrue:[ObjectMemory ioInterruptHandler:self].
3522
291ec553ac33 restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents: 3312
diff changeset
   914
    ObjectMemory timerInterruptHandler:self.
291ec553ac33 restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents: 3312
diff changeset
   915
    ObjectMemory childSignalInterruptHandler:self.
291ec553ac33 restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents: 3312
diff changeset
   916
3967
5e0053fdbf52 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3917
diff changeset
   917
    "Modified: / 7.1.1997 / 16:48:26 / stefan"
5e0053fdbf52 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3917
diff changeset
   918
    "Modified: / 4.2.1999 / 13:08:39 / cg"
3522
291ec553ac33 restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents: 3312
diff changeset
   919
!
291ec553ac33 restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents: 3312
diff changeset
   920
291ec553ac33 restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents: 3312
diff changeset
   921
reinitialize
291ec553ac33 restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents: 3312
diff changeset
   922
    "all previous processes (except those marked as restartable) are made dead 
291ec553ac33 restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents: 3312
diff changeset
   923
     - 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
   924
     especially, windowgroups have to.
291ec553ac33 restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents: 3312
diff changeset
   925
     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
   926
     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
   927
     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
   928
     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
   929
     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
   930
     In praxis, this is not much of a problem, since in almost every case,
291ec553ac33 restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents: 3312
diff changeset
   931
     the computation state can be saved in some object, and processing be 
291ec553ac33 restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents: 3312
diff changeset
   932
     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
   933
3525
26fe903e0250 oops - no need for last change
Claus Gittinger <cg@exept.de>
parents: 3522
diff changeset
   934
    |processesToRestart|
26fe903e0250 oops - no need for last change
Claus Gittinger <cg@exept.de>
parents: 3522
diff changeset
   935
3522
291ec553ac33 restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents: 3312
diff changeset
   936
    "
291ec553ac33 restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents: 3312
diff changeset
   937
     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
   938
    "
291ec553ac33 restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents: 3312
diff changeset
   939
    processesToRestart := OrderedCollection new.
291ec553ac33 restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents: 3312
diff changeset
   940
    KnownProcesses do:[:p |
5101
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
   941
	(p notNil and:[p ~~ 0]) ifTrue:[
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
   942
	    "how, exactly should this be done ?"
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
   943
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
   944
	    p isRestartable == true ifTrue:[
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
   945
		p nextLink:nil.
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
   946
		processesToRestart add:p
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
   947
	    ] ifFalse:[
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
   948
		p setId:nil state:#dead
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
   949
	    ]
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
   950
	].
3522
291ec553ac33 restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents: 3312
diff changeset
   951
    ].
291ec553ac33 restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents: 3312
diff changeset
   952
    scheduler setId:nil state:#dead. 
291ec553ac33 restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents: 3312
diff changeset
   953
291ec553ac33 restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents: 3312
diff changeset
   954
    "
291ec553ac33 restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents: 3312
diff changeset
   955
     now, start from scratch
291ec553ac33 restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents: 3312
diff changeset
   956
    "
291ec553ac33 restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents: 3312
diff changeset
   957
    KnownProcesses := nil.
291ec553ac33 restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents: 3312
diff changeset
   958
    self initialize.
291ec553ac33 restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents: 3312
diff changeset
   959
3525
26fe903e0250 oops - no need for last change
Claus Gittinger <cg@exept.de>
parents: 3522
diff changeset
   960
    processesToRestart do:[:p |
5101
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
   961
	p imageRestart
3522
291ec553ac33 restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents: 3312
diff changeset
   962
    ]
291ec553ac33 restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents: 3312
diff changeset
   963
3525
26fe903e0250 oops - no need for last change
Claus Gittinger <cg@exept.de>
parents: 3522
diff changeset
   964
    "Modified: / 7.6.1998 / 02:23:56 / cg"
3522
291ec553ac33 restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents: 3312
diff changeset
   965
! !
291ec553ac33 restart of restartableProcesses must be done after
Claus Gittinger <cg@exept.de>
parents: 3312
diff changeset
   966
3777
f351744c575f fix terminate/interrupt/reschedule while in osWait (win32)
Claus Gittinger <cg@exept.de>
parents: 3745
diff changeset
   967
!ProcessorScheduler methodsFor:'native thread support'!
f351744c575f fix terminate/interrupt/reschedule while in osWait (win32)
Claus Gittinger <cg@exept.de>
parents: 3745
diff changeset
   968
7842
c6ce40656157 preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents: 7761
diff changeset
   969
vmResumeInterrupt:id
c6ce40656157 preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents: 7761
diff changeset
   970
    "signal from VM to resume a thread after finish of an osWait or wrapCall-wait. 
c6ce40656157 preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents: 7761
diff changeset
   971
     MUST be invoked with interrupts blocked.
c6ce40656157 preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents: 7761
diff changeset
   972
     This is only used with native threads."
c6ce40656157 preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents: 7761
diff changeset
   973
8504
93b46834c68f #unblockInterrupts returns the prvious blocking state
Stefan Vogel <sv@exept.de>
parents: 8494
diff changeset
   974
    <context: #return>
93b46834c68f #unblockInterrupts returns the prvious blocking state
Stefan Vogel <sv@exept.de>
parents: 8494
diff changeset
   975
7842
c6ce40656157 preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents: 7761
diff changeset
   976
    |index pri aProcess l|
c6ce40656157 preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents: 7761
diff changeset
   977
c6ce40656157 preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents: 7761
diff changeset
   978
    OperatingSystem interruptsBlocked ifFalse:[
c6ce40656157 preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents: 7761
diff changeset
   979
        MiniDebugger 
c6ce40656157 preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents: 7761
diff changeset
   980
            enterWithMessage:'vmResumeInterrupt with no interruptsBlocked'
c6ce40656157 preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents: 7761
diff changeset
   981
            mayProceed:true.
c6ce40656157 preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents: 7761
diff changeset
   982
    ].
c6ce40656157 preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents: 7761
diff changeset
   983
c6ce40656157 preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents: 7761
diff changeset
   984
    index := KnownProcessIds identityIndexOf:id.
c6ce40656157 preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents: 7761
diff changeset
   985
    index ~~ 0 ifTrue:[
c6ce40656157 preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents: 7761
diff changeset
   986
        aProcess := KnownProcesses at:index.
c6ce40656157 preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents: 7761
diff changeset
   987
        "/
c6ce40656157 preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents: 7761
diff changeset
   988
        "/ CG: the situation below may happen, if the wrapCall
c6ce40656157 preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents: 7761
diff changeset
   989
        "/ finishes before the process was layed to sleep
c6ce40656157 preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents: 7761
diff changeset
   990
        "/ (i.e. schedulerIRQ arrives before the threadSwitch was finished).
c6ce40656157 preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents: 7761
diff changeset
   991
        "/ In that case, simply resume it and everything is OK.
c6ce40656157 preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents: 7761
diff changeset
   992
        "/
c6ce40656157 preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents: 7761
diff changeset
   993
        pri := aProcess priority.
c6ce40656157 preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents: 7761
diff changeset
   994
        l := quiescentProcessLists at:pri.
c6ce40656157 preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents: 7761
diff changeset
   995
        "if already running, ignore"
c6ce40656157 preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents: 7761
diff changeset
   996
        l notNil ifTrue:[
c6ce40656157 preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents: 7761
diff changeset
   997
            (l identityIndexOf:aProcess) ~~ 0 ifTrue:[
c6ce40656157 preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents: 7761
diff changeset
   998
                aProcess state == #wrapWait ifTrue:[
7845
5b8ac9a628e8 renamed immediateInterrupt & resumeImmediateInterrupt
ca
parents: 7844
diff changeset
   999
                   'ProcSched [info]: resumeIRQ for wrapWait process ' infoPrintCR.
5b8ac9a628e8 renamed immediateInterrupt & resumeImmediateInterrupt
ca
parents: 7844
diff changeset
  1000
                    aProcess state:#run.
5b8ac9a628e8 renamed immediateInterrupt & resumeImmediateInterrupt
ca
parents: 7844
diff changeset
  1001
                    ^ self
5b8ac9a628e8 renamed immediateInterrupt & resumeImmediateInterrupt
ca
parents: 7844
diff changeset
  1002
                ].
5b8ac9a628e8 renamed immediateInterrupt & resumeImmediateInterrupt
ca
parents: 7844
diff changeset
  1003
                aProcess state == #osWait ifTrue:[
5b8ac9a628e8 renamed immediateInterrupt & resumeImmediateInterrupt
ca
parents: 7844
diff changeset
  1004
                   'ProcSched [info]: resumeIRQ for osWait process ' infoPrintCR.
7842
c6ce40656157 preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents: 7761
diff changeset
  1005
                    aProcess state:#run.
c6ce40656157 preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents: 7761
diff changeset
  1006
                    ^ self
c6ce40656157 preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents: 7761
diff changeset
  1007
                ].
7845
5b8ac9a628e8 renamed immediateInterrupt & resumeImmediateInterrupt
ca
parents: 7844
diff changeset
  1008
                aProcess state == #stopped ifTrue:[
5b8ac9a628e8 renamed immediateInterrupt & resumeImmediateInterrupt
ca
parents: 7844
diff changeset
  1009
                   'ProcSched [info]: resumeIRQ for stopped process ' infoPrintCR.
5b8ac9a628e8 renamed immediateInterrupt & resumeImmediateInterrupt
ca
parents: 7844
diff changeset
  1010
                    aProcess state:#run.
5b8ac9a628e8 renamed immediateInterrupt & resumeImmediateInterrupt
ca
parents: 7844
diff changeset
  1011
                    ^ self
5b8ac9a628e8 renamed immediateInterrupt & resumeImmediateInterrupt
ca
parents: 7844
diff changeset
  1012
                ].
5b8ac9a628e8 renamed immediateInterrupt & resumeImmediateInterrupt
ca
parents: 7844
diff changeset
  1013
                'ProcSched [info]: oops - resumeIRQ for already running process ' infoPrint.
5b8ac9a628e8 renamed immediateInterrupt & resumeImmediateInterrupt
ca
parents: 7844
diff changeset
  1014
                aProcess id infoPrint. 
5b8ac9a628e8 renamed immediateInterrupt & resumeImmediateInterrupt
ca
parents: 7844
diff changeset
  1015
                ' in state ' infoPrint.
5b8ac9a628e8 renamed immediateInterrupt & resumeImmediateInterrupt
ca
parents: 7844
diff changeset
  1016
                aProcess state infoPrintCR.
7842
c6ce40656157 preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents: 7761
diff changeset
  1017
                ^ self
c6ce40656157 preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents: 7761
diff changeset
  1018
            ]
c6ce40656157 preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents: 7761
diff changeset
  1019
        ] ifFalse:[
c6ce40656157 preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents: 7761
diff changeset
  1020
            l := LinkedList new.
c6ce40656157 preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents: 7761
diff changeset
  1021
            quiescentProcessLists at:pri put:l.
c6ce40656157 preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents: 7761
diff changeset
  1022
        ].
c6ce40656157 preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents: 7761
diff changeset
  1023
        l addLast:aProcess.
c6ce40656157 preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents: 7761
diff changeset
  1024
        aProcess state:#run.
c6ce40656157 preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents: 7761
diff changeset
  1025
    ] ifFalse:[
c6ce40656157 preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents: 7761
diff changeset
  1026
        'ProcSched [info]: oops - resumeIRQ for unknown process: ' infoPrint.
c6ce40656157 preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents: 7761
diff changeset
  1027
        id infoPrintCR.
c6ce40656157 preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents: 7761
diff changeset
  1028
    ]
c6ce40656157 preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents: 7761
diff changeset
  1029
c6ce40656157 preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents: 7761
diff changeset
  1030
    "Modified: / 28.9.1998 / 11:36:53 / cg"
c6ce40656157 preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents: 7761
diff changeset
  1031
!
c6ce40656157 preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents: 7761
diff changeset
  1032
7844
906062102891 preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents: 7843
diff changeset
  1033
vmSuspendInterrupt:whyCode
7842
c6ce40656157 preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents: 7761
diff changeset
  1034
    "signal from VM to suspend a thread into a certain state.
c6ce40656157 preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents: 7761
diff changeset
  1035
     Invoked before the VM switches to the scheduler process. 
c6ce40656157 preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents: 7761
diff changeset
  1036
     MUST be invoked with interrupts blocked.
c6ce40656157 preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents: 7761
diff changeset
  1037
     This is only used with native threads."
c6ce40656157 preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents: 7761
diff changeset
  1038
8504
93b46834c68f #unblockInterrupts returns the prvious blocking state
Stefan Vogel <sv@exept.de>
parents: 8494
diff changeset
  1039
    <context: #return>
93b46834c68f #unblockInterrupts returns the prvious blocking state
Stefan Vogel <sv@exept.de>
parents: 8494
diff changeset
  1040
7843
922a4285375a preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents: 7842
diff changeset
  1041
    |pri l newState|
7842
c6ce40656157 preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents: 7761
diff changeset
  1042
c6ce40656157 preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents: 7761
diff changeset
  1043
    OperatingSystem interruptsBlocked ifFalse:[
c6ce40656157 preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents: 7761
diff changeset
  1044
        MiniDebugger 
c6ce40656157 preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents: 7761
diff changeset
  1045
            enterWithMessage:'immediateInterrupt with no interruptsBlocked'
c6ce40656157 preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents: 7761
diff changeset
  1046
            mayProceed:true.
c6ce40656157 preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents: 7761
diff changeset
  1047
    ].
c6ce40656157 preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents: 7761
diff changeset
  1048
7844
906062102891 preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents: 7843
diff changeset
  1049
    (whyCode == 2) ifTrue:[
7843
922a4285375a preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents: 7842
diff changeset
  1050
         newState := #wrapWait.
922a4285375a preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents: 7842
diff changeset
  1051
    ] ifFalse:[
7844
906062102891 preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents: 7843
diff changeset
  1052
        (whyCode == 3) ifTrue:[
7843
922a4285375a preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents: 7842
diff changeset
  1053
            newState := #osWait.
922a4285375a preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents: 7842
diff changeset
  1054
        ] ifFalse:[
922a4285375a preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents: 7842
diff changeset
  1055
            newState := #stopped.
922a4285375a preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents: 7842
diff changeset
  1056
        ].
922a4285375a preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents: 7842
diff changeset
  1057
    ].
7842
c6ce40656157 preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents: 7761
diff changeset
  1058
    activeProcess setStateTo:newState if:#active.
c6ce40656157 preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents: 7761
diff changeset
  1059
c6ce40656157 preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents: 7761
diff changeset
  1060
    pri := activeProcess priority.
c6ce40656157 preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents: 7761
diff changeset
  1061
    l := quiescentProcessLists at:pri.
c6ce40656157 preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents: 7761
diff changeset
  1062
c6ce40656157 preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents: 7761
diff changeset
  1063
    "notice: this is slightly faster than putting the if-code into
c6ce40656157 preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents: 7761
diff changeset
  1064
     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
  1065
    "
c6ce40656157 preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents: 7761
diff changeset
  1066
    (l isNil or:[(l remove:activeProcess ifAbsent:nil) isNil]) ifTrue:[
c6ce40656157 preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents: 7761
diff changeset
  1067
        "/ 'Processor [warning]: bad vmSuspendInterrupt: not on run list' errorPrintCR.
c6ce40656157 preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents: 7761
diff changeset
  1068
        MiniDebugger enterWithMessage:'bad vmSuspendInterrupt: not on run list' mayProceed:true.
c6ce40656157 preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents: 7761
diff changeset
  1069
        ^ self
c6ce40656157 preps to rename immediateInterrupt and resumeImmediateInterrupt
ca
parents: 7761
diff changeset
  1070
    ].
3777
f351744c575f fix terminate/interrupt/reschedule while in osWait (win32)
Claus Gittinger <cg@exept.de>
parents: 3745
diff changeset
  1071
! !
f351744c575f fix terminate/interrupt/reschedule while in osWait (win32)
Claus Gittinger <cg@exept.de>
parents: 3745
diff changeset
  1072
827
3eb3911cb63e Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents: 807
diff changeset
  1073
!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
  1074
3eb3911cb63e Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents: 807
diff changeset
  1075
childSignalInterrupt
2116
1bcb6ee86fca fixed pending sigChild problem;
Claus Gittinger <cg@exept.de>
parents: 2111
diff changeset
  1076
    "{ Pragma: +returnable }"
1bcb6ee86fca fixed pending sigChild problem;
Claus Gittinger <cg@exept.de>
parents: 2111
diff changeset
  1077
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
  1078
    "child changed state - switch to scheduler process which will decide 
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
  1079
     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
  1080
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
  1081
    gotChildSignalInterrupt := true.
2966
856dfc8a294a lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2962
diff changeset
  1082
    activeProcess ~~ scheduler ifTrue:[
5101
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  1083
	interruptedProcess := activeProcess.
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  1084
	self threadSwitch:scheduler
2966
856dfc8a294a lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2962
diff changeset
  1085
    ]
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
  1086
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
  1087
    "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
  1088
!
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
  1089
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
  1090
handleChildSignalInterrupt
827
3eb3911cb63e Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents: 807
diff changeset
  1091
    "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
  1092
     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
  1093
523533898acd Reset sigCHLD interrupt handler, when no more processes are being waited for.
Stefan Vogel <sv@exept.de>
parents: 829
diff changeset
  1094
    |osProcessStatus blocking wasBlocked|
827
3eb3911cb63e Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents: 807
diff changeset
  1095
840
523533898acd Reset sigCHLD interrupt handler, when no more processes are being waited for.
Stefan Vogel <sv@exept.de>
parents: 829
diff changeset
  1096
    blocking := OperatingSystem blockingChildProcessWait.
827
3eb3911cb63e Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents: 807
diff changeset
  1097
840
523533898acd Reset sigCHLD interrupt handler, when no more processes are being waited for.
Stefan Vogel <sv@exept.de>
parents: 829
diff changeset
  1098
    "/ 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
  1099
    wasBlocked := OperatingSystem blockInterrupts.
827
3eb3911cb63e Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents: 807
diff changeset
  1100
    [
6421
58dca33cf0fc #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 6376
diff changeset
  1101
        [
58dca33cf0fc #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 6376
diff changeset
  1102
            osProcessStatus := OperatingSystem childProcessWait:blocking pid:nil.
58dca33cf0fc #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 6376
diff changeset
  1103
            osProcessStatus notNil ifTrue:[
58dca33cf0fc #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 6376
diff changeset
  1104
                |pid action|
58dca33cf0fc #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 6376
diff changeset
  1105
58dca33cf0fc #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 6376
diff changeset
  1106
                pid := osProcessStatus pid.
58dca33cf0fc #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 6376
diff changeset
  1107
                osProcessStatus stillAlive ifTrue:[
58dca33cf0fc #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 6376
diff changeset
  1108
                    action := osChildExitActions at:pid ifAbsent:nil.
58dca33cf0fc #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 6376
diff changeset
  1109
                ] ifFalse:[
58dca33cf0fc #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 6376
diff changeset
  1110
                    action := osChildExitActions removeKey:pid ifAbsent:nil.
58dca33cf0fc #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 6376
diff changeset
  1111
                ].
58dca33cf0fc #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 6376
diff changeset
  1112
                action notNil ifTrue:[
58dca33cf0fc #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 6376
diff changeset
  1113
                    action value:osProcessStatus
58dca33cf0fc #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 6376
diff changeset
  1114
                ].
58dca33cf0fc #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 6376
diff changeset
  1115
            ].
58dca33cf0fc #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 6376
diff changeset
  1116
58dca33cf0fc #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 6376
diff changeset
  1117
            "/ if pollChildProcesses does block, poll only one status change.
58dca33cf0fc #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 6376
diff changeset
  1118
            "/ we will get another SIGCHLD for other status changes.
58dca33cf0fc #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 6376
diff changeset
  1119
58dca33cf0fc #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 6376
diff changeset
  1120
            osProcessStatus notNil and:[blocking not]
58dca33cf0fc #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 6376
diff changeset
  1121
        ] whileTrue.
58dca33cf0fc #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 6376
diff changeset
  1122
58dca33cf0fc #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 6376
diff changeset
  1123
        "/ if there are no more waiters, disable SIGCHILD handler.
58dca33cf0fc #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 6376
diff changeset
  1124
        "/ this helps us with synchronous waiters (e.g. pclose),
58dca33cf0fc #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 6376
diff changeset
  1125
        "/ But they should block SIGCHLD anyway.
58dca33cf0fc #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 6376
diff changeset
  1126
58dca33cf0fc #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 6376
diff changeset
  1127
        osChildExitActions isEmpty ifTrue:[
58dca33cf0fc #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 6376
diff changeset
  1128
            OperatingSystem disableChildSignalInterrupts.
58dca33cf0fc #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 6376
diff changeset
  1129
        ].
58dca33cf0fc #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 6376
diff changeset
  1130
    ] ensure:[
58dca33cf0fc #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 6376
diff changeset
  1131
        wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
1032
924c177085f8 care to reenable interrupts
Claus Gittinger <cg@exept.de>
parents: 1001
diff changeset
  1132
    ]
827
3eb3911cb63e Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents: 807
diff changeset
  1133
840
523533898acd Reset sigCHLD interrupt handler, when no more processes are being waited for.
Stefan Vogel <sv@exept.de>
parents: 829
diff changeset
  1134
    "Modified: 5.1.1996 / 16:56:11 / stefan"
1032
924c177085f8 care to reenable interrupts
Claus Gittinger <cg@exept.de>
parents: 1001
diff changeset
  1135
    "Modified: 28.2.1996 / 21:36:31 / cg"
1154
96bb8fce61cf Fix removeCorruptedFds to clear LastErrorNumber. Handle ChildSignalInterrupts in Scheduler's context, to avoid errno corruption.
Stefan Vogel <sv@exept.de>
parents: 1133
diff changeset
  1136
    "Created: 12.4.1996 / 10:08:21 / stefan"
827
3eb3911cb63e Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents: 807
diff changeset
  1137
!
3eb3911cb63e Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents: 807
diff changeset
  1138
2499
95392696facc Fix race condition when waiting for SIGCHLD.
Stefan Vogel <sv@exept.de>
parents: 2468
diff changeset
  1139
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
  1140
    "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
  1141
     aBlockReturningPid is evaluated and supposed to return
95392696facc Fix race condition when waiting for SIGCHLD.
Stefan Vogel <sv@exept.de>
parents: 2468
diff changeset
  1142
     the process-id of an OS-process or nil.
95392696facc Fix race condition when waiting for SIGCHLD.
Stefan Vogel <sv@exept.de>
parents: 2468
diff changeset
  1143
     To avoid race conditions, the OS-process must be started 
95392696facc Fix race condition when waiting for SIGCHLD.
Stefan Vogel <sv@exept.de>
parents: 2468
diff changeset
  1144
     within the block.
95392696facc Fix race condition when waiting for SIGCHLD.
Stefan Vogel <sv@exept.de>
parents: 2468
diff changeset
  1145
     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
  1146
     status of the OS process changes (e.g. the process terminates).
2611
9a575397bf9a fixed davids monitorPid (dont wait a second; dont do busy poll ...)
Claus Gittinger <cg@exept.de>
parents: 2534
diff changeset
  1147
     The method returns the value from aBlockReturningPid (i.e a pid or nil)."
9a575397bf9a fixed davids monitorPid (dont wait a second; dont do busy poll ...)
Claus Gittinger <cg@exept.de>
parents: 2534
diff changeset
  1148
2926
182baa3a4862 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2831
diff changeset
  1149
    |pid blocked osProcessStatus|
827
3eb3911cb63e Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents: 807
diff changeset
  1150
2962
038a8f143e49 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2926
diff changeset
  1151
    OperatingSystem supportsChildInterrupts ifTrue:[
6606
fa110cb8566c Use #ifCurtailed: instead of #valueOnUnwindDo:
Stefan Vogel <sv@exept.de>
parents: 6434
diff changeset
  1152
        "/ SIGCHLD is supported,
fa110cb8566c Use #ifCurtailed: instead of #valueOnUnwindDo:
Stefan Vogel <sv@exept.de>
parents: 6434
diff changeset
  1153
        "/ aBlock will be evaluated, as soon as a SIGCHLD interrupt for pid has been received.
fa110cb8566c Use #ifCurtailed: instead of #valueOnUnwindDo:
Stefan Vogel <sv@exept.de>
parents: 6434
diff changeset
  1154
fa110cb8566c Use #ifCurtailed: instead of #valueOnUnwindDo:
Stefan Vogel <sv@exept.de>
parents: 6434
diff changeset
  1155
        OperatingSystem enableChildSignalInterrupts.
fa110cb8566c Use #ifCurtailed: instead of #valueOnUnwindDo:
Stefan Vogel <sv@exept.de>
parents: 6434
diff changeset
  1156
        blocked := OperatingSystem blockInterrupts.
fa110cb8566c Use #ifCurtailed: instead of #valueOnUnwindDo:
Stefan Vogel <sv@exept.de>
parents: 6434
diff changeset
  1157
        pid := aBlockReturningPid value.
fa110cb8566c Use #ifCurtailed: instead of #valueOnUnwindDo:
Stefan Vogel <sv@exept.de>
parents: 6434
diff changeset
  1158
        pid notNil ifTrue:[
fa110cb8566c Use #ifCurtailed: instead of #valueOnUnwindDo:
Stefan Vogel <sv@exept.de>
parents: 6434
diff changeset
  1159
            osChildExitActions at:pid put:actionBlock.
fa110cb8566c Use #ifCurtailed: instead of #valueOnUnwindDo:
Stefan Vogel <sv@exept.de>
parents: 6434
diff changeset
  1160
        ].
fa110cb8566c Use #ifCurtailed: instead of #valueOnUnwindDo:
Stefan Vogel <sv@exept.de>
parents: 6434
diff changeset
  1161
        blocked ifFalse:[
fa110cb8566c Use #ifCurtailed: instead of #valueOnUnwindDo:
Stefan Vogel <sv@exept.de>
parents: 6434
diff changeset
  1162
            OperatingSystem unblockInterrupts.
fa110cb8566c Use #ifCurtailed: instead of #valueOnUnwindDo:
Stefan Vogel <sv@exept.de>
parents: 6434
diff changeset
  1163
        ].
840
523533898acd Reset sigCHLD interrupt handler, when no more processes are being waited for.
Stefan Vogel <sv@exept.de>
parents: 829
diff changeset
  1164
    ] ifFalse:[
6606
fa110cb8566c Use #ifCurtailed: instead of #valueOnUnwindDo:
Stefan Vogel <sv@exept.de>
parents: 6434
diff changeset
  1165
        "/ SIGCHLD is not supported, fork a high prio process 
fa110cb8566c Use #ifCurtailed: instead of #valueOnUnwindDo:
Stefan Vogel <sv@exept.de>
parents: 6434
diff changeset
  1166
        "/ to poll for for the exit of pid.
fa110cb8566c Use #ifCurtailed: instead of #valueOnUnwindDo:
Stefan Vogel <sv@exept.de>
parents: 6434
diff changeset
  1167
fa110cb8566c Use #ifCurtailed: instead of #valueOnUnwindDo:
Stefan Vogel <sv@exept.de>
parents: 6434
diff changeset
  1168
        blocked := OperatingSystem blockInterrupts.
fa110cb8566c Use #ifCurtailed: instead of #valueOnUnwindDo:
Stefan Vogel <sv@exept.de>
parents: 6434
diff changeset
  1169
        pid := aBlockReturningPid value.
fa110cb8566c Use #ifCurtailed: instead of #valueOnUnwindDo:
Stefan Vogel <sv@exept.de>
parents: 6434
diff changeset
  1170
        pid notNil ifTrue:[
fa110cb8566c Use #ifCurtailed: instead of #valueOnUnwindDo:
Stefan Vogel <sv@exept.de>
parents: 6434
diff changeset
  1171
            osChildExitActions at:pid put:actionBlock.
fa110cb8566c Use #ifCurtailed: instead of #valueOnUnwindDo:
Stefan Vogel <sv@exept.de>
parents: 6434
diff changeset
  1172
        ].
fa110cb8566c Use #ifCurtailed: instead of #valueOnUnwindDo:
Stefan Vogel <sv@exept.de>
parents: 6434
diff changeset
  1173
        blocked ifFalse:[
fa110cb8566c Use #ifCurtailed: instead of #valueOnUnwindDo:
Stefan Vogel <sv@exept.de>
parents: 6434
diff changeset
  1174
            OperatingSystem unblockInterrupts.
fa110cb8566c Use #ifCurtailed: instead of #valueOnUnwindDo:
Stefan Vogel <sv@exept.de>
parents: 6434
diff changeset
  1175
        ].
fa110cb8566c Use #ifCurtailed: instead of #valueOnUnwindDo:
Stefan Vogel <sv@exept.de>
parents: 6434
diff changeset
  1176
fa110cb8566c Use #ifCurtailed: instead of #valueOnUnwindDo:
Stefan Vogel <sv@exept.de>
parents: 6434
diff changeset
  1177
        pid notNil ifTrue:[
fa110cb8566c Use #ifCurtailed: instead of #valueOnUnwindDo:
Stefan Vogel <sv@exept.de>
parents: 6434
diff changeset
  1178
            [
fa110cb8566c Use #ifCurtailed: instead of #valueOnUnwindDo:
Stefan Vogel <sv@exept.de>
parents: 6434
diff changeset
  1179
                [
fa110cb8566c Use #ifCurtailed: instead of #valueOnUnwindDo:
Stefan Vogel <sv@exept.de>
parents: 6434
diff changeset
  1180
                  |polling myDelay t|
fa110cb8566c Use #ifCurtailed: instead of #valueOnUnwindDo:
Stefan Vogel <sv@exept.de>
parents: 6434
diff changeset
  1181
fa110cb8566c Use #ifCurtailed: instead of #valueOnUnwindDo:
Stefan Vogel <sv@exept.de>
parents: 6434
diff changeset
  1182
                  polling := true.
fa110cb8566c Use #ifCurtailed: instead of #valueOnUnwindDo:
Stefan Vogel <sv@exept.de>
parents: 6434
diff changeset
  1183
                  myDelay := Delay forMilliseconds:(t := EventPollingInterval).
fa110cb8566c Use #ifCurtailed: instead of #valueOnUnwindDo:
Stefan Vogel <sv@exept.de>
parents: 6434
diff changeset
  1184
                  [polling] whileTrue:[
fa110cb8566c Use #ifCurtailed: instead of #valueOnUnwindDo:
Stefan Vogel <sv@exept.de>
parents: 6434
diff changeset
  1185
                      t ~~ EventPollingInterval ifTrue:[
fa110cb8566c Use #ifCurtailed: instead of #valueOnUnwindDo:
Stefan Vogel <sv@exept.de>
parents: 6434
diff changeset
  1186
                          "/ interval changed -> need a new delay
fa110cb8566c Use #ifCurtailed: instead of #valueOnUnwindDo:
Stefan Vogel <sv@exept.de>
parents: 6434
diff changeset
  1187
                          myDelay delay:(t := EventPollingInterval).
fa110cb8566c Use #ifCurtailed: instead of #valueOnUnwindDo:
Stefan Vogel <sv@exept.de>
parents: 6434
diff changeset
  1188
                      ].
fa110cb8566c Use #ifCurtailed: instead of #valueOnUnwindDo:
Stefan Vogel <sv@exept.de>
parents: 6434
diff changeset
  1189
                      myDelay wait.
fa110cb8566c Use #ifCurtailed: instead of #valueOnUnwindDo:
Stefan Vogel <sv@exept.de>
parents: 6434
diff changeset
  1190
                      (osChildExitActions includesKey:pid) ifFalse:[
fa110cb8566c Use #ifCurtailed: instead of #valueOnUnwindDo:
Stefan Vogel <sv@exept.de>
parents: 6434
diff changeset
  1191
                          polling := false.
fa110cb8566c Use #ifCurtailed: instead of #valueOnUnwindDo:
Stefan Vogel <sv@exept.de>
parents: 6434
diff changeset
  1192
                      ] ifTrue:[
fa110cb8566c Use #ifCurtailed: instead of #valueOnUnwindDo:
Stefan Vogel <sv@exept.de>
parents: 6434
diff changeset
  1193
                          osProcessStatus := OperatingSystem childProcessWait:false pid:pid.
fa110cb8566c Use #ifCurtailed: instead of #valueOnUnwindDo:
Stefan Vogel <sv@exept.de>
parents: 6434
diff changeset
  1194
                          osProcessStatus notNil ifTrue:[
fa110cb8566c Use #ifCurtailed: instead of #valueOnUnwindDo:
Stefan Vogel <sv@exept.de>
parents: 6434
diff changeset
  1195
                              (osProcessStatus pid = pid) ifTrue:[
fa110cb8566c Use #ifCurtailed: instead of #valueOnUnwindDo:
Stefan Vogel <sv@exept.de>
parents: 6434
diff changeset
  1196
                                  osChildExitActions removeKey:pid ifAbsent:nil.
fa110cb8566c Use #ifCurtailed: instead of #valueOnUnwindDo:
Stefan Vogel <sv@exept.de>
parents: 6434
diff changeset
  1197
                                  actionBlock value:osProcessStatus.
fa110cb8566c Use #ifCurtailed: instead of #valueOnUnwindDo:
Stefan Vogel <sv@exept.de>
parents: 6434
diff changeset
  1198
                                  polling := false.
fa110cb8566c Use #ifCurtailed: instead of #valueOnUnwindDo:
Stefan Vogel <sv@exept.de>
parents: 6434
diff changeset
  1199
                              ] ifFalse:[
fa110cb8566c Use #ifCurtailed: instead of #valueOnUnwindDo:
Stefan Vogel <sv@exept.de>
parents: 6434
diff changeset
  1200
                                  osProcessStatus stillAlive
fa110cb8566c Use #ifCurtailed: instead of #valueOnUnwindDo:
Stefan Vogel <sv@exept.de>
parents: 6434
diff changeset
  1201
                              ]
fa110cb8566c Use #ifCurtailed: instead of #valueOnUnwindDo:
Stefan Vogel <sv@exept.de>
parents: 6434
diff changeset
  1202
                          ]
fa110cb8566c Use #ifCurtailed: instead of #valueOnUnwindDo:
Stefan Vogel <sv@exept.de>
parents: 6434
diff changeset
  1203
                      ]. 
fa110cb8566c Use #ifCurtailed: instead of #valueOnUnwindDo:
Stefan Vogel <sv@exept.de>
parents: 6434
diff changeset
  1204
                  ]
fa110cb8566c Use #ifCurtailed: instead of #valueOnUnwindDo:
Stefan Vogel <sv@exept.de>
parents: 6434
diff changeset
  1205
              ] ifCurtailed:[
fa110cb8566c Use #ifCurtailed: instead of #valueOnUnwindDo:
Stefan Vogel <sv@exept.de>
parents: 6434
diff changeset
  1206
                  osChildExitActions removeKey:pid ifAbsent:nil
fa110cb8566c Use #ifCurtailed: instead of #valueOnUnwindDo:
Stefan Vogel <sv@exept.de>
parents: 6434
diff changeset
  1207
              ]
fa110cb8566c Use #ifCurtailed: instead of #valueOnUnwindDo:
Stefan Vogel <sv@exept.de>
parents: 6434
diff changeset
  1208
            ] forkAt:TimingPriority.
fa110cb8566c Use #ifCurtailed: instead of #valueOnUnwindDo:
Stefan Vogel <sv@exept.de>
parents: 6434
diff changeset
  1209
        ].
840
523533898acd Reset sigCHLD interrupt handler, when no more processes are being waited for.
Stefan Vogel <sv@exept.de>
parents: 829
diff changeset
  1210
    ].
2499
95392696facc Fix race condition when waiting for SIGCHLD.
Stefan Vogel <sv@exept.de>
parents: 2468
diff changeset
  1211
    ^ pid
95392696facc Fix race condition when waiting for SIGCHLD.
Stefan Vogel <sv@exept.de>
parents: 2468
diff changeset
  1212
3270
fd52c625f87c fixed monitoring for non-sigChild systems (WIN32)
Claus Gittinger <cg@exept.de>
parents: 3246
diff changeset
  1213
    "Created: / 25.3.1997 / 10:54:56 / stefan"
fd52c625f87c fixed monitoring for non-sigChild systems (WIN32)
Claus Gittinger <cg@exept.de>
parents: 3246
diff changeset
  1214
    "Modified: / 25.3.1997 / 11:21:05 / stefan"
fd52c625f87c fixed monitoring for non-sigChild systems (WIN32)
Claus Gittinger <cg@exept.de>
parents: 3246
diff changeset
  1215
    "Modified: / 15.4.1997 / 11:55:57 / David"
4127
f3960fe6ec41 reuse the delay object in #monitor:action:
Claus Gittinger <cg@exept.de>
parents: 4042
diff changeset
  1216
    "Modified: / 27.4.1999 / 20:09:38 / cg"
1166
f5affd8cb289 added #unmonitorPid: - there still is trouble with zombie subchilds, if a process is killed via #killProcess:
Claus Gittinger <cg@exept.de>
parents: 1154
diff changeset
  1217
!
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
  1218
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
  1219
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
  1220
    "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
  1221
2966
856dfc8a294a lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2962
diff changeset
  1222
    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
  1223
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
  1224
    "Created: 12.4.1996 / 19:01:59 / cg"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1225
! !
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1226
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1227
!ProcessorScheduler methodsFor:'primitive process primitives'!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1228
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1229
scheduleForInterrupt:aProcess
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1230
    "make aProcess evaluate its pushed interrupt block(s)"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1231
1092
2a8acc60f5b5 added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents: 1086
diff changeset
  1232
    self scheduleInterruptActionsOf:aProcess.
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1233
    aProcess state ~~ #stopped ifTrue:[
7848
89d9378201b1 checkin from browser
ca
parents: 7845
diff changeset
  1234
        "
89d9378201b1 checkin from browser
ca
parents: 7845
diff changeset
  1235
         make the process runnable
89d9378201b1 checkin from browser
ca
parents: 7845
diff changeset
  1236
        "
89d9378201b1 checkin from browser
ca
parents: 7845
diff changeset
  1237
        self resume:aProcess
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1238
    ]
1092
2a8acc60f5b5 added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents: 1086
diff changeset
  1239
3777
f351744c575f fix terminate/interrupt/reschedule while in osWait (win32)
Claus Gittinger <cg@exept.de>
parents: 3745
diff changeset
  1240
    "Modified: / 24.8.1998 / 18:31:32 / cg"
1092
2a8acc60f5b5 added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents: 1086
diff changeset
  1241
!
2a8acc60f5b5 added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents: 1086
diff changeset
  1242
2a8acc60f5b5 added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents: 1086
diff changeset
  1243
scheduleInterruptActionsOf:aProcess
2a8acc60f5b5 added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents: 1086
diff changeset
  1244
    "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
  1245
     when resumed."
2a8acc60f5b5 added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents: 1086
diff changeset
  1246
2a8acc60f5b5 added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents: 1086
diff changeset
  1247
    |id|
2a8acc60f5b5 added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents: 1086
diff changeset
  1248
2a8acc60f5b5 added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents: 1086
diff changeset
  1249
    aProcess isNil ifTrue:[^ self].
2a8acc60f5b5 added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents: 1086
diff changeset
  1250
    aProcess == activeProcess ifTrue:[^ self].
2a8acc60f5b5 added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents: 1086
diff changeset
  1251
2a8acc60f5b5 added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents: 1086
diff changeset
  1252
    id := aProcess id.
2a8acc60f5b5 added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents: 1086
diff changeset
  1253
    self class threadInterrupt:id.
2a8acc60f5b5 added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents: 1086
diff changeset
  1254
2a8acc60f5b5 added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents: 1086
diff changeset
  1255
    "Created: 5.3.1996 / 17:25:55 / cg"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1256
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1257
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1258
threadSwitch:aProcess
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1259
    "continue execution in aProcess.
1783
be7402f74d94 hide timerInterrupt & ioInterrupt contexts when switching
Claus Gittinger <cg@exept.de>
parents: 1780
diff changeset
  1260
     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
  1261
3644
dacb2b9d4867 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3566
diff changeset
  1262
    |id pri ok oldProcess oldPri oldId p nm singleStep wasBlocked|
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1263
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1264
    (aProcess isNil or:[aProcess == activeProcess]) ifTrue:[^ self].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1265
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1266
    wasBlocked := OperatingSystem blockInterrupts.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1267
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1268
    oldProcess := activeProcess.
2262
4c4d810f006f semaphore names
Claus Gittinger <cg@exept.de>
parents: 2258
diff changeset
  1269
    oldId := activeProcessId.
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1270
    oldPri := currentPriority.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1271
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1272
    id := aProcess id.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1273
    pri := aProcess priority.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1274
    singleStep := aProcess isSingleStepping.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1275
    aProcess state:#active.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1276
    oldProcess setStateTo:#run if:#active.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1277
5449
bf1de72fd2bb preps for rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5406
diff changeset
  1278
    currentPriority := pri.
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1279
    activeProcess := aProcess.
2262
4c4d810f006f semaphore names
Claus Gittinger <cg@exept.de>
parents: 2258
diff changeset
  1280
    activeProcessId := id.
5453
0984e1210892 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5449
diff changeset
  1281
    ok := self threadSwitchFrom:oldProcess to:aProcess id:id singleStep:singleStep.
5449
bf1de72fd2bb preps for rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5406
diff changeset
  1282
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1283
    "time passes spent in some other process ...
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1284
     ... here again"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1285
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1286
    p := activeProcess.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1287
    activeProcess := oldProcess.
2262
4c4d810f006f semaphore names
Claus Gittinger <cg@exept.de>
parents: 2258
diff changeset
  1288
    activeProcessId := oldId.
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1289
    currentPriority := oldProcess priority.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1290
3786
1ef55d18a4d4 added support to halt a native process
Claus Gittinger <cg@exept.de>
parents: 3777
diff changeset
  1291
    ok == true ifFalse:[
6990
a6bda971619f race with threadDestroy (leftOver process-structures in VM);
ca
parents: 6940
diff changeset
  1292
        "
a6bda971619f race with threadDestroy (leftOver process-structures in VM);
ca
parents: 6940
diff changeset
  1293
         switch failed for some reason -
a6bda971619f race with threadDestroy (leftOver process-structures in VM);
ca
parents: 6940
diff changeset
  1294
         destroy (hard-terminate) the bad process.
a6bda971619f race with threadDestroy (leftOver process-structures in VM);
ca
parents: 6940
diff changeset
  1295
         This happens when:
a6bda971619f race with threadDestroy (leftOver process-structures in VM);
ca
parents: 6940
diff changeset
  1296
         - the stack went above the absolute limit
a6bda971619f race with threadDestroy (leftOver process-structures in VM);
ca
parents: 6940
diff changeset
  1297
           (VM switches back to scheduler)
a6bda971619f race with threadDestroy (leftOver process-structures in VM);
ca
parents: 6940
diff changeset
  1298
         - a halted process cannot execute its interrupt
a6bda971619f race with threadDestroy (leftOver process-structures in VM);
ca
parents: 6940
diff changeset
  1299
           actions (win32 only)
a6bda971619f race with threadDestroy (leftOver process-structures in VM);
ca
parents: 6940
diff changeset
  1300
        "
a6bda971619f race with threadDestroy (leftOver process-structures in VM);
ca
parents: 6940
diff changeset
  1301
        (id := p id) ~~ 0 ifTrue:[
a6bda971619f race with threadDestroy (leftOver process-structures in VM);
ca
parents: 6940
diff changeset
  1302
            id notNil ifTrue:[
a6bda971619f race with threadDestroy (leftOver process-structures in VM);
ca
parents: 6940
diff changeset
  1303
                'Processor [warning]: problem with process ' errorPrint. 
a6bda971619f race with threadDestroy (leftOver process-structures in VM);
ca
parents: 6940
diff changeset
  1304
                id errorPrint. 
a6bda971619f race with threadDestroy (leftOver process-structures in VM);
ca
parents: 6940
diff changeset
  1305
                (nm := p name) notNil ifTrue:[
a6bda971619f race with threadDestroy (leftOver process-structures in VM);
ca
parents: 6940
diff changeset
  1306
                    ' (' errorPrint. nm errorPrint. ')' errorPrint.
a6bda971619f race with threadDestroy (leftOver process-structures in VM);
ca
parents: 6940
diff changeset
  1307
                ].
a6bda971619f race with threadDestroy (leftOver process-structures in VM);
ca
parents: 6940
diff changeset
  1308
a6bda971619f race with threadDestroy (leftOver process-structures in VM);
ca
parents: 6940
diff changeset
  1309
                ok == #halted ifTrue:[
a6bda971619f race with threadDestroy (leftOver process-structures in VM);
ca
parents: 6940
diff changeset
  1310
                    "/ that process was halted (win32 only)
a6bda971619f race with threadDestroy (leftOver process-structures in VM);
ca
parents: 6940
diff changeset
  1311
                    p state:#halted.
a6bda971619f race with threadDestroy (leftOver process-structures in VM);
ca
parents: 6940
diff changeset
  1312
                   '; stopped it.' errorPrintCR.
a6bda971619f race with threadDestroy (leftOver process-structures in VM);
ca
parents: 6940
diff changeset
  1313
                   self suspend:p.
a6bda971619f race with threadDestroy (leftOver process-structures in VM);
ca
parents: 6940
diff changeset
  1314
                ] ifFalse:[
a6bda971619f race with threadDestroy (leftOver process-structures in VM);
ca
parents: 6940
diff changeset
  1315
                   '; hard-terminate it.' errorPrintCR.
a6bda971619f race with threadDestroy (leftOver process-structures in VM);
ca
parents: 6940
diff changeset
  1316
                   'Processor [info]: cleanup may take a while if stack is huge' infoPrintCR.
a6bda971619f race with threadDestroy (leftOver process-structures in VM);
ca
parents: 6940
diff changeset
  1317
                   p state:#cleanup.
a6bda971619f race with threadDestroy (leftOver process-structures in VM);
ca
parents: 6940
diff changeset
  1318
                   self terminateNoSignal:p.
a6bda971619f race with threadDestroy (leftOver process-structures in VM);
ca
parents: 6940
diff changeset
  1319
                ]
a6bda971619f race with threadDestroy (leftOver process-structures in VM);
ca
parents: 6940
diff changeset
  1320
            ]
a6bda971619f race with threadDestroy (leftOver process-structures in VM);
ca
parents: 6940
diff changeset
  1321
        ]
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1322
    ].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1323
    zombie notNil ifTrue:[
6990
a6bda971619f race with threadDestroy (leftOver process-structures in VM);
ca
parents: 6940
diff changeset
  1324
        self class threadDestroy:zombie.
a6bda971619f race with threadDestroy (leftOver process-structures in VM);
ca
parents: 6940
diff changeset
  1325
        zombie := nil
1783
be7402f74d94 hide timerInterrupt & ioInterrupt contexts when switching
Claus Gittinger <cg@exept.de>
parents: 1780
diff changeset
  1326
    ].
be7402f74d94 hide timerInterrupt & ioInterrupt contexts when switching
Claus Gittinger <cg@exept.de>
parents: 1780
diff changeset
  1327
    wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
5449
bf1de72fd2bb preps for rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5406
diff changeset
  1328
!
bf1de72fd2bb preps for rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5406
diff changeset
  1329
5453
0984e1210892 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5449
diff changeset
  1330
threadSwitchFrom:oldProcess to:aProcess id:id singleStep:singleStep
5449
bf1de72fd2bb preps for rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5406
diff changeset
  1331
    "continue execution in aProcess.
bf1de72fd2bb preps for rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5406
diff changeset
  1332
     WARNING: this is very a low level entry, no process administration is done here"
bf1de72fd2bb preps for rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5406
diff changeset
  1333
bf1de72fd2bb preps for rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5406
diff changeset
  1334
    "
bf1de72fd2bb preps for rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5406
diff changeset
  1335
     no interrupts now - activeProcess has already been changed
bf1de72fd2bb preps for rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5406
diff changeset
  1336
     (dont add any message sends here)
bf1de72fd2bb preps for rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5406
diff changeset
  1337
    "
bf1de72fd2bb preps for rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5406
diff changeset
  1338
    activeProcess := aProcess.
bf1de72fd2bb preps for rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5406
diff changeset
  1339
    activeProcessId := id.
bf1de72fd2bb preps for rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5406
diff changeset
  1340
%{
bf1de72fd2bb preps for rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5406
diff changeset
  1341
    extern OBJ ___threadSwitch();
bf1de72fd2bb preps for rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5406
diff changeset
  1342
bf1de72fd2bb preps for rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5406
diff changeset
  1343
    if (__isSmallInteger(id)) {
8600
108874a95d52 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8523
diff changeset
  1344
        RETURN ( ___threadSwitch(__context, __intVal(id), (singleStep == true) ? 1 : 0, 0) );
5449
bf1de72fd2bb preps for rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5406
diff changeset
  1345
    }
8600
108874a95d52 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8523
diff changeset
  1346
    RETURN (false);
5449
bf1de72fd2bb preps for rel5 migration
Claus Gittinger <cg@exept.de>
parents: 5406
diff changeset
  1347
%}
1787
32632b6f969d remember threadSwitch:from: idea for later implementation;
Claus Gittinger <cg@exept.de>
parents: 1783
diff changeset
  1348
! !
32632b6f969d remember threadSwitch:from: idea for later implementation;
Claus Gittinger <cg@exept.de>
parents: 1783
diff changeset
  1349
1981
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1350
!ProcessorScheduler methodsFor:'priority constants'!
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1351
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1352
highIOPriority
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1353
    "not currently used - for ST80 compatibility only"
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1354
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1355
    ^ 16 "claus: is this ok ?"
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1356
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1357
    "Created: 15.11.1996 / 11:42:39 / cg"
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1358
!
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1359
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1360
highestPriority
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1361
    "return the highest priority value (normal) processes can have."
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1362
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1363
    "must be below schedulingPriority - 
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1364
     otherwise scheduler could be blocked ...
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1365
    "
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1366
    ^ HighestPriority  
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1367
!
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1368
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1369
lowIOPriority
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1370
    "not currently used - for ST80 compatibility only"
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1371
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1372
    ^ 2 "claus: is this ok ?"
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1373
!
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1374
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1375
lowestPriority
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1376
    "return the lowest priority value"
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1377
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1378
    ^ 1   "do not change this - its not variable"
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1379
!
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1380
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1381
schedulingPriority
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1382
    "return the priority at which the scheduler runs."
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1383
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1384
    "must be above highestPriority - 
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1385
     otherwise scheduler could be blocked ...
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1386
    "
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1387
    ^ SchedulingPriority
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1388
!
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1389
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1390
systemBackgroundPriority
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1391
    "return the priority, at which background system processing
7076
738bbff659e8 comments
Claus Gittinger <cg@exept.de>
parents: 7046
diff changeset
  1392
     should take place."
1981
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1393
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1394
    ^ 4
7076
738bbff659e8 comments
Claus Gittinger <cg@exept.de>
parents: 7046
diff changeset
  1395
738bbff659e8 comments
Claus Gittinger <cg@exept.de>
parents: 7046
diff changeset
  1396
    "
738bbff659e8 comments
Claus Gittinger <cg@exept.de>
parents: 7046
diff changeset
  1397
     Processor systemBackgroundPriority
738bbff659e8 comments
Claus Gittinger <cg@exept.de>
parents: 7046
diff changeset
  1398
    "
1981
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1399
!
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1400
2190
8afa4709d8a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2188
diff changeset
  1401
timeSlicingPriorityLimit
8afa4709d8a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2188
diff changeset
  1402
    "return the priority, above which no timeslicing takes place
8afa4709d8a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2188
diff changeset
  1403
     (i.e. processes running at a higher priority are not preempted).
8afa4709d8a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2188
diff changeset
  1404
     This is only effective, if preemption is enabled."
8afa4709d8a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2188
diff changeset
  1405
8afa4709d8a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2188
diff changeset
  1406
    ^ TimeSlicingPriorityLimit
8afa4709d8a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2188
diff changeset
  1407
!
8afa4709d8a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2188
diff changeset
  1408
2191
6c641780265d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2190
diff changeset
  1409
timingPriority
6c641780265d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2190
diff changeset
  1410
    "return the priority, at which all timing takes place (messageTally,
6c641780265d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2190
diff changeset
  1411
     delay etc.)"
6c641780265d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2190
diff changeset
  1412
6c641780265d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2190
diff changeset
  1413
    ^ TimingPriority
6c641780265d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2190
diff changeset
  1414
!
6c641780265d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2190
diff changeset
  1415
1981
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1416
userBackgroundPriority
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1417
    "return the priority, at which background user (non-interactive) processing
7076
738bbff659e8 comments
Claus Gittinger <cg@exept.de>
parents: 7046
diff changeset
  1418
     should take place."
1981
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1419
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1420
    ^ 6
7076
738bbff659e8 comments
Claus Gittinger <cg@exept.de>
parents: 7046
diff changeset
  1421
738bbff659e8 comments
Claus Gittinger <cg@exept.de>
parents: 7046
diff changeset
  1422
    "
738bbff659e8 comments
Claus Gittinger <cg@exept.de>
parents: 7046
diff changeset
  1423
     Processor userBackgroundPriority
738bbff659e8 comments
Claus Gittinger <cg@exept.de>
parents: 7046
diff changeset
  1424
    "
1981
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1425
!
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1426
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1427
userInterruptPriority
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1428
    "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
  1429
     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
  1430
     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
  1431
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1432
    ^ UserInterruptPriority
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1433
!
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1434
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1435
userSchedulingPriority
de394714f50b added #hiIOPriority for protocol completeness
Claus Gittinger <cg@exept.de>
parents: 1836
diff changeset
  1436
    "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
  1437
     takes place"
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
    ^ UserSchedulingPriority
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
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1442
!ProcessorScheduler methodsFor:'private'!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1443
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1444
remember:aProcess
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1445
    "remember aProcess for later disposal (where the underlying
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1446
     system resources have to be freed)."
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1447
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1448
    |newShadow oldId wasBlocked
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1449
     oldSize "{ Class: SmallInteger }"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1450
     index   "{ Class: SmallInteger }"
1787
32632b6f969d remember threadSwitch:from: idea for later implementation;
Claus Gittinger <cg@exept.de>
parents: 1783
diff changeset
  1451
     sz      "{ Class: SmallInteger }" |
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1452
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1453
    wasBlocked := OperatingSystem blockInterrupts.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1454
    index := 1.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1455
    sz := KnownProcessIds size.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1456
    [index <= sz] whileTrue:[
2534
6ac73e757c70 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2499
diff changeset
  1457
	(KnownProcesses at:index) isNil ifTrue:[
6ac73e757c70 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2499
diff changeset
  1458
	    oldId := KnownProcessIds at:index.
6ac73e757c70 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2499
diff changeset
  1459
	    oldId notNil ifTrue:[
6ac73e757c70 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2499
diff changeset
  1460
		self class threadDestroy:oldId.
6ac73e757c70 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2499
diff changeset
  1461
	    ].
6ac73e757c70 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2499
diff changeset
  1462
	    KnownProcesses at:index put:aProcess.
6ac73e757c70 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2499
diff changeset
  1463
	    KnownProcessIds at:index put:aProcess id.
6ac73e757c70 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2499
diff changeset
  1464
	    wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
6ac73e757c70 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2499
diff changeset
  1465
	    ^ self
6ac73e757c70 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2499
diff changeset
  1466
	].
6ac73e757c70 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2499
diff changeset
  1467
	index := index + 1
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1468
    ].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1469
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1470
    KnownProcessIds grow:index.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1471
    KnownProcessIds at:index put:aProcess id.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1472
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1473
    oldSize := KnownProcesses size.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1474
    (index > oldSize) ifTrue:[
2534
6ac73e757c70 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2499
diff changeset
  1475
	newShadow := WeakArray new:(oldSize * 2).
6ac73e757c70 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2499
diff changeset
  1476
	newShadow addDependent:self class.
6ac73e757c70 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2499
diff changeset
  1477
	newShadow replaceFrom:1 with:KnownProcesses.
6ac73e757c70 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2499
diff changeset
  1478
	KnownProcesses := newShadow
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1479
    ].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1480
    KnownProcesses at:index put:aProcess.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1481
    wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
2091
c11bb3e29a1b Use dependent mechamism of WeakArray instead of #watcher.
Stefan Vogel <sv@exept.de>
parents: 1981
diff changeset
  1482
c11bb3e29a1b Use dependent mechamism of WeakArray instead of #watcher.
Stefan Vogel <sv@exept.de>
parents: 1981
diff changeset
  1483
    "Modified: 7.1.1997 / 16:48:39 / stefan"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1484
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1485
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1486
unRemember:aProcess
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1487
    "forget aProcess - dispose processing will not consider this one"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1488
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1489
    |index wasBlocked|
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1490
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1491
    wasBlocked := OperatingSystem blockInterrupts.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1492
    index := KnownProcesses identityIndexOf:aProcess.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1493
    index ~~ 0 ifTrue:[
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1494
	KnownProcessIds at:index put:nil.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1495
	KnownProcesses at:index put:nil.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1496
    ].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1497
    wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1498
! !
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1499
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1500
!ProcessorScheduler methodsFor:'process creation'!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1501
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1502
newProcessFor:aProcess
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1503
    "create a physical (VM-) process for aProcess.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1504
     Return true if ok, false if something went wrong.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1505
     The process is not scheduled; to start it running, 
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1506
     it needs a Process>>resume. Once resumed, the process will later 
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1507
     get control in its #start method."
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1508
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1509
    |id|
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1510
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1511
    id := self class threadCreate:aProcess withId:nil.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1512
    id isNil ifTrue:[^ false].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1513
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1514
    aProcess setId:id state:#light.   "meaning: has no stack yet"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1515
    self remember:aProcess.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1516
    ^ true
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1517
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1518
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1519
newProcessFor:aProcess withId:idWant
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1520
    "private entry for Process restart - do not use in your program"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1521
1836
08a200835cc8 process restart is different if done at image restart time.
Claus Gittinger <cg@exept.de>
parents: 1793
diff changeset
  1522
    idWant isNil ifTrue:[
2534
6ac73e757c70 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2499
diff changeset
  1523
	^ self newProcessFor:aProcess
1836
08a200835cc8 process restart is different if done at image restart time.
Claus Gittinger <cg@exept.de>
parents: 1793
diff changeset
  1524
    ].
08a200835cc8 process restart is different if done at image restart time.
Claus Gittinger <cg@exept.de>
parents: 1793
diff changeset
  1525
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1526
    (self class threadCreate:aProcess withId:idWant) ~~ idWant ifTrue:[
2534
6ac73e757c70 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2499
diff changeset
  1527
	^ false
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1528
    ].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1529
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1530
    aProcess state:#light.   "meaning: has no stack yet"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1531
    self remember:aProcess.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1532
    ^ true
1836
08a200835cc8 process restart is different if done at image restart time.
Claus Gittinger <cg@exept.de>
parents: 1793
diff changeset
  1533
08a200835cc8 process restart is different if done at image restart time.
Claus Gittinger <cg@exept.de>
parents: 1793
diff changeset
  1534
    "Modified: 28.10.1996 / 19:14:28 / cg"
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
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1537
!ProcessorScheduler methodsFor:'queries'!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1538
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1539
activeProcessIsSystemProcess
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1540
    "return true if the active process is a system process,
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1541
     which should not be suspended."
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1542
2637
0d8508bedf06 Move #isSystemProcess from ProcessorScheduler to Process.
Stefan Vogel <sv@exept.de>
parents: 2626
diff changeset
  1543
    ^ activeProcess isSystemProcess
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1544
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1545
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1546
     Processor activeProcessIsSystemProcess
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1547
    "
2637
0d8508bedf06 Move #isSystemProcess from ProcessorScheduler to Process.
Stefan Vogel <sv@exept.de>
parents: 2626
diff changeset
  1548
0d8508bedf06 Move #isSystemProcess from ProcessorScheduler to Process.
Stefan Vogel <sv@exept.de>
parents: 2626
diff changeset
  1549
    "Modified: 17.4.1997 / 12:59:33 / stefan"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1550
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1551
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
  1552
anyUserProcessAtAll
1571
8d00e6b97ca7 changed #anyUserProcessAtAll,
Claus Gittinger <cg@exept.de>
parents: 1473
diff changeset
  1553
    "return true, if there is any process still running with a
8d00e6b97ca7 changed #anyUserProcessAtAll,
Claus Gittinger <cg@exept.de>
parents: 1473
diff changeset
  1554
     non-zero processGroup (i.e. any non-system process).
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
  1555
     This is used to determine if we should stop scheduling
2193
Claus Gittinger <cg@exept.de>
parents: 2191
diff changeset
  1556
     in standAlone applications.
Claus Gittinger <cg@exept.de>
parents: 2191
diff changeset
  1557
     A userProcess has a non-zero processGroup."
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
  1558
3745
3fd121f2e74e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3740
diff changeset
  1559
    |listArray l prio "{ Class: SmallInteger }" 
3fd121f2e74e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3740
diff changeset
  1560
     wasBlocked|
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
  1561
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
  1562
    prio := HighestPriority.
3745
3fd121f2e74e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3740
diff changeset
  1563
    wasBlocked := OperatingSystem blockInterrupts.
3fd121f2e74e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3740
diff changeset
  1564
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
  1565
    listArray := quiescentProcessLists.
1571
8d00e6b97ca7 changed #anyUserProcessAtAll,
Claus Gittinger <cg@exept.de>
parents: 1473
diff changeset
  1566
8d00e6b97ca7 changed #anyUserProcessAtAll,
Claus Gittinger <cg@exept.de>
parents: 1473
diff changeset
  1567
    [prio >= 1] whileTrue:[
1679
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  1568
	l := listArray at:prio.
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  1569
	l notNil ifTrue:[
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  1570
	    l do:[:aProcess |
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  1571
		aProcess processGroupId ~~ 0 ifTrue:[
3745
3fd121f2e74e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3740
diff changeset
  1572
		    wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
1679
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  1573
		    ^ true.
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  1574
		]
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  1575
	    ]
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  1576
	].
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  1577
	prio := prio - 1
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
  1578
    ].
3745
3fd121f2e74e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3740
diff changeset
  1579
    wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
964
6d87e84d86ac in standAloneMode: exit dispatch if last process dies and no more sema/timer waits are pending
Claus Gittinger <cg@exept.de>
parents: 840
diff changeset
  1580
    ^ false
1571
8d00e6b97ca7 changed #anyUserProcessAtAll,
Claus Gittinger <cg@exept.de>
parents: 1473
diff changeset
  1581
8d00e6b97ca7 changed #anyUserProcessAtAll,
Claus Gittinger <cg@exept.de>
parents: 1473
diff changeset
  1582
    "
8d00e6b97ca7 changed #anyUserProcessAtAll,
Claus Gittinger <cg@exept.de>
parents: 1473
diff changeset
  1583
     Processor anyUserProcessAtAll  
8d00e6b97ca7 changed #anyUserProcessAtAll,
Claus Gittinger <cg@exept.de>
parents: 1473
diff changeset
  1584
    "
8d00e6b97ca7 changed #anyUserProcessAtAll,
Claus Gittinger <cg@exept.de>
parents: 1473
diff changeset
  1585
1618
9fb4ee952e89 use nil for empty lists
Claus Gittinger <cg@exept.de>
parents: 1606
diff changeset
  1586
    "Modified: 29.7.1996 / 11:49:17 / cg"
964
6d87e84d86ac in standAloneMode: exit dispatch if last process dies and no more sema/timer waits are pending
Claus Gittinger <cg@exept.de>
parents: 840
diff changeset
  1587
!
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
  1588
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1589
highestPriorityRunnableProcess
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1590
    "return the highest prio runnable process"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1591
3745
3fd121f2e74e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3740
diff changeset
  1592
    |listArray l p prio "{ Class: SmallInteger }" 
3fd121f2e74e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3740
diff changeset
  1593
     wasBlocked|
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1594
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1595
    prio := HighestPriority.
3745
3fd121f2e74e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3740
diff changeset
  1596
    wasBlocked := OperatingSystem blockInterrupts.
3fd121f2e74e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3740
diff changeset
  1597
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1598
    listArray := quiescentProcessLists.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1599
    [prio >= 1] whileTrue:[
2534
6ac73e757c70 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2499
diff changeset
  1600
	l := listArray at:prio.
6ac73e757c70 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2499
diff changeset
  1601
	l notNil ifTrue:[
6ac73e757c70 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2499
diff changeset
  1602
	    l isEmpty ifFalse:[
6ac73e757c70 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2499
diff changeset
  1603
		p := l first.
6ac73e757c70 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2499
diff changeset
  1604
		"
6ac73e757c70 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2499
diff changeset
  1605
		 if it got corrupted somehow ...
6ac73e757c70 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2499
diff changeset
  1606
		"
6ac73e757c70 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2499
diff changeset
  1607
		p id isNil ifTrue:[
6ac73e757c70 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2499
diff changeset
  1608
		    'Processor [warning]: process with nil id removed' errorPrintCR.
6ac73e757c70 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2499
diff changeset
  1609
		    l removeFirst.
3745
3fd121f2e74e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3740
diff changeset
  1610
		    p := nil.
2534
6ac73e757c70 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2499
diff changeset
  1611
		].
3745
3fd121f2e74e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3740
diff changeset
  1612
		wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
2534
6ac73e757c70 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2499
diff changeset
  1613
		^ p
6ac73e757c70 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2499
diff changeset
  1614
	    ]
6ac73e757c70 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2499
diff changeset
  1615
	].
6ac73e757c70 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2499
diff changeset
  1616
	prio := prio - 1
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1617
    ].
3745
3fd121f2e74e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3740
diff changeset
  1618
    wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1619
    ^ nil
1086
7b0641a2e1ef nicer message
Claus Gittinger <cg@exept.de>
parents: 1061
diff changeset
  1620
2385
9b6e06112b58 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2353
diff changeset
  1621
    "Modified: 12.2.1997 / 12:41:49 / cg"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1622
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1623
5389
509d4228751b added query: #isDispatching
ca
parents: 5107
diff changeset
  1624
isDispatching
509d4228751b added query: #isDispatching
ca
parents: 5107
diff changeset
  1625
    ^ dispatching
509d4228751b added query: #isDispatching
ca
parents: 5107
diff changeset
  1626
!
509d4228751b added query: #isDispatching
ca
parents: 5107
diff changeset
  1627
1177
05f4917ccc4f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1166
diff changeset
  1628
isPureEventDriven
05f4917ccc4f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1166
diff changeset
  1629
    "this is temporary - (maybe not :-).
05f4917ccc4f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1166
diff changeset
  1630
     you can run ST/X either with or without processes.
05f4917ccc4f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1166
diff changeset
  1631
     Without, there is conceptionally a single process handling all
05f4917ccc4f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1166
diff changeset
  1632
     outside events and timeouts. This has some negative implications
05f4917ccc4f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1166
diff changeset
  1633
     (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
  1634
     assembler support - i.e. quick portability.
05f4917ccc4f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1166
diff changeset
  1635
     The PureEvent flag will automatically be set if the runtime system
05f4917ccc4f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1166
diff changeset
  1636
     does not support threads - otherwise, it can be set manually
05f4917ccc4f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1166
diff changeset
  1637
     (from rc-file).
05f4917ccc4f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1166
diff changeset
  1638
    "
05f4917ccc4f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1166
diff changeset
  1639
05f4917ccc4f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1166
diff changeset
  1640
    ^ PureEventDriven
05f4917ccc4f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1166
diff changeset
  1641
05f4917ccc4f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1166
diff changeset
  1642
    "Created: 13.4.1996 / 20:31:31 / cg"
05f4917ccc4f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1166
diff changeset
  1643
!
05f4917ccc4f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1166
diff changeset
  1644
2191
6c641780265d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2190
diff changeset
  1645
isTimeSlicing
6c641780265d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2190
diff changeset
  1646
    "return true, if in timeslicing mode"
6c641780265d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2190
diff changeset
  1647
6c641780265d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2190
diff changeset
  1648
    ^ timeSliceProcess notNil
6c641780265d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2190
diff changeset
  1649
6c641780265d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2190
diff changeset
  1650
    "
6c641780265d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2190
diff changeset
  1651
     Processor isTimeSlicing
6c641780265d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2190
diff changeset
  1652
    "
6c641780265d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2190
diff changeset
  1653
6c641780265d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2190
diff changeset
  1654
    "Modified: 17.1.1997 / 17:48:41 / cg"
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
!ProcessorScheduler methodsFor:'scheduling'!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1658
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1659
changePriority:prio for:aProcess
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1660
    "change the priority of aProcess"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1661
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1662
    |oldList newList oldPrio newPrio wasBlocked|
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
    oldPrio := aProcess priority.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1665
    oldPrio == prio ifTrue:[^ self].
1042
cc49fd1e3c7e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1032
diff changeset
  1666
    aProcess == scheduler ifTrue:[^ self].
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1667
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1668
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1669
     check for valid argument
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1670
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1671
    newPrio := prio.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1672
    newPrio < 1 ifTrue:[
6421
58dca33cf0fc #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 6376
diff changeset
  1673
        newPrio := 1.
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1674
    ] ifFalse:[
6421
58dca33cf0fc #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 6376
diff changeset
  1675
        newPrio > HighestPriority ifTrue:[
58dca33cf0fc #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 6376
diff changeset
  1676
            newPrio := HighestPriority
58dca33cf0fc #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 6376
diff changeset
  1677
        ]
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1678
    ].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1679
1042
cc49fd1e3c7e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1032
diff changeset
  1680
    [
6421
58dca33cf0fc #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 6376
diff changeset
  1681
        wasBlocked := OperatingSystem blockInterrupts.
58dca33cf0fc #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 6376
diff changeset
  1682
58dca33cf0fc #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 6376
diff changeset
  1683
        aProcess setPriority:newPrio.
58dca33cf0fc #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 6376
diff changeset
  1684
58dca33cf0fc #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 6376
diff changeset
  1685
        oldList := quiescentProcessLists at:oldPrio.
58dca33cf0fc #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 6376
diff changeset
  1686
        oldList notNil ifTrue:[
58dca33cf0fc #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 6376
diff changeset
  1687
            (oldList remove:aProcess ifAbsent:nil) notNil ifTrue:[
58dca33cf0fc #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 6376
diff changeset
  1688
                newList := quiescentProcessLists at:newPrio.
58dca33cf0fc #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 6376
diff changeset
  1689
                newList isNil ifTrue:[
58dca33cf0fc #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 6376
diff changeset
  1690
                    quiescentProcessLists at:newPrio put:(newList := LinkedList new).
58dca33cf0fc #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 6376
diff changeset
  1691
                ].
58dca33cf0fc #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 6376
diff changeset
  1692
                newList addLast:aProcess.
58dca33cf0fc #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 6376
diff changeset
  1693
58dca33cf0fc #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 6376
diff changeset
  1694
                "if its the current process lowering its prio 
58dca33cf0fc #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 6376
diff changeset
  1695
                 or another one raising, we have to reschedule"
58dca33cf0fc #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 6376
diff changeset
  1696
58dca33cf0fc #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 6376
diff changeset
  1697
                aProcess == activeProcess ifTrue:[
58dca33cf0fc #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 6376
diff changeset
  1698
                    currentPriority := newPrio.
58dca33cf0fc #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 6376
diff changeset
  1699
                    newPrio < oldPrio ifTrue:[
58dca33cf0fc #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 6376
diff changeset
  1700
                        self threadSwitch:scheduler.    
58dca33cf0fc #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 6376
diff changeset
  1701
                    ]
58dca33cf0fc #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 6376
diff changeset
  1702
                ] ifFalse:[
58dca33cf0fc #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 6376
diff changeset
  1703
                    newPrio > currentPriority ifTrue:[
58dca33cf0fc #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 6376
diff changeset
  1704
                        self threadSwitch:aProcess.
58dca33cf0fc #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 6376
diff changeset
  1705
                    ]
58dca33cf0fc #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 6376
diff changeset
  1706
                ].
58dca33cf0fc #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 6376
diff changeset
  1707
            ]
58dca33cf0fc #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 6376
diff changeset
  1708
        ]
58dca33cf0fc #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 6376
diff changeset
  1709
    ] ensure:[
58dca33cf0fc #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 6376
diff changeset
  1710
        wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
1042
cc49fd1e3c7e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1032
diff changeset
  1711
    ]
1032
924c177085f8 care to reenable interrupts
Claus Gittinger <cg@exept.de>
parents: 1001
diff changeset
  1712
3724
49c043d9c0b3 dynamic priorities
Claus Gittinger <cg@exept.de>
parents: 3722
diff changeset
  1713
    "Modified: / 4.8.1998 / 00:08:54 / cg"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1714
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1715
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1716
interruptActive
1783
be7402f74d94 hide timerInterrupt & ioInterrupt contexts when switching
Claus Gittinger <cg@exept.de>
parents: 1780
diff changeset
  1717
    "interrupt the current process 
be7402f74d94 hide timerInterrupt & ioInterrupt contexts when switching
Claus Gittinger <cg@exept.de>
parents: 1780
diff changeset
  1718
     - 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
  1719
     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
  1720
     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
  1721
9991
a03847e11498 make #interruptActive returnable for better debugging
Stefan Vogel <sv@exept.de>
parents: 9452
diff changeset
  1722
    <context: #return>
a03847e11498 make #interruptActive returnable for better debugging
Stefan Vogel <sv@exept.de>
parents: 9452
diff changeset
  1723
1791
9278f0b8a7e1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1787
diff changeset
  1724
    |s|
9278f0b8a7e1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1787
diff changeset
  1725
9278f0b8a7e1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1787
diff changeset
  1726
    "/ hide those intermediate scheduler contexts;
9278f0b8a7e1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1787
diff changeset
  1727
    "/ the interrupt block should think it was called right 
9278f0b8a7e1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1787
diff changeset
  1728
    "/ from the originally interrupted context
9278f0b8a7e1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1787
diff changeset
  1729
9278f0b8a7e1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1787
diff changeset
  1730
    s := thisContext sender.
9991
a03847e11498 make #interruptActive returnable for better debugging
Stefan Vogel <sv@exept.de>
parents: 9452
diff changeset
  1731
    s selector == #threadSwitchFrom:to:id:singleStep: ifTrue:[
a03847e11498 make #interruptActive returnable for better debugging
Stefan Vogel <sv@exept.de>
parents: 9452
diff changeset
  1732
        s := s sender.
a03847e11498 make #interruptActive returnable for better debugging
Stefan Vogel <sv@exept.de>
parents: 9452
diff changeset
  1733
        s selector == #threadSwitch: ifTrue:[
a03847e11498 make #interruptActive returnable for better debugging
Stefan Vogel <sv@exept.de>
parents: 9452
diff changeset
  1734
            s := s sender.
a03847e11498 make #interruptActive returnable for better debugging
Stefan Vogel <sv@exept.de>
parents: 9452
diff changeset
  1735
            s selector == #timerInterrupt ifTrue:[
a03847e11498 make #interruptActive returnable for better debugging
Stefan Vogel <sv@exept.de>
parents: 9452
diff changeset
  1736
                s := s sender
a03847e11498 make #interruptActive returnable for better debugging
Stefan Vogel <sv@exept.de>
parents: 9452
diff changeset
  1737
            ]
a03847e11498 make #interruptActive returnable for better debugging
Stefan Vogel <sv@exept.de>
parents: 9452
diff changeset
  1738
        ]
1791
9278f0b8a7e1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1787
diff changeset
  1739
    ].
9278f0b8a7e1 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1787
diff changeset
  1740
2727
853b7910cff2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2724
diff changeset
  1741
    "/ the returned value here has a subtle effect:
853b7910cff2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2724
diff changeset
  1742
    "/ if false, the interrupt is assumed to be not taken,
853b7910cff2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2724
diff changeset
  1743
    "/ and will be redelivered.
2724
9fb9ea4bf858 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2637
diff changeset
  1744
    ^ activeProcess interruptedIn:s
1783
be7402f74d94 hide timerInterrupt & ioInterrupt contexts when switching
Claus Gittinger <cg@exept.de>
parents: 1780
diff changeset
  1745
1793
537207488596 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1791
diff changeset
  1746
    "Modified: 20.10.1996 / 17:06:48 / cg"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1747
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1748
3273
343ecdba9817 added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents: 3271
diff changeset
  1749
makeRunnable:aProcess
343ecdba9817 added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents: 3271
diff changeset
  1750
    "set aProcess runnable - but do not reschedule." 
343ecdba9817 added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents: 3271
diff changeset
  1751
343ecdba9817 added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents: 3271
diff changeset
  1752
    |l pri wasBlocked|
343ecdba9817 added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents: 3271
diff changeset
  1753
343ecdba9817 added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents: 3271
diff changeset
  1754
    "ignore, if process is already dead"
343ecdba9817 added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents: 3271
diff changeset
  1755
    (aProcess isNil or:[aProcess id isNil]) ifTrue:[^ self].
343ecdba9817 added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents: 3271
diff changeset
  1756
343ecdba9817 added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents: 3271
diff changeset
  1757
343ecdba9817 added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents: 3271
diff changeset
  1758
    aProcess == activeProcess ifTrue:[
5101
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  1759
	"special handling for waiting schedulers"
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  1760
	aProcess == scheduler ifTrue:[
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  1761
	    suspendScheduler := false.
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  1762
	].
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  1763
	^ self
3273
343ecdba9817 added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents: 3271
diff changeset
  1764
    ].
343ecdba9817 added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents: 3271
diff changeset
  1765
343ecdba9817 added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents: 3271
diff changeset
  1766
    wasBlocked := OperatingSystem blockInterrupts.
343ecdba9817 added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents: 3271
diff changeset
  1767
343ecdba9817 added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents: 3271
diff changeset
  1768
    pri := aProcess priority.
343ecdba9817 added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents: 3271
diff changeset
  1769
343ecdba9817 added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents: 3271
diff changeset
  1770
    l := quiescentProcessLists at:pri.
343ecdba9817 added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents: 3271
diff changeset
  1771
    "if already running, ignore"
343ecdba9817 added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents: 3271
diff changeset
  1772
    l notNil ifTrue:[
5101
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  1773
	(l identityIndexOf:aProcess) ~~ 0 ifTrue:[
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  1774
	    wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  1775
	    ^ self
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  1776
	]
3273
343ecdba9817 added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents: 3271
diff changeset
  1777
    ] ifFalse:[
5101
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  1778
	l := LinkedList new.
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  1779
	quiescentProcessLists at:pri put:l.
3273
343ecdba9817 added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents: 3271
diff changeset
  1780
    ].
343ecdba9817 added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents: 3271
diff changeset
  1781
    l addLast:aProcess.
343ecdba9817 added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents: 3271
diff changeset
  1782
    wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
343ecdba9817 added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents: 3271
diff changeset
  1783
343ecdba9817 added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents: 3271
diff changeset
  1784
    aProcess state:#run
343ecdba9817 added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents: 3271
diff changeset
  1785
343ecdba9817 added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents: 3271
diff changeset
  1786
    "Modified: / 29.7.1996 / 12:07:37 / cg"
343ecdba9817 added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents: 3271
diff changeset
  1787
    "Created: / 4.2.1998 / 20:58:28 / cg"
343ecdba9817 added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents: 3271
diff changeset
  1788
!
343ecdba9817 added #makeRunnable - same as #resume but does not reschedule.
Claus Gittinger <cg@exept.de>
parents: 3271
diff changeset
  1789
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1790
processTermination
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1791
    "sent by VM if the current process finished its startup block 
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1792
     without proper process termination. Lay him to rest now. 
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1793
     This can only happen, if something went wrong in Block>>newProcess, 
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1794
     since the block defined there always terminates itself."
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1795
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1796
    self terminateNoSignal:activeProcess.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1797
    self threadSwitch:scheduler
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1798
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1799
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1800
reschedule
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1801
    "switch to the highest prio runnable process.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1802
     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
  1803
     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
  1804
     to allow giving up the CPU."
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1805
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1806
    ^ self threadSwitch:scheduler
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1807
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1808
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1809
resume:aProcess
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1810
    "set aProcess runnable - 
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1811
     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
  1812
4002
341a896cb334 allow stopping a waiting process
Claus Gittinger <cg@exept.de>
parents: 3969
diff changeset
  1813
    |l pri wasBlocked s|
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1814
1679
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  1815
    "ignore, if process is already dead"
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  1816
    (aProcess isNil or:[aProcess id isNil]) ifTrue:[^ self].
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  1817
4002
341a896cb334 allow stopping a waiting process
Claus Gittinger <cg@exept.de>
parents: 3969
diff changeset
  1818
    (s := aProcess state) == #osWait ifTrue:[
8456
9bc0aa33907f No error message when trying to resume a stopped process
Stefan Vogel <sv@exept.de>
parents: 7863
diff changeset
  1819
        'Processor [warning]: bad resume: #osWait' errorPrintCR.
9bc0aa33907f No error message when trying to resume a stopped process
Stefan Vogel <sv@exept.de>
parents: 7863
diff changeset
  1820
        "/ MiniDebugger enterWithMessage:'bad resume: state osWait'.
9bc0aa33907f No error message when trying to resume a stopped process
Stefan Vogel <sv@exept.de>
parents: 7863
diff changeset
  1821
        ^ self.
3777
f351744c575f fix terminate/interrupt/reschedule while in osWait (win32)
Claus Gittinger <cg@exept.de>
parents: 3745
diff changeset
  1822
    ].
4002
341a896cb334 allow stopping a waiting process
Claus Gittinger <cg@exept.de>
parents: 3969
diff changeset
  1823
    s == #stopped ifTrue:[
8456
9bc0aa33907f No error message when trying to resume a stopped process
Stefan Vogel <sv@exept.de>
parents: 7863
diff changeset
  1824
        "by definition, stopped processes cannot be resumed"
9bc0aa33907f No error message when trying to resume a stopped process
Stefan Vogel <sv@exept.de>
parents: 7863
diff changeset
  1825
        ^ self.
4002
341a896cb334 allow stopping a waiting process
Claus Gittinger <cg@exept.de>
parents: 3969
diff changeset
  1826
    ].
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1827
1679
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  1828
    aProcess == activeProcess ifTrue:[
8456
9bc0aa33907f No error message when trying to resume a stopped process
Stefan Vogel <sv@exept.de>
parents: 7863
diff changeset
  1829
        "special handling for waiting schedulers"
9bc0aa33907f No error message when trying to resume a stopped process
Stefan Vogel <sv@exept.de>
parents: 7863
diff changeset
  1830
        aProcess == scheduler ifTrue:[
9bc0aa33907f No error message when trying to resume a stopped process
Stefan Vogel <sv@exept.de>
parents: 7863
diff changeset
  1831
            suspendScheduler := false.
9bc0aa33907f No error message when trying to resume a stopped process
Stefan Vogel <sv@exept.de>
parents: 7863
diff changeset
  1832
        ].
9bc0aa33907f No error message when trying to resume a stopped process
Stefan Vogel <sv@exept.de>
parents: 7863
diff changeset
  1833
        ^ self
1679
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  1834
    ].
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1835
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1836
    wasBlocked := OperatingSystem blockInterrupts.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1837
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1838
    pri := aProcess priority.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1839
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1840
    l := quiescentProcessLists at:pri.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1841
    "if already running, ignore"
1618
9fb4ee952e89 use nil for empty lists
Claus Gittinger <cg@exept.de>
parents: 1606
diff changeset
  1842
    l notNil ifTrue:[
8456
9bc0aa33907f No error message when trying to resume a stopped process
Stefan Vogel <sv@exept.de>
parents: 7863
diff changeset
  1843
        (l identityIndexOf:aProcess) ~~ 0 ifTrue:[
9bc0aa33907f No error message when trying to resume a stopped process
Stefan Vogel <sv@exept.de>
parents: 7863
diff changeset
  1844
            wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
9bc0aa33907f No error message when trying to resume a stopped process
Stefan Vogel <sv@exept.de>
parents: 7863
diff changeset
  1845
            ^ self
9bc0aa33907f No error message when trying to resume a stopped process
Stefan Vogel <sv@exept.de>
parents: 7863
diff changeset
  1846
        ]
1618
9fb4ee952e89 use nil for empty lists
Claus Gittinger <cg@exept.de>
parents: 1606
diff changeset
  1847
    ] ifFalse:[
8456
9bc0aa33907f No error message when trying to resume a stopped process
Stefan Vogel <sv@exept.de>
parents: 7863
diff changeset
  1848
        l := LinkedList new.
9bc0aa33907f No error message when trying to resume a stopped process
Stefan Vogel <sv@exept.de>
parents: 7863
diff changeset
  1849
        quiescentProcessLists at:pri put:l.
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1850
    ].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1851
    l addLast:aProcess.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1852
    wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1853
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1854
    (pri > currentPriority) ifTrue:[
8456
9bc0aa33907f No error message when trying to resume a stopped process
Stefan Vogel <sv@exept.de>
parents: 7863
diff changeset
  1855
        "
9bc0aa33907f No error message when trying to resume a stopped process
Stefan Vogel <sv@exept.de>
parents: 7863
diff changeset
  1856
         its prio is higher; immediately transfer control to it
9bc0aa33907f No error message when trying to resume a stopped process
Stefan Vogel <sv@exept.de>
parents: 7863
diff changeset
  1857
        "
9bc0aa33907f No error message when trying to resume a stopped process
Stefan Vogel <sv@exept.de>
parents: 7863
diff changeset
  1858
        self threadSwitch:aProcess
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1859
    ] ifFalse:[
8456
9bc0aa33907f No error message when trying to resume a stopped process
Stefan Vogel <sv@exept.de>
parents: 7863
diff changeset
  1860
        "
9bc0aa33907f No error message when trying to resume a stopped process
Stefan Vogel <sv@exept.de>
parents: 7863
diff changeset
  1861
         its prio is lower; it will have to wait for a while ...
9bc0aa33907f No error message when trying to resume a stopped process
Stefan Vogel <sv@exept.de>
parents: 7863
diff changeset
  1862
        "
9bc0aa33907f No error message when trying to resume a stopped process
Stefan Vogel <sv@exept.de>
parents: 7863
diff changeset
  1863
        aProcess state:#run 
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1864
    ]
1618
9fb4ee952e89 use nil for empty lists
Claus Gittinger <cg@exept.de>
parents: 1606
diff changeset
  1865
8456
9bc0aa33907f No error message when trying to resume a stopped process
Stefan Vogel <sv@exept.de>
parents: 7863
diff changeset
  1866
    "Modified: / 24-08-1998 / 18:28:42 / cg"
9bc0aa33907f No error message when trying to resume a stopped process
Stefan Vogel <sv@exept.de>
parents: 7863
diff changeset
  1867
    "Modified: / 03-08-2004 / 19:01:47 / stefan"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1868
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1869
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1870
resumeForSingleSend:aProcess
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1871
    "like resume, but let the process execute a single send only.
3271
f9b081667d3e Fix comment.
Stefan Vogel <sv@exept.de>
parents: 3270
diff changeset
  1872
     This will be used by the debugger for single stepping."
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1873
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1874
    (aProcess isNil or:[aProcess == activeProcess]) ifTrue:[^ self].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1875
    aProcess singleStep:true.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1876
    self resume:aProcess
3271
f9b081667d3e Fix comment.
Stefan Vogel <sv@exept.de>
parents: 3270
diff changeset
  1877
f9b081667d3e Fix comment.
Stefan Vogel <sv@exept.de>
parents: 3270
diff changeset
  1878
    "Modified: / 3.2.1998 / 01:08:08 / stefan"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1879
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1880
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1881
suspend:aProcess
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1882
    "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
  1883
     If the process is the current one, reschedule.
2155
0cf80e958130 comment
Claus Gittinger <cg@exept.de>
parents: 2149
diff changeset
  1884
0cf80e958130 comment
Claus Gittinger <cg@exept.de>
parents: 2149
diff changeset
  1885
     Notice:
6939
6f6ea7b0a5ab stopping an suspended process fix
Claus Gittinger <cg@exept.de>
parents: 6807
diff changeset
  1886
         This method should only be called by Process>>suspend or
6f6ea7b0a5ab stopping an suspended process fix
Claus Gittinger <cg@exept.de>
parents: 6807
diff changeset
  1887
         Process>>suspendWithState:"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1888
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1889
    |pri l p wasBlocked|
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1890
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1891
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1892
     some debugging stuff
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1893
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1894
    aProcess isNil ifTrue:[
9295
0891968787ec invalid scheduling switch errors are proceedable
Claus Gittinger <cg@exept.de>
parents: 9120
diff changeset
  1895
        InvalidProcessSignal raiseRequestWith:aProcess errorString:'nil suspend'.
6939
6f6ea7b0a5ab stopping an suspended process fix
Claus Gittinger <cg@exept.de>
parents: 6807
diff changeset
  1896
        ^ self
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1897
    ].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1898
    aProcess id isNil ifTrue:[
9295
0891968787ec invalid scheduling switch errors are proceedable
Claus Gittinger <cg@exept.de>
parents: 9120
diff changeset
  1899
        InvalidProcessSignal raiseRequestWith:aProcess errorString:'bad suspend: already dead'.
6939
6f6ea7b0a5ab stopping an suspended process fix
Claus Gittinger <cg@exept.de>
parents: 6807
diff changeset
  1900
        self threadSwitch:scheduler.
6f6ea7b0a5ab stopping an suspended process fix
Claus Gittinger <cg@exept.de>
parents: 6807
diff changeset
  1901
        ^ self
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1902
    ].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1903
    aProcess == scheduler ifTrue:[
6939
6f6ea7b0a5ab stopping an suspended process fix
Claus Gittinger <cg@exept.de>
parents: 6807
diff changeset
  1904
        "only the scheduler may suspend itself"
6f6ea7b0a5ab stopping an suspended process fix
Claus Gittinger <cg@exept.de>
parents: 6807
diff changeset
  1905
        activeProcess == scheduler ifTrue:[
6f6ea7b0a5ab stopping an suspended process fix
Claus Gittinger <cg@exept.de>
parents: 6807
diff changeset
  1906
            suspendScheduler := true.
6f6ea7b0a5ab stopping an suspended process fix
Claus Gittinger <cg@exept.de>
parents: 6807
diff changeset
  1907
            [suspendScheduler] whileTrue:[
6f6ea7b0a5ab stopping an suspended process fix
Claus Gittinger <cg@exept.de>
parents: 6807
diff changeset
  1908
                self dispatch.
6f6ea7b0a5ab stopping an suspended process fix
Claus Gittinger <cg@exept.de>
parents: 6807
diff changeset
  1909
            ].
6f6ea7b0a5ab stopping an suspended process fix
Claus Gittinger <cg@exept.de>
parents: 6807
diff changeset
  1910
            ^ self
6f6ea7b0a5ab stopping an suspended process fix
Claus Gittinger <cg@exept.de>
parents: 6807
diff changeset
  1911
        ].
6f6ea7b0a5ab stopping an suspended process fix
Claus Gittinger <cg@exept.de>
parents: 6807
diff changeset
  1912
9295
0891968787ec invalid scheduling switch errors are proceedable
Claus Gittinger <cg@exept.de>
parents: 9120
diff changeset
  1913
        InvalidProcessSignal raiseRequestWith:aProcess errorString:'attempt to suspend scheduler'.
6939
6f6ea7b0a5ab stopping an suspended process fix
Claus Gittinger <cg@exept.de>
parents: 6807
diff changeset
  1914
        ^ self
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1915
    ].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1916
7863
516fa101129e care for interrupt action before suspending a process
ca
parents: 7848
diff changeset
  1917
    aProcess hasInterruptActions ifTrue:[
516fa101129e care for interrupt action before suspending a process
ca
parents: 7848
diff changeset
  1918
        aProcess interrupt.
516fa101129e care for interrupt action before suspending a process
ca
parents: 7848
diff changeset
  1919
    ].
516fa101129e care for interrupt action before suspending a process
ca
parents: 7848
diff changeset
  1920
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1921
    wasBlocked := OperatingSystem blockInterrupts.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1922
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1923
    pri := aProcess priority.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1924
    l := quiescentProcessLists at:pri.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1925
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1926
    "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
  1927
     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
  1928
    "
3969
0f30268b10c3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3967
diff changeset
  1929
    (l isNil or:[(l remove:aProcess ifAbsent:nil) isNil]) ifTrue:[
6940
2f937d8bb561 stopping an suspended process: no longer give a warning message
Claus Gittinger <cg@exept.de>
parents: 6939
diff changeset
  1930
        "/ 'Processor [warning]: bad suspend: process is not running' errorPrintCR.
6939
6f6ea7b0a5ab stopping an suspended process fix
Claus Gittinger <cg@exept.de>
parents: 6807
diff changeset
  1931
        "/ MiniDebugger enterWithMessage:'bad suspend: process is not running'.
6f6ea7b0a5ab stopping an suspended process fix
Claus Gittinger <cg@exept.de>
parents: 6807
diff changeset
  1932
        aProcess == activeProcess ifTrue:[
6f6ea7b0a5ab stopping an suspended process fix
Claus Gittinger <cg@exept.de>
parents: 6807
diff changeset
  1933
            self threadSwitch:scheduler.
6f6ea7b0a5ab stopping an suspended process fix
Claus Gittinger <cg@exept.de>
parents: 6807
diff changeset
  1934
        ].
6f6ea7b0a5ab stopping an suspended process fix
Claus Gittinger <cg@exept.de>
parents: 6807
diff changeset
  1935
        wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
6f6ea7b0a5ab stopping an suspended process fix
Claus Gittinger <cg@exept.de>
parents: 6807
diff changeset
  1936
        ^ self
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1937
    ].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1938
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1939
    (aProcess == activeProcess) ifTrue:[
6939
6f6ea7b0a5ab stopping an suspended process fix
Claus Gittinger <cg@exept.de>
parents: 6807
diff changeset
  1940
        "we can immediately switch sometimes"
6f6ea7b0a5ab stopping an suspended process fix
Claus Gittinger <cg@exept.de>
parents: 6807
diff changeset
  1941
        l isEmpty ifFalse:[
6f6ea7b0a5ab stopping an suspended process fix
Claus Gittinger <cg@exept.de>
parents: 6807
diff changeset
  1942
            p := l first
6f6ea7b0a5ab stopping an suspended process fix
Claus Gittinger <cg@exept.de>
parents: 6807
diff changeset
  1943
        ] ifTrue:[
6f6ea7b0a5ab stopping an suspended process fix
Claus Gittinger <cg@exept.de>
parents: 6807
diff changeset
  1944
            p := scheduler
6f6ea7b0a5ab stopping an suspended process fix
Claus Gittinger <cg@exept.de>
parents: 6807
diff changeset
  1945
        ].
6f6ea7b0a5ab stopping an suspended process fix
Claus Gittinger <cg@exept.de>
parents: 6807
diff changeset
  1946
        self threadSwitch:p 
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1947
    ].
752
0259dd855289 new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents: 750
diff changeset
  1948
3745
3fd121f2e74e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3740
diff changeset
  1949
    wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
3fd121f2e74e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3740
diff changeset
  1950
3680
9dfecf84ff93 no need for threadSwitch in bad suspend.
Claus Gittinger <cg@exept.de>
parents: 3650
diff changeset
  1951
    "Modified: / 23.9.1996 / 13:49:24 / stefan"
9dfecf84ff93 no need for threadSwitch in bad suspend.
Claus Gittinger <cg@exept.de>
parents: 3650
diff changeset
  1952
    "Modified: / 27.7.1998 / 23:34:59 / cg"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1953
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1954
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1955
terminate:aProcess
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1956
    "terminate aProcess. This is donen by sending aProcess the terminateSignal,
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1957
     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
  1958
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1959
    aProcess terminate
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1960
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1961
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1962
terminateActive
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1963
    "terminate the current process (i.e. the running process kills itself).
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1964
     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
  1965
     unwind blocks and finally do a hard terminate.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1966
     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
  1967
     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
  1968
     continued to grow its stack)"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1969
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1970
    activeProcess terminate
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1971
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1972
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1973
terminateActiveNoSignal
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1974
    "hard terminate the active process, without sending any
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1975
     terminate signal thus no unwind blocks are evaluated."
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1976
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1977
    self terminateNoSignal:activeProcess
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1978
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1979
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1980
terminateNoSignal:aProcess
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1981
    "hard terminate aProcess without sending the terminate signal, thus
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1982
     no unwind blocks or exitAction are performed in the process.. 
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1983
     If its not the current process, it is simply removed from its list 
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1984
     and physically destroyed. Otherwise (since we can't take away the chair
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1985
     we are sitting on), a switch is forced and the process 
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1986
     will be physically destroyed by the next running process. 
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1987
     (see zombie handling)"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1988
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1989
    |pri id l wasBlocked|
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1990
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1991
    aProcess isNil ifTrue:[^ self].
807
e51ce11ca948 and dont allow quickTerminate as well.
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
  1992
    aProcess == scheduler ifTrue:[
6939
6f6ea7b0a5ab stopping an suspended process fix
Claus Gittinger <cg@exept.de>
parents: 6807
diff changeset
  1993
        InvalidProcessSignal raiseWith:aProcess errorString:'attempt to terminate scheduler'.
6f6ea7b0a5ab stopping an suspended process fix
Claus Gittinger <cg@exept.de>
parents: 6807
diff changeset
  1994
        ^ self
807
e51ce11ca948 and dont allow quickTerminate as well.
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
  1995
    ].
e51ce11ca948 and dont allow quickTerminate as well.
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
  1996
6990
a6bda971619f race with threadDestroy (leftOver process-structures in VM);
ca
parents: 6940
diff changeset
  1997
    wasBlocked := OperatingSystem blockInterrupts.
a6bda971619f race with threadDestroy (leftOver process-structures in VM);
ca
parents: 6940
diff changeset
  1998
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1999
    id := aProcess id.
6990
a6bda971619f race with threadDestroy (leftOver process-structures in VM);
ca
parents: 6940
diff changeset
  2000
    id isNil ifTrue:[   "already dead"
a6bda971619f race with threadDestroy (leftOver process-structures in VM);
ca
parents: 6940
diff changeset
  2001
        wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
a6bda971619f race with threadDestroy (leftOver process-structures in VM);
ca
parents: 6940
diff changeset
  2002
        ^ self        
a6bda971619f race with threadDestroy (leftOver process-structures in VM);
ca
parents: 6940
diff changeset
  2003
    ].   
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2004
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2005
    aProcess setId:nil state:#dead.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2006
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2007
    "remove the process from the runnable list"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2008
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2009
    pri := aProcess priority.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2010
    l := quiescentProcessLists at:pri.
5840
430a17e002c4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5702
diff changeset
  2011
    l notNil ifTrue:[
6939
6f6ea7b0a5ab stopping an suspended process fix
Claus Gittinger <cg@exept.de>
parents: 6807
diff changeset
  2012
        (l remove:aProcess ifAbsent:nil) notNil ifTrue:[
6f6ea7b0a5ab stopping an suspended process fix
Claus Gittinger <cg@exept.de>
parents: 6807
diff changeset
  2013
            l isEmpty ifTrue:[
6f6ea7b0a5ab stopping an suspended process fix
Claus Gittinger <cg@exept.de>
parents: 6807
diff changeset
  2014
                quiescentProcessLists at:pri put:nil
6f6ea7b0a5ab stopping an suspended process fix
Claus Gittinger <cg@exept.de>
parents: 6807
diff changeset
  2015
            ]
6f6ea7b0a5ab stopping an suspended process fix
Claus Gittinger <cg@exept.de>
parents: 6807
diff changeset
  2016
        ].
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2017
    ].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2018
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2019
    aProcess == activeProcess ifTrue:[
6939
6f6ea7b0a5ab stopping an suspended process fix
Claus Gittinger <cg@exept.de>
parents: 6807
diff changeset
  2020
        "
6f6ea7b0a5ab stopping an suspended process fix
Claus Gittinger <cg@exept.de>
parents: 6807
diff changeset
  2021
         hard case - its the currently running process
6f6ea7b0a5ab stopping an suspended process fix
Claus Gittinger <cg@exept.de>
parents: 6807
diff changeset
  2022
         we must have the next active process destroy this one
6f6ea7b0a5ab stopping an suspended process fix
Claus Gittinger <cg@exept.de>
parents: 6807
diff changeset
  2023
         (we cannot destroy the chair we are sitting on ... :-)
6f6ea7b0a5ab stopping an suspended process fix
Claus Gittinger <cg@exept.de>
parents: 6807
diff changeset
  2024
        "
6990
a6bda971619f race with threadDestroy (leftOver process-structures in VM);
ca
parents: 6940
diff changeset
  2025
        zombie notNil ifTrue:[
8494
30334ff58607 fix error message
Stefan Vogel <sv@exept.de>
parents: 8456
diff changeset
  2026
            self error:'active process is zombie' mayProceed:true.
6990
a6bda971619f race with threadDestroy (leftOver process-structures in VM);
ca
parents: 6940
diff changeset
  2027
            self class threadDestroy:zombie.
a6bda971619f race with threadDestroy (leftOver process-structures in VM);
ca
parents: 6940
diff changeset
  2028
        ].
a6bda971619f race with threadDestroy (leftOver process-structures in VM);
ca
parents: 6940
diff changeset
  2029
a6bda971619f race with threadDestroy (leftOver process-structures in VM);
ca
parents: 6940
diff changeset
  2030
        self unRemember:aProcess.
6939
6f6ea7b0a5ab stopping an suspended process fix
Claus Gittinger <cg@exept.de>
parents: 6807
diff changeset
  2031
        zombie := id.
6990
a6bda971619f race with threadDestroy (leftOver process-structures in VM);
ca
parents: 6940
diff changeset
  2032
a6bda971619f race with threadDestroy (leftOver process-structures in VM);
ca
parents: 6940
diff changeset
  2033
        wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
6939
6f6ea7b0a5ab stopping an suspended process fix
Claus Gittinger <cg@exept.de>
parents: 6807
diff changeset
  2034
        self threadSwitch:scheduler.
6f6ea7b0a5ab stopping an suspended process fix
Claus Gittinger <cg@exept.de>
parents: 6807
diff changeset
  2035
        "not reached"
6f6ea7b0a5ab stopping an suspended process fix
Claus Gittinger <cg@exept.de>
parents: 6807
diff changeset
  2036
        ^ self
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2037
    ].
6990
a6bda971619f race with threadDestroy (leftOver process-structures in VM);
ca
parents: 6940
diff changeset
  2038
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2039
    self unRemember:aProcess.
6990
a6bda971619f race with threadDestroy (leftOver process-structures in VM);
ca
parents: 6940
diff changeset
  2040
    self class threadDestroy:id.
a6bda971619f race with threadDestroy (leftOver process-structures in VM);
ca
parents: 6940
diff changeset
  2041
a6bda971619f race with threadDestroy (leftOver process-structures in VM);
ca
parents: 6940
diff changeset
  2042
    wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
1618
9fb4ee952e89 use nil for empty lists
Claus Gittinger <cg@exept.de>
parents: 1606
diff changeset
  2043
1679
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  2044
    "Modified: 23.9.1996 / 13:50:24 / stefan"
2468
540067a4816b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2442
diff changeset
  2045
    "Modified: 20.3.1997 / 16:03:39 / cg"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2046
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2047
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2048
yield
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2049
    "move the currently running process to the end of the currentList
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2050
     and reschedule to the first in the list, thus switching to the 
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2051
     next same-prio-process."
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2052
1618
9fb4ee952e89 use nil for empty lists
Claus Gittinger <cg@exept.de>
parents: 1606
diff changeset
  2053
    |l sz wasBlocked|
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2054
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2055
    wasBlocked := OperatingSystem blockInterrupts.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2056
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
     debugging consistency check - will be removed later
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2059
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2060
    activeProcess priority ~~ currentPriority ifTrue:[
2534
6ac73e757c70 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2499
diff changeset
  2061
	'Processor [warning]: process changed its priority' errorPrintCR.
6ac73e757c70 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2499
diff changeset
  2062
	currentPriority := activeProcess priority.
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2063
    ].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2064
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2065
    l := quiescentProcessLists at:currentPriority.
1618
9fb4ee952e89 use nil for empty lists
Claus Gittinger <cg@exept.de>
parents: 1606
diff changeset
  2066
    sz := l size.
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
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2069
     debugging consistency checks - will be removed later
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2070
    "
1618
9fb4ee952e89 use nil for empty lists
Claus Gittinger <cg@exept.de>
parents: 1606
diff changeset
  2071
    sz == 0 ifTrue:[
2534
6ac73e757c70 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2499
diff changeset
  2072
	wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
6ac73e757c70 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2499
diff changeset
  2073
	'Processor [warning]: empty runnable list' errorPrintCR.
6ac73e757c70 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2499
diff changeset
  2074
	^ self
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2075
    ].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2076
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2077
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2078
     check if the running process is not the only one
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2079
    "
1618
9fb4ee952e89 use nil for empty lists
Claus Gittinger <cg@exept.de>
parents: 1606
diff changeset
  2080
    sz ~~ 1 ifTrue:[
2534
6ac73e757c70 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2499
diff changeset
  2081
	"
6ac73e757c70 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2499
diff changeset
  2082
	 bring running process to the end
6ac73e757c70 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2499
diff changeset
  2083
	"
6ac73e757c70 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2499
diff changeset
  2084
	l removeFirst.
6ac73e757c70 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2499
diff changeset
  2085
	l addLast:activeProcess.
6ac73e757c70 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2499
diff changeset
  2086
6ac73e757c70 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2499
diff changeset
  2087
	"
6ac73e757c70 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2499
diff changeset
  2088
	 and switch to first in the list
6ac73e757c70 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2499
diff changeset
  2089
	"
6ac73e757c70 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2499
diff changeset
  2090
	self threadSwitch:(l first).
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2091
    ].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2092
    wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
1086
7b0641a2e1ef nicer message
Claus Gittinger <cg@exept.de>
parents: 1061
diff changeset
  2093
2129
e03cd7bc3475 newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents: 2123
diff changeset
  2094
    "Modified: 10.1.1997 / 18:04:35 / cg"
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
7264
cf619b9f31b6 method category rename
Claus Gittinger <cg@exept.de>
parents: 7097
diff changeset
  2097
!ProcessorScheduler methodsFor:'scheduling-preemptive'!
2188
3814c1d74d2b integrated the timeSlicer
Claus Gittinger <cg@exept.de>
parents: 2155
diff changeset
  2098
3722
1114c2014bea added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents: 3718
diff changeset
  2099
recomputeDynamicPriorities
1114c2014bea added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents: 3718
diff changeset
  2100
    "recompute dynamic priorities."
1114c2014bea added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents: 3718
diff changeset
  2101
3728
970b2b4c9118 try to avoid object allocations in timeSlicers #recomputeDynamicPriorities.
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
  2102
    |processesDecreased processesToIncrease|
970b2b4c9118 try to avoid object allocations in timeSlicers #recomputeDynamicPriorities.
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
  2103
970b2b4c9118 try to avoid object allocations in timeSlicers #recomputeDynamicPriorities.
Claus Gittinger <cg@exept.de>
parents: 3724
diff changeset
  2104
    scheduledProcesses notNil ifTrue:[
5101
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2105
	"/ this is written a bit cryptic - to avoid creation
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2106
	"/ of garbage objects (Id'sets) if possible.
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2107
	"/ since this runs 50 times a second and most of the
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2108
	"/ time, no rescheduling is req'd
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2109
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2110
	scheduledProcesses do:[:aProcess |
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2111
	    |range prio|
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2112
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2113
	    "/ decrease priority of processes that did run
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2114
	    (range := aProcess priorityRange) notNil ifTrue:[
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2115
		aProcess priority > range start ifTrue:[
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2116
		    processesDecreased isNil ifTrue:[
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2117
			processesDecreased := IdentitySet new.
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2118
		    ].
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2119
		    processesDecreased add:aProcess.
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2120
		]
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2121
	    ]
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2122
	].
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2123
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2124
	processesDecreased notNil ifTrue:[
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2125
	    processesDecreased do:[:aProcess |
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2126
		|newPri|
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2127
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2128
		"/ newPri := aProcess priority - 1.
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2129
		newPri := aProcess priorityRange start.
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2130
		self changePriority:newPri for:aProcess.
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2131
	    ].
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2132
	].
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2133
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2134
	"/ and increase all prios of those that did not run, but are runnable
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2135
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2136
	TimeSlicingPriorityLimit to:1 by:-1 do:[:i |
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2137
	    |list|
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2138
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2139
	    (list := quiescentProcessLists at:i) size > 0 ifTrue:[
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2140
		list do:[:aProcess |
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2141
		    |range prio|
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2142
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2143
		    (range := aProcess priorityRange) notNil ifTrue:[
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2144
			(processesDecreased isNil
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2145
			or:[(processesDecreased includes:aProcess) not]) ifTrue:[
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2146
			    aProcess priority < range stop ifTrue:[
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2147
				processesToIncrease isNil ifTrue:[
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2148
				    processesToIncrease := IdentitySet new.
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2149
				].
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2150
				processesToIncrease add:aProcess
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2151
			    ]
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2152
			]
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2153
		    ]
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2154
		]
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2155
	    ]
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2156
	].
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2157
	processesToIncrease notNil ifTrue:[
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2158
	    processesToIncrease do:[:aProcess |
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2159
		self changePriority:(aProcess priority + 1) for:aProcess.
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2160
	    ].
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2161
	].
3722
1114c2014bea added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents: 3718
diff changeset
  2162
    ].
1114c2014bea added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents: 3718
diff changeset
  2163
3862
1a5b7b1ce72e drop dynamic prio to low-value instead of decrementing
Claus Gittinger <cg@exept.de>
parents: 3857
diff changeset
  2164
    "Modified: / 21.9.1998 / 09:07:54 / cg"
3790
629791828694 also keep track of scheduler processes, if
Claus Gittinger <cg@exept.de>
parents: 3787
diff changeset
  2165
!
629791828694 also keep track of scheduler processes, if
Claus Gittinger <cg@exept.de>
parents: 3787
diff changeset
  2166
629791828694 also keep track of scheduler processes, if
Claus Gittinger <cg@exept.de>
parents: 3787
diff changeset
  2167
scheduledProcesses
629791828694 also keep track of scheduler processes, if
Claus Gittinger <cg@exept.de>
parents: 3787
diff changeset
  2168
    "return a collection of recently scheduled processes.
629791828694 also keep track of scheduler processes, if
Claus Gittinger <cg@exept.de>
parents: 3787
diff changeset
  2169
     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
  2170
     scheduler is running"
629791828694 also keep track of scheduler processes, if
Claus Gittinger <cg@exept.de>
parents: 3787
diff changeset
  2171
629791828694 also keep track of scheduler processes, if
Claus Gittinger <cg@exept.de>
parents: 3787
diff changeset
  2172
    ^ scheduledProcesses ? #()
629791828694 also keep track of scheduler processes, if
Claus Gittinger <cg@exept.de>
parents: 3787
diff changeset
  2173
629791828694 also keep track of scheduler processes, if
Claus Gittinger <cg@exept.de>
parents: 3787
diff changeset
  2174
    "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
  2175
    "Modified: / 27.8.1998 / 12:56:35 / cg"
3722
1114c2014bea added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents: 3718
diff changeset
  2176
!
1114c2014bea added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents: 3718
diff changeset
  2177
2188
3814c1d74d2b integrated the timeSlicer
Claus Gittinger <cg@exept.de>
parents: 2155
diff changeset
  2178
slice
3814c1d74d2b integrated the timeSlicer
Claus Gittinger <cg@exept.de>
parents: 2155
diff changeset
  2179
    "Give other Processes at the current priority a chance to run."
3814c1d74d2b integrated the timeSlicer
Claus Gittinger <cg@exept.de>
parents: 2155
diff changeset
  2180
3814c1d74d2b integrated the timeSlicer
Claus Gittinger <cg@exept.de>
parents: 2155
diff changeset
  2181
    |i "{ Class: SmallInteger }"
3745
3fd121f2e74e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3740
diff changeset
  2182
     list wasBlocked|
3fd121f2e74e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3740
diff changeset
  2183
3fd121f2e74e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3740
diff changeset
  2184
    wasBlocked := OperatingSystem blockInterrupts.
2188
3814c1d74d2b integrated the timeSlicer
Claus Gittinger <cg@exept.de>
parents: 2155
diff changeset
  2185
2190
8afa4709d8a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2188
diff changeset
  2186
    i := TimeSlicingPriorityLimit.
2333
776bb9cb7b27 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2292
diff changeset
  2187
    [(i > 0) and:[(list := quiescentProcessLists at:i) size <= 1]] whileTrue: [i := i - 1].
3745
3fd121f2e74e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3740
diff changeset
  2188
    i ~~ 0 ifTrue: [
5101
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2189
	"/ shuffle that list
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2190
	list addLast:(list removeFirst).
3745
3fd121f2e74e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3740
diff changeset
  2191
    ].
3fd121f2e74e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3740
diff changeset
  2192
    wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
2188
3814c1d74d2b integrated the timeSlicer
Claus Gittinger <cg@exept.de>
parents: 2155
diff changeset
  2193
3724
49c043d9c0b3 dynamic priorities
Claus Gittinger <cg@exept.de>
parents: 3722
diff changeset
  2194
    "Modified: / 4.8.1998 / 00:13:32 / cg"
2188
3814c1d74d2b integrated the timeSlicer
Claus Gittinger <cg@exept.de>
parents: 2155
diff changeset
  2195
!
3814c1d74d2b integrated the timeSlicer
Claus Gittinger <cg@exept.de>
parents: 2155
diff changeset
  2196
3814c1d74d2b integrated the timeSlicer
Claus Gittinger <cg@exept.de>
parents: 2155
diff changeset
  2197
startTimeSlicing
2190
8afa4709d8a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2188
diff changeset
  2198
    "start preemptive scheduling (timeSlicing)"
8afa4709d8a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2188
diff changeset
  2199
8afa4709d8a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2188
diff changeset
  2200
    timeSliceProcess notNil ifTrue: [^ self].
8afa4709d8a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2188
diff changeset
  2201
2188
3814c1d74d2b integrated the timeSlicer
Claus Gittinger <cg@exept.de>
parents: 2155
diff changeset
  2202
    timeSliceProcess := [
6606
fa110cb8566c Use #ifCurtailed: instead of #valueOnUnwindDo:
Stefan Vogel <sv@exept.de>
parents: 6434
diff changeset
  2203
        [
fa110cb8566c Use #ifCurtailed: instead of #valueOnUnwindDo:
Stefan Vogel <sv@exept.de>
parents: 6434
diff changeset
  2204
            |myDelay t flipFlop|
fa110cb8566c Use #ifCurtailed: instead of #valueOnUnwindDo:
Stefan Vogel <sv@exept.de>
parents: 6434
diff changeset
  2205
fa110cb8566c Use #ifCurtailed: instead of #valueOnUnwindDo:
Stefan Vogel <sv@exept.de>
parents: 6434
diff changeset
  2206
            myDelay := Delay forMilliseconds:(t := TimeSliceInterval).
fa110cb8566c Use #ifCurtailed: instead of #valueOnUnwindDo:
Stefan Vogel <sv@exept.de>
parents: 6434
diff changeset
  2207
            flipFlop := true.
fa110cb8566c Use #ifCurtailed: instead of #valueOnUnwindDo:
Stefan Vogel <sv@exept.de>
parents: 6434
diff changeset
  2208
fa110cb8566c Use #ifCurtailed: instead of #valueOnUnwindDo:
Stefan Vogel <sv@exept.de>
parents: 6434
diff changeset
  2209
            [true] whileTrue: [
fa110cb8566c Use #ifCurtailed: instead of #valueOnUnwindDo:
Stefan Vogel <sv@exept.de>
parents: 6434
diff changeset
  2210
                t ~~ TimeSliceInterval ifTrue:[
fa110cb8566c Use #ifCurtailed: instead of #valueOnUnwindDo:
Stefan Vogel <sv@exept.de>
parents: 6434
diff changeset
  2211
                    "/ interval changed -> need a new delay
fa110cb8566c Use #ifCurtailed: instead of #valueOnUnwindDo:
Stefan Vogel <sv@exept.de>
parents: 6434
diff changeset
  2212
                    myDelay delay:(t := TimeSliceInterval).
fa110cb8566c Use #ifCurtailed: instead of #valueOnUnwindDo:
Stefan Vogel <sv@exept.de>
parents: 6434
diff changeset
  2213
                ].
fa110cb8566c Use #ifCurtailed: instead of #valueOnUnwindDo:
Stefan Vogel <sv@exept.de>
parents: 6434
diff changeset
  2214
                myDelay wait.
fa110cb8566c Use #ifCurtailed: instead of #valueOnUnwindDo:
Stefan Vogel <sv@exept.de>
parents: 6434
diff changeset
  2215
                self slice.
fa110cb8566c Use #ifCurtailed: instead of #valueOnUnwindDo:
Stefan Vogel <sv@exept.de>
parents: 6434
diff changeset
  2216
fa110cb8566c Use #ifCurtailed: instead of #valueOnUnwindDo:
Stefan Vogel <sv@exept.de>
parents: 6434
diff changeset
  2217
                "/ every other tick, recompute priorities.
fa110cb8566c Use #ifCurtailed: instead of #valueOnUnwindDo:
Stefan Vogel <sv@exept.de>
parents: 6434
diff changeset
  2218
                flipFlop := flipFlop not.
fa110cb8566c Use #ifCurtailed: instead of #valueOnUnwindDo:
Stefan Vogel <sv@exept.de>
parents: 6434
diff changeset
  2219
                flipFlop ifTrue:[
9120
c428cd8a9c52 recreate scheduledProcesses set for each cycle;
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
  2220
                    scheduledProcesses notNil ifTrue:[
6606
fa110cb8566c Use #ifCurtailed: instead of #valueOnUnwindDo:
Stefan Vogel <sv@exept.de>
parents: 6434
diff changeset
  2221
                        supportDynamicPriorities == true ifTrue:[
fa110cb8566c Use #ifCurtailed: instead of #valueOnUnwindDo:
Stefan Vogel <sv@exept.de>
parents: 6434
diff changeset
  2222
                            self recomputeDynamicPriorities.
fa110cb8566c Use #ifCurtailed: instead of #valueOnUnwindDo:
Stefan Vogel <sv@exept.de>
parents: 6434
diff changeset
  2223
                        ].
fa110cb8566c Use #ifCurtailed: instead of #valueOnUnwindDo:
Stefan Vogel <sv@exept.de>
parents: 6434
diff changeset
  2224
                        scheduledProcesses removeAll.
fa110cb8566c Use #ifCurtailed: instead of #valueOnUnwindDo:
Stefan Vogel <sv@exept.de>
parents: 6434
diff changeset
  2225
                    ].
9120
c428cd8a9c52 recreate scheduledProcesses set for each cycle;
Claus Gittinger <cg@exept.de>
parents: 8913
diff changeset
  2226
                    scheduledProcesses := IdentitySet new.
6606
fa110cb8566c Use #ifCurtailed: instead of #valueOnUnwindDo:
Stefan Vogel <sv@exept.de>
parents: 6434
diff changeset
  2227
                ].
fa110cb8566c Use #ifCurtailed: instead of #valueOnUnwindDo:
Stefan Vogel <sv@exept.de>
parents: 6434
diff changeset
  2228
            ]
fa110cb8566c Use #ifCurtailed: instead of #valueOnUnwindDo:
Stefan Vogel <sv@exept.de>
parents: 6434
diff changeset
  2229
        ] ifCurtailed:[
fa110cb8566c Use #ifCurtailed: instead of #valueOnUnwindDo:
Stefan Vogel <sv@exept.de>
parents: 6434
diff changeset
  2230
            timeSliceProcess := nil
fa110cb8566c Use #ifCurtailed: instead of #valueOnUnwindDo:
Stefan Vogel <sv@exept.de>
parents: 6434
diff changeset
  2231
        ]
2188
3814c1d74d2b integrated the timeSlicer
Claus Gittinger <cg@exept.de>
parents: 2155
diff changeset
  2232
    ] newProcess.
2190
8afa4709d8a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2188
diff changeset
  2233
    timeSliceProcess priority:HighestPriority.
2188
3814c1d74d2b integrated the timeSlicer
Claus Gittinger <cg@exept.de>
parents: 2155
diff changeset
  2234
    timeSliceProcess name:'time slicer'.
2831
02f9aa61f71b ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
  2235
    timeSliceProcess restartable:true.
2198
0537156f1fd7 make the timeSlicer a systemProcess
Claus Gittinger <cg@exept.de>
parents: 2193
diff changeset
  2236
    timeSliceProcess beSystemProcess.
2188
3814c1d74d2b integrated the timeSlicer
Claus Gittinger <cg@exept.de>
parents: 2155
diff changeset
  2237
    timeSliceProcess resume.
3814c1d74d2b integrated the timeSlicer
Claus Gittinger <cg@exept.de>
parents: 2155
diff changeset
  2238
3814c1d74d2b integrated the timeSlicer
Claus Gittinger <cg@exept.de>
parents: 2155
diff changeset
  2239
    "
2258
8894d33af5f6 reuse delays
Claus Gittinger <cg@exept.de>
parents: 2198
diff changeset
  2240
     Processor stopTimeSlicing.
8894d33af5f6 reuse delays
Claus Gittinger <cg@exept.de>
parents: 2198
diff changeset
  2241
     Processor startTimeSlicing.
2188
3814c1d74d2b integrated the timeSlicer
Claus Gittinger <cg@exept.de>
parents: 2155
diff changeset
  2242
    "
3814c1d74d2b integrated the timeSlicer
Claus Gittinger <cg@exept.de>
parents: 2155
diff changeset
  2243
3724
49c043d9c0b3 dynamic priorities
Claus Gittinger <cg@exept.de>
parents: 3722
diff changeset
  2244
    "Created: / 17.1.1997 / 16:42:02 / cg"
3790
629791828694 also keep track of scheduler processes, if
Claus Gittinger <cg@exept.de>
parents: 3787
diff changeset
  2245
    "Modified: / 27.8.1998 / 13:04:31 / cg"
2188
3814c1d74d2b integrated the timeSlicer
Claus Gittinger <cg@exept.de>
parents: 2155
diff changeset
  2246
!
3814c1d74d2b integrated the timeSlicer
Claus Gittinger <cg@exept.de>
parents: 2155
diff changeset
  2247
3814c1d74d2b integrated the timeSlicer
Claus Gittinger <cg@exept.de>
parents: 2155
diff changeset
  2248
stopTimeSlicing
2190
8afa4709d8a2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2188
diff changeset
  2249
    "stop preemptive scheduling (timeSlicing)"
2188
3814c1d74d2b integrated the timeSlicer
Claus Gittinger <cg@exept.de>
parents: 2155
diff changeset
  2250
3814c1d74d2b integrated the timeSlicer
Claus Gittinger <cg@exept.de>
parents: 2155
diff changeset
  2251
    timeSliceProcess notNil ifTrue: [
5101
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2252
	timeSliceProcess terminate.
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2253
	timeSliceProcess := nil.
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2254
	scheduledProcesses := nil
2188
3814c1d74d2b integrated the timeSlicer
Claus Gittinger <cg@exept.de>
parents: 2155
diff changeset
  2255
    ]
3814c1d74d2b integrated the timeSlicer
Claus Gittinger <cg@exept.de>
parents: 2155
diff changeset
  2256
3814c1d74d2b integrated the timeSlicer
Claus Gittinger <cg@exept.de>
parents: 2155
diff changeset
  2257
    "
3814c1d74d2b integrated the timeSlicer
Claus Gittinger <cg@exept.de>
parents: 2155
diff changeset
  2258
     Processor stopTimeSlicing
3814c1d74d2b integrated the timeSlicer
Claus Gittinger <cg@exept.de>
parents: 2155
diff changeset
  2259
    "
3814c1d74d2b integrated the timeSlicer
Claus Gittinger <cg@exept.de>
parents: 2155
diff changeset
  2260
3790
629791828694 also keep track of scheduler processes, if
Claus Gittinger <cg@exept.de>
parents: 3787
diff changeset
  2261
    "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
  2262
    "Modified: / 27.8.1998 / 13:00:37 / cg"
3722
1114c2014bea added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents: 3718
diff changeset
  2263
!
1114c2014bea added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents: 3718
diff changeset
  2264
1114c2014bea added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents: 3718
diff changeset
  2265
supportDynamicPriorities
1114c2014bea added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents: 3718
diff changeset
  2266
    "return true, if dynamic priorities are enabled"
1114c2014bea added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents: 3718
diff changeset
  2267
1114c2014bea added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents: 3718
diff changeset
  2268
    ^ supportDynamicPriorities
1114c2014bea added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents: 3718
diff changeset
  2269
1114c2014bea added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents: 3718
diff changeset
  2270
    "Created: / 3.8.1998 / 22:05:15 / cg"
1114c2014bea added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents: 3718
diff changeset
  2271
    "Modified: / 3.8.1998 / 22:55:08 / cg"
1114c2014bea added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents: 3718
diff changeset
  2272
!
1114c2014bea added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents: 3718
diff changeset
  2273
1114c2014bea added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents: 3718
diff changeset
  2274
supportDynamicPriorities:aBoolean
1114c2014bea added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents: 3718
diff changeset
  2275
    "enable/disable dynamic priorities"
1114c2014bea added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents: 3718
diff changeset
  2276
1114c2014bea added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents: 3718
diff changeset
  2277
    supportDynamicPriorities := aBoolean.
1114c2014bea added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents: 3718
diff changeset
  2278
1114c2014bea added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents: 3718
diff changeset
  2279
    "
1114c2014bea added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents: 3718
diff changeset
  2280
     Processor supportDynamicPriorities:true
1114c2014bea added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents: 3718
diff changeset
  2281
     Processor supportDynamicPriorities:false
1114c2014bea added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents: 3718
diff changeset
  2282
    "
1114c2014bea added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents: 3718
diff changeset
  2283
1114c2014bea added support for dynamic priorities.
Claus Gittinger <cg@exept.de>
parents: 3718
diff changeset
  2284
    "Modified: / 3.8.1998 / 22:54:52 / cg"
2188
3814c1d74d2b integrated the timeSlicer
Claus Gittinger <cg@exept.de>
parents: 2155
diff changeset
  2285
! !
3814c1d74d2b integrated the timeSlicer
Claus Gittinger <cg@exept.de>
parents: 2155
diff changeset
  2286
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2287
!ProcessorScheduler methodsFor:'semaphore signalling'!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2288
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2289
disableSemaphore:aSemaphore
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2290
    "disable triggering of a semaphore"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2291
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2292
    |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
  2293
     wasBlocked fd|
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2294
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2295
    wasBlocked := OperatingSystem blockInterrupts.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2296
    idx := readSemaphoreArray identityIndexOf:aSemaphore startingAt:1.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2297
    [idx ~~ 0] whileTrue:[
5101
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2298
	useIOInterrupts ifTrue:[
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2299
	    fd := readFdArray at:idx.
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2300
	    fd notNil ifTrue:[
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2301
		OperatingSystem disableIOInterruptsOn:fd
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2302
	    ].
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2303
	].
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2304
	readFdArray at:idx put:nil.
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2305
	readSemaphoreArray at:idx put:nil.
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2306
	readCheckArray at:idx put:nil.
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2307
	idx := readSemaphoreArray identityIndexOf:aSemaphore startingAt:idx+1.
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2308
    ].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2309
    idx := writeSemaphoreArray identityIndexOf:aSemaphore startingAt:1.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2310
    [idx ~~ 0] whileTrue:[
5101
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2311
	useIOInterrupts ifTrue:[
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2312
	    fd := writeFdArray at:idx.
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2313
	    fd notNil ifTrue:[
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2314
		OperatingSystem disableIOInterruptsOn:fd
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2315
	    ].
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2316
	].
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2317
	writeFdArray at:idx put:nil.
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2318
	writeSemaphoreArray at:idx put:nil.
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2319
	writeCheckArray at:idx put:nil.
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2320
	idx := writeSemaphoreArray identityIndexOf:aSemaphore startingAt:idx+1.
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
    idx := timeoutSemaphoreArray identityIndexOf:aSemaphore startingAt:1.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2323
    [idx ~~ 0] whileTrue:[
5101
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2324
	timeoutArray at:idx put:nil.
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2325
	timeoutSemaphoreArray at:idx put:nil.
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2326
	timeoutActionArray at:idx put:nil.
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2327
	timeoutProcessArray at:idx put:nil.
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2328
	idx := timeoutSemaphoreArray identityIndexOf:aSemaphore startingAt:idx+1.
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2329
    ].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2330
    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
  2331
02f9aa61f71b ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
  2332
    "Modified: 4.8.1997 / 15:19:33 / cg"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2333
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2334
1683
f7fed00976ab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1681
diff changeset
  2335
signal:aSemaphore
f7fed00976ab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1681
diff changeset
  2336
    "arrange for a semaphore to be triggered as soon as possible.
f7fed00976ab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1681
diff changeset
  2337
     The actual signalling is performed slightly delayed, when the dispatcher
2618
6d314138ab88 commentary
Claus Gittinger <cg@exept.de>
parents: 2614
diff changeset
  2338
     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
  2339
     process continues to execute, even if the semaphore signalling would
6d314138ab88 commentary
Claus Gittinger <cg@exept.de>
parents: 2614
diff changeset
  2340
     make a higher prio process runnable.
6d314138ab88 commentary
Claus Gittinger <cg@exept.de>
parents: 2614
diff changeset
  2341
     This is provided as entry for primitive-code (external functions)
6d314138ab88 commentary
Claus Gittinger <cg@exept.de>
parents: 2614
diff changeset
  2342
     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
  2343
     suspended (i.e. it is called by __STX_SignalSemaphore()).
6d314138ab88 commentary
Claus Gittinger <cg@exept.de>
parents: 2614
diff changeset
  2344
     Normal smalltalk code should always send an appropriate message directly
6d314138ab88 commentary
Claus Gittinger <cg@exept.de>
parents: 2614
diff changeset
  2345
     to the semaphore (i.e. aSemaphore signal)."
1683
f7fed00976ab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1681
diff changeset
  2346
3917
fd02c3beb3d1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3916
diff changeset
  2347
    self signal:aSemaphore atMilliseconds:OperatingSystem getMillisecondTime.
fd02c3beb3d1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3916
diff changeset
  2348
fd02c3beb3d1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3916
diff changeset
  2349
    "Modified: / 9.11.1998 / 20:39:06 / cg"
1683
f7fed00976ab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1681
diff changeset
  2350
!
f7fed00976ab checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1681
diff changeset
  2351
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2352
signal:aSemaphore afterMilliseconds:millis
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2353
    "arrange for a semaphore to be triggered after some milliseconds"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2354
3917
fd02c3beb3d1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3916
diff changeset
  2355
    |now then|
fd02c3beb3d1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3916
diff changeset
  2356
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2357
    now := OperatingSystem getMillisecondTime.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2358
    then := OperatingSystem millisecondTimeAdd:now and:millis rounded.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2359
    self signal:aSemaphore atMilliseconds:then.
3917
fd02c3beb3d1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3916
diff changeset
  2360
fd02c3beb3d1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3916
diff changeset
  2361
    "Modified: / 9.11.1998 / 20:39:27 / cg"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2362
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2363
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2364
signal:aSemaphore afterSeconds:seconds
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2365
    "arrange for a semaphore to be triggered after some seconds"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2366
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2367
    self signal:aSemaphore afterMilliseconds:(seconds * 1000)
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2368
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2369
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2370
signal:aSemaphore atMilliseconds:aMillisecondTime
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2371
    "arrange for a semaphore to be triggered at a specific millisecond time.
2618
6d314138ab88 commentary
Claus Gittinger <cg@exept.de>
parents: 2614
diff changeset
  2372
     If there is already a pending trigger time installed for that semaphore,
6d314138ab88 commentary
Claus Gittinger <cg@exept.de>
parents: 2614
diff changeset
  2373
     the time of the pending trigger is changed."
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2374
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2375
    |index "{ Class: SmallInteger }"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2376
     wasBlocked|
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2377
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2378
    wasBlocked := OperatingSystem blockInterrupts.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2379
    index := timeoutSemaphoreArray identityIndexOf:aSemaphore startingAt:1.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2380
    index ~~ 0 ifTrue:[
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2381
	timeoutArray at:index put:aMillisecondTime
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2382
    ] ifFalse:[
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2383
	index := timeoutArray identityIndexOf:nil startingAt:1.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2384
	index ~~ 0 ifTrue:[
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2385
	    timeoutSemaphoreArray at:index put:aSemaphore.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2386
	    timeoutArray at:index put:aMillisecondTime.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2387
	    timeoutActionArray at:index put:nil.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2388
	    timeoutProcessArray at:index put:nil 
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2389
	] ifFalse:[
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2390
	    timeoutSemaphoreArray := timeoutSemaphoreArray copyWith:aSemaphore.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2391
	    timeoutArray := timeoutArray copyWith:aMillisecondTime.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2392
	    timeoutActionArray := timeoutActionArray copyWith:nil.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2393
	    timeoutProcessArray := timeoutProcessArray copyWith:nil 
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2394
	].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2395
    ].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2396
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2397
    anyTimeouts := true.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2398
    wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2399
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2400
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2401
signal:aSemaphore onInput:aFileDescriptor
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2402
    "arrange for a semaphore to be triggered when input on aFileDescriptor
2622
62acc925dfc5 comment
Claus Gittinger <cg@exept.de>
parents: 2618
diff changeset
  2403
     arrives. This will only happen, if the OS supports selecting on fileDescriptors."
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2404
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2405
    self signal:aSemaphore onInput:aFileDescriptor orCheck:nil
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2406
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2407
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2408
signal:aSemaphore onInput:aFileDescriptor orCheck:aBlock
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2409
    "arrange for a semaphore to be triggered when input on aFileDescriptor
5101
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2410
     arrives OR checkblock evaluates to true. 
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2411
     The checkBlock will be evaluated by the scheduler from time to time 
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2412
     (i.e. every few milliseconds).
2618
6d314138ab88 commentary
Claus Gittinger <cg@exept.de>
parents: 2614
diff changeset
  2413
     (This is req'd for buffered input, where a select may not detect 
6d314138ab88 commentary
Claus Gittinger <cg@exept.de>
parents: 2614
diff changeset
  2414
      data which has already been read into a buffer - as in Xlib.
6d314138ab88 commentary
Claus Gittinger <cg@exept.de>
parents: 2614
diff changeset
  2415
      Or on systems, where we cannot select on a displays eventQ, such as windows)"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2416
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2417
    |idx "{ Class: SmallInteger }"
6807
ba04d2e1a416 oops - hps lexer is not 8-bit clean
Claus Gittinger <cg@exept.de>
parents: 6619
diff changeset
  2418
     wasBlocked|
1627
f95285226059 infoPrint for NT (no select)
Claus Gittinger <cg@exept.de>
parents: 1618
diff changeset
  2419
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2420
    wasBlocked := OperatingSystem blockInterrupts.
3116
e535e4e266dd more error handling;
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
  2421
6807
ba04d2e1a416 oops - hps lexer is not 8-bit clean
Claus Gittinger <cg@exept.de>
parents: 6619
diff changeset
  2422
    aFileDescriptor isNil ifTrue:[
3116
e535e4e266dd more error handling;
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
  2423
	(readCheckArray identityIndexOf:aBlock startingAt:1) == 0 ifTrue:[
5101
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2424
	    idx := readFdArray identityIndexOf:nil startingAt:1.
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2425
	    idx ~~ 0 ifTrue:[
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2426
		readFdArray at:idx put:aFileDescriptor.
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2427
		readSemaphoreArray at:idx put:aSemaphore.
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2428
		readCheckArray at:idx put:aBlock
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2429
	    ] ifFalse:[
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2430
		readFdArray := readFdArray copyWith:nil.
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2431
		readSemaphoreArray := readSemaphoreArray copyWith:aSemaphore.
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2432
		readCheckArray := readCheckArray copyWith:aBlock.
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2433
	    ]
3116
e535e4e266dd more error handling;
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
  2434
	]
e535e4e266dd more error handling;
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
  2435
    ] ifFalse:[
5101
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2436
	(readFdArray identityIndexOf:aFileDescriptor startingAt:1) == 0 ifTrue:[
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2437
	    idx := readFdArray identityIndexOf:nil startingAt:1.
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2438
	    idx ~~ 0 ifTrue:[
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2439
		readFdArray at:idx put:aFileDescriptor.
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2440
		readSemaphoreArray at:idx put:aSemaphore.
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2441
		readCheckArray at:idx put:aBlock
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2442
	    ] ifFalse:[
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2443
		readFdArray := readFdArray copyWith:aFileDescriptor.
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2444
		readSemaphoreArray := readSemaphoreArray copyWith:aSemaphore.
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2445
		readCheckArray := readCheckArray copyWith:aBlock.
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2446
	    ].
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2447
	    useIOInterrupts ifTrue:[
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2448
		OperatingSystem enableIOInterruptsOn:aFileDescriptor
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2449
	    ].
3116
e535e4e266dd more error handling;
Claus Gittinger <cg@exept.de>
parents: 2966
diff changeset
  2450
	]
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2451
    ].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2452
    wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
2123
6f9cb1ed9db5 new infoMessage scheme
Claus Gittinger <cg@exept.de>
parents: 2116
diff changeset
  2453
2831
02f9aa61f71b ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
  2454
    "Modified: 4.8.1997 / 15:20:45 / cg"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2455
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2456
5103
7b1f6c93b3aa checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5101
diff changeset
  2457
signal:aSemaphore onInputStream:aStream
7b1f6c93b3aa checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5101
diff changeset
  2458
    "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
  2459
     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
  2460
     otherwise, it will be polled every few milliseconds (MSDOS)."
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2461
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2462
    aStream canBeSelected ifTrue:[
6376
6a3ce5694cc9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6260
diff changeset
  2463
	"/ can this stream be selected on ?
6a3ce5694cc9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6260
diff changeset
  2464
	self signal:aSemaphore onInput:aStream fileDescriptor orCheck:nil
5101
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2465
    ] ifFalse:[
6376
6a3ce5694cc9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6260
diff changeset
  2466
	"/ nope - must poll ...
6a3ce5694cc9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6260
diff changeset
  2467
	self signal:aSemaphore onInput:nil orCheck:[aStream canReadWithoutBlocking]
5101
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2468
    ]
5107
1dc3079e8eaf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5103
diff changeset
  2469
1dc3079e8eaf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5103
diff changeset
  2470
    "Modified: / 14.12.1999 / 23:58:50 / cg"
5101
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2471
!
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2472
5103
7b1f6c93b3aa checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5101
diff changeset
  2473
signal:aSemaphore onOutput:aFileDescriptor
7b1f6c93b3aa checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5101
diff changeset
  2474
    "arrange for a semaphore to be triggered when output on aFileDescriptor
7b1f6c93b3aa checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5101
diff changeset
  2475
     is possible without blocking."
7b1f6c93b3aa checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5101
diff changeset
  2476
7b1f6c93b3aa checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5101
diff changeset
  2477
    self signal:aSemaphore onOutput:aFileDescriptor orCheck:nil
7b1f6c93b3aa checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5101
diff changeset
  2478
7b1f6c93b3aa checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5101
diff changeset
  2479
    "Created: / 14.12.1999 / 19:54:12 / cg"
7b1f6c93b3aa checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5101
diff changeset
  2480
!
7b1f6c93b3aa checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5101
diff changeset
  2481
5101
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2482
signal:aSemaphore onOutput:aFileDescriptor orCheck:aBlock
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2483
    "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
  2484
     is possible (i.e. can be written without blocking) or aBlock returns true.
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2485
     The checkBlock will be evaluated by the scheduler from time to time 
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2486
     (i.e. every few milliseconds).
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2487
     This checkBlock is required for poor windows, where a WaitForObject does
6807
ba04d2e1a416 oops - hps lexer is not 8-bit clean
Claus Gittinger <cg@exept.de>
parents: 6619
diff changeset
  2488
     not know about sockets."
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2489
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2490
    |idx "{ Class: SmallInteger }"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2491
     wasBlocked|
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2492
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2493
    wasBlocked := OperatingSystem blockInterrupts.
5101
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2494
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2495
    aFileDescriptor isNil ifTrue:[
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2496
	(writeCheckArray identityIndexOf:aBlock startingAt:1) == 0 ifTrue:[
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2497
	    idx := writeFdArray identityIndexOf:nil startingAt:1.
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2498
	    idx ~~ 0 ifTrue:[
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2499
		writeFdArray at:idx put:aFileDescriptor.
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2500
		writeSemaphoreArray at:idx put:aSemaphore.
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2501
		writeCheckArray at:idx put:aBlock
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2502
	    ] ifFalse:[
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2503
		writeFdArray := writeFdArray copyWith:nil.
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2504
		writeSemaphoreArray := writeSemaphoreArray copyWith:aSemaphore.
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2505
		writeCheckArray := writeCheckArray copyWith:aBlock.
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2506
	    ]
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2507
	]
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2508
    ] ifFalse:[
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2509
	(writeFdArray identityIndexOf:aFileDescriptor startingAt:1) == 0 ifTrue:[
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2510
	    idx := writeFdArray identityIndexOf:nil startingAt:1.
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2511
	    idx ~~ 0 ifTrue:[
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2512
		writeFdArray at:idx put:aFileDescriptor.
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2513
		writeSemaphoreArray at:idx put:aSemaphore.
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2514
		writeCheckArray at:idx put:aBlock
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2515
	    ] ifFalse:[
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2516
		writeFdArray := writeFdArray copyWith:aFileDescriptor.
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2517
		writeSemaphoreArray := writeSemaphoreArray copyWith:aSemaphore.
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2518
		writeCheckArray := writeCheckArray copyWith:aBlock.
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2519
	    ].
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2520
	    useIOInterrupts ifTrue:[
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2521
		OperatingSystem enableIOInterruptsOn:aFileDescriptor
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2522
	    ].
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2523
	]
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2524
    ].
5101
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  2525
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2526
    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
  2527
02f9aa61f71b ioInterrupts work (must set owner of fd's - at least on linux)
Claus Gittinger <cg@exept.de>
parents: 2830
diff changeset
  2528
    "Modified: 4.8.1997 / 15:21:49 / cg"
5103
7b1f6c93b3aa checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5101
diff changeset
  2529
!
7b1f6c93b3aa checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5101
diff changeset
  2530
7b1f6c93b3aa checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5101
diff changeset
  2531
signal:aSemaphore onOutputStream:aStream
7b1f6c93b3aa checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5101
diff changeset
  2532
    "arrange for a semaphore to be triggered when output on aStream is possible. 
7b1f6c93b3aa checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5101
diff changeset
  2533
     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
  2534
     otherwise, it will be polled every few milliseconds (MSDOS)."
7b1f6c93b3aa checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5101
diff changeset
  2535
7b1f6c93b3aa checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5101
diff changeset
  2536
    aStream canBeSelected ifTrue:[
6376
6a3ce5694cc9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6260
diff changeset
  2537
	"/ can this stream be selected on ?
6a3ce5694cc9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6260
diff changeset
  2538
	self signal:aSemaphore onOutput:aStream fileDescriptor orCheck:nil
5103
7b1f6c93b3aa checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5101
diff changeset
  2539
    ] ifFalse:[
6376
6a3ce5694cc9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6260
diff changeset
  2540
	"/ nope - must poll ...
6a3ce5694cc9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6260
diff changeset
  2541
	self signal:aSemaphore onOutput:nil orCheck:[aStream canWriteWithoutBlocking]
5103
7b1f6c93b3aa checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5101
diff changeset
  2542
    ]
5107
1dc3079e8eaf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5103
diff changeset
  2543
1dc3079e8eaf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5103
diff changeset
  2544
    "Modified: / 14.12.1999 / 23:59:19 / cg"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2545
! !
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2546
3650
523781600982 added #useIOInterrupts: to allow disabling this feature
Claus Gittinger <cg@exept.de>
parents: 3644
diff changeset
  2547
!ProcessorScheduler methodsFor:'special configuration'!
523781600982 added #useIOInterrupts: to allow disabling this feature
Claus Gittinger <cg@exept.de>
parents: 3644
diff changeset
  2548
523781600982 added #useIOInterrupts: to allow disabling this feature
Claus Gittinger <cg@exept.de>
parents: 3644
diff changeset
  2549
useIOInterrupts:aBoolean
523781600982 added #useIOInterrupts: to allow disabling this feature
Claus Gittinger <cg@exept.de>
parents: 3644
diff changeset
  2550
    "enable/disable the use of IO-interrupts.
523781600982 added #useIOInterrupts: to allow disabling this feature
Claus Gittinger <cg@exept.de>
parents: 3644
diff changeset
  2551
     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
  2552
     are polled in regular intervals.
523781600982 added #useIOInterrupts: to allow disabling this feature
Claus Gittinger <cg@exept.de>
parents: 3644
diff changeset
  2553
     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
  2554
     interrupt.
523781600982 added #useIOInterrupts: to allow disabling this feature
Claus Gittinger <cg@exept.de>
parents: 3644
diff changeset
  2555
     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
  2556
     (typically 2-7%).
523781600982 added #useIOInterrupts: to allow disabling this feature
Claus Gittinger <cg@exept.de>
parents: 3644
diff changeset
  2557
     Notice: 
6376
6a3ce5694cc9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6260
diff changeset
  2558
	some systems do not support IO-interrupts (or have a broken stdio-lib), 
6a3ce5694cc9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6260
diff changeset
  2559
	and this feature is always disabled;
3650
523781600982 added #useIOInterrupts: to allow disabling this feature
Claus Gittinger <cg@exept.de>
parents: 3644
diff changeset
  2560
     Also notice:
6376
6a3ce5694cc9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6260
diff changeset
  2561
	we found that in some Xlib-implementations, interrupted reads are not
6a3ce5694cc9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6260
diff changeset
  2562
	handled correctly (especially in multi-headed applications), and this
6a3ce5694cc9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6260
diff changeset
  2563
	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
  2564
523781600982 added #useIOInterrupts: to allow disabling this feature
Claus Gittinger <cg@exept.de>
parents: 3644
diff changeset
  2565
     If this method is used to disable IO interrupts in multi-headed apps, 
523781600982 added #useIOInterrupts: to allow disabling this feature
Claus Gittinger <cg@exept.de>
parents: 3644
diff changeset
  2566
     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
  2567
523781600982 added #useIOInterrupts: to allow disabling this feature
Claus Gittinger <cg@exept.de>
parents: 3644
diff changeset
  2568
    OperatingSystem supportsIOInterrupts ifTrue:[
6376
6a3ce5694cc9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6260
diff changeset
  2569
	useIOInterrupts := aBoolean
3650
523781600982 added #useIOInterrupts: to allow disabling this feature
Claus Gittinger <cg@exept.de>
parents: 3644
diff changeset
  2570
    ].
523781600982 added #useIOInterrupts: to allow disabling this feature
Claus Gittinger <cg@exept.de>
parents: 3644
diff changeset
  2571
523781600982 added #useIOInterrupts: to allow disabling this feature
Claus Gittinger <cg@exept.de>
parents: 3644
diff changeset
  2572
    "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
  2573
! !
523781600982 added #useIOInterrupts: to allow disabling this feature
Claus Gittinger <cg@exept.de>
parents: 3644
diff changeset
  2574
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2575
!ProcessorScheduler methodsFor:'timeout handling'!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2576
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2577
addTimedBlock:aBlock afterMilliseconds:delta
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2578
    "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
  2579
     evaluated after delta milliseconds. The process which installs this timed 
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2580
     block will be interrupted for execution of the block.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2581
     (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
  2582
      executing; if it is suspended, it will be resumed).
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2583
     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
  2584
     (i.e. it will trigger only once).
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  2585
     Returns an ID, which can be used in #removeTimeoutWidthID:"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2586
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2587
    ^ self addTimedBlock:aBlock for:activeProcess afterMilliseconds:delta
1676
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  2588
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  2589
    "Modified: 23.9.1996 / 14:33:59 / cg"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2590
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2591
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2592
addTimedBlock:aBlock afterSeconds:delta
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2593
    "add the argument, aBlock to the list of time-scheduled-blocks.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2594
     to be evaluated after delta seconds. The process which installs this timed 
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2595
     block will be interrupted for execution of the block.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2596
     (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
  2597
      executing; if it is suspended, it will be resumed).
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2598
     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
  2599
     (i.e. it will trigger only once).
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  2600
     Returns an ID, which can be used in #removeTimeoutWidthID:"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2601
1676
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  2602
    ^ self addTimedBlock:aBlock for:activeProcess afterMilliseconds:(delta * 1000) rounded
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  2603
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  2604
    "Modified: 23.9.1996 / 14:34:04 / cg"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2605
!
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
addTimedBlock:aBlock atMilliseconds:aMillisecondTime
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2608
    "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
  2609
     evaluated when the millisecondClock value passes aMillisecondTime.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2610
     The process which installs this timed block will be interrupted for 
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2611
     execution of the block.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2612
     (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
  2613
      executing; if it is suspended, it will be resumed).
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2614
     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
  2615
     (i.e. it will trigger only once).     
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  2616
     Returns an ID, which can be used in #removeTimeoutWidthID:"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2617
1676
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  2618
    ^ self addTimedBlock:aBlock for:activeProcess atMilliseconds:aMillisecondTime
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  2619
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  2620
    "Modified: 23.9.1996 / 14:34:09 / cg"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2621
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2622
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2623
addTimedBlock:aBlock for:aProcess afterMilliseconds:delta
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2624
    "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
  2625
     evaluated after delta milliseconds. The process specified by the argument,
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2626
     aProcess will be interrupted for execution of the block. 
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2627
     (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
  2628
      executing; if it is suspended, it will be resumed).
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2629
     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
  2630
     (which is dangerous - the block should not raise any error conditions).
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2631
     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
  2632
     (i.e. it will trigger only once).
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  2633
     Returns an ID, which can be used in #removeTimeoutWidthID:"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2634
1676
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  2635
    |now then wasBlocked id|
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2636
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2637
    wasBlocked := OperatingSystem blockInterrupts.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2638
    now := OperatingSystem getMillisecondTime.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2639
    then := OperatingSystem millisecondTimeAdd:now and:delta.
1676
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  2640
    id := self addTimedBlock:aBlock for:aProcess atMilliseconds:then.
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2641
    wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
1676
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  2642
    ^ id
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  2643
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  2644
    "Modified: 23.9.1996 / 14:34:13 / cg"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2645
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2646
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2647
addTimedBlock:aBlock for:aProcess afterSeconds:delta
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2648
    "add the argument, aBlock to the list of time-scheduled-blocks.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2649
     to be evaluated after delta seconds. aProcess will be interrupted for 
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2650
     execution of the block.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2651
     (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
  2652
      executing; if it is suspended, it will be resumed).
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2653
     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
  2654
     (which is dangerous - the block should not raise any error conditions).
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2655
     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
  2656
     (i.e. it will trigger only once).
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  2657
     Returns an ID, which can be used in #removeTimeoutWidthID:"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2658
1676
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  2659
    ^ self addTimedBlock:aBlock for:aProcess afterMilliseconds:(delta * 1000) rounded
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  2660
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  2661
    "Modified: 23.9.1996 / 14:34:18 / cg"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2662
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2663
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2664
addTimedBlock:aBlock for:aProcess atMilliseconds:aMillisecondTime
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2665
    "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
  2666
     evaluated by aProcess when the millisecondClock value passes 
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2667
     aMillisecondTime. 
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2668
     If that block is already in the timeout list, 
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2669
     its trigger-time is changed.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2670
     The process specified by the argument, aProcess will be interrupted 
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2671
     for execution of the block. 
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2672
     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
  2673
     (which is dangerous - the block should not raise any error conditions).
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2674
     If the process is active at trigger time, the interrupt will occur in 
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2675
     whatever method it is executing; if suspended at trigger time, it will be 
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2676
     resumed.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2677
     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
  2678
     (i.e. it will trigger only once).    
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  2679
     Returns an ID, which can be used in #removeTimeoutWidthID:"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2680
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2681
    |index "{ Class: SmallInteger }"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2682
     wasBlocked|
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2683
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2684
    wasBlocked := OperatingSystem blockInterrupts.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2685
    index := timeoutActionArray identityIndexOf:aBlock startingAt:1.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2686
    index ~~ 0 ifTrue:[
2534
6ac73e757c70 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2499
diff changeset
  2687
	timeoutArray at:index put:aMillisecondTime
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2688
    ] ifFalse:[
2534
6ac73e757c70 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2499
diff changeset
  2689
	index := timeoutArray indexOf:nil.
6ac73e757c70 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2499
diff changeset
  2690
	index ~~ 0 ifTrue:[
6ac73e757c70 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2499
diff changeset
  2691
	    timeoutArray at:index put:aMillisecondTime.
6ac73e757c70 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2499
diff changeset
  2692
	    timeoutActionArray at:index put:aBlock.
6ac73e757c70 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2499
diff changeset
  2693
	    timeoutSemaphoreArray at:index put:nil. 
6ac73e757c70 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2499
diff changeset
  2694
	    timeoutProcessArray at:index put:aProcess 
6ac73e757c70 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2499
diff changeset
  2695
	] ifFalse:[
6ac73e757c70 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2499
diff changeset
  2696
	    timeoutArray := timeoutArray copyWith:aMillisecondTime.
6ac73e757c70 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2499
diff changeset
  2697
	    timeoutActionArray := timeoutActionArray copyWith:aBlock.
6ac73e757c70 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2499
diff changeset
  2698
	    timeoutSemaphoreArray := timeoutSemaphoreArray copyWith:nil.
6ac73e757c70 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2499
diff changeset
  2699
	    timeoutProcessArray := timeoutProcessArray copyWith:aProcess.
6ac73e757c70 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2499
diff changeset
  2700
	    index := timeoutArray size.
6ac73e757c70 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2499
diff changeset
  2701
	].
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2702
    ].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2703
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2704
    anyTimeouts := true.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2705
    wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
1676
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  2706
    ^ index
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  2707
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  2708
    "Modified: 23.9.1996 / 14:34:23 / cg"
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  2709
!
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  2710
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  2711
addTimeoutFunctionCall:anExternalFunction for:aProcess afterMilliseconds:delta with:argument
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  2712
    "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
  2713
     after some millisecond-Delay.
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  2714
     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
  2715
     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
  2716
     in this processes context.
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  2717
     The callBack will be removed from the timed-block list after evaluation 
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  2718
     (i.e. it will trigger only once).
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  2719
     Returns an ID, which can be used in #removeTimeoutWidthID:"
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  2720
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  2721
    |now then wasBlocked id|
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  2722
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  2723
    wasBlocked := OperatingSystem blockInterrupts.
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  2724
    now := OperatingSystem getMillisecondTime.
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  2725
    then := OperatingSystem millisecondTimeAdd:now and:delta.
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  2726
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  2727
    id := self
2534
6ac73e757c70 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2499
diff changeset
  2728
	addTimeoutFunctionCall:anExternalFunction 
6ac73e757c70 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2499
diff changeset
  2729
	for:aProcess 
6ac73e757c70 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2499
diff changeset
  2730
	atMilliseconds:then 
6ac73e757c70 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2499
diff changeset
  2731
	with:argument.
1676
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  2732
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  2733
    wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  2734
    ^ id
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  2735
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  2736
    "Created: 23.9.1996 / 14:28:27 / cg"
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  2737
    "Modified: 23.9.1996 / 14:34:42 / cg"
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  2738
!
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  2739
1681
56d8d1d96d95 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1680
diff changeset
  2740
addTimeoutFunctionCall:anExternalFunction for:aProcess atMilliseconds:milliTime with:argument
1676
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  2741
    "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
  2742
     at some millisecond-time.
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  2743
     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
  2744
     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
  2745
     in this processes context.
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  2746
     The callBack will be removed from the timed-block list after evaluation 
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  2747
     (i.e. it will trigger only once).
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  2748
     Returns an ID, which can be used in #removeTimeoutWidthID:"
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  2749
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  2750
    |action|
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  2751
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  2752
    action := [anExternalFunction callWith:argument].
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  2753
    ^ self
2534
6ac73e757c70 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2499
diff changeset
  2754
	addTimedBlock:action 
6ac73e757c70 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2499
diff changeset
  2755
	for:aProcess 
6ac73e757c70 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2499
diff changeset
  2756
	atMilliseconds:milliTime.
1676
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  2757
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  2758
    "Created: 23.9.1996 / 14:29:30 / cg"
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  2759
    "Modified: 23.9.1996 / 14:34:57 / cg"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2760
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2761
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2762
evaluateTimeouts
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2763
    "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
  2764
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2765
    |sema now aTime block blocksToEvaluate 
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2766
     processes n "{ Class: SmallInteger }"|
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2767
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2768
    anyTimeouts ifFalse:[ ^ self].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2769
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2770
    "have to collect the blocks first, then evaluate them. This avoids
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2771
     problems due to newly inserted blocks."
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2772
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2773
    now := OperatingSystem getMillisecondTime.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2774
    blocksToEvaluate := nil.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2775
    n := timeoutArray size.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2776
    anyTimeouts := false.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2777
    1 to:n do:[:index |
9437
432a4a06934f + timeoutHandlerProcess
ca
parents: 9295
diff changeset
  2778
        aTime := timeoutArray at:index.
432a4a06934f + timeoutHandlerProcess
ca
parents: 9295
diff changeset
  2779
        aTime notNil ifTrue:[
432a4a06934f + timeoutHandlerProcess
ca
parents: 9295
diff changeset
  2780
            (OperatingSystem millisecondTime:aTime isAfter:now) ifFalse:[
432a4a06934f + timeoutHandlerProcess
ca
parents: 9295
diff changeset
  2781
                "this one should be triggered"
432a4a06934f + timeoutHandlerProcess
ca
parents: 9295
diff changeset
  2782
432a4a06934f + timeoutHandlerProcess
ca
parents: 9295
diff changeset
  2783
                sema := timeoutSemaphoreArray at:index.
432a4a06934f + timeoutHandlerProcess
ca
parents: 9295
diff changeset
  2784
                sema notNil ifTrue:[
432a4a06934f + timeoutHandlerProcess
ca
parents: 9295
diff changeset
  2785
                    timeoutSemaphoreArray at:index put:nil.
432a4a06934f + timeoutHandlerProcess
ca
parents: 9295
diff changeset
  2786
                    sema signalOnce.
432a4a06934f + timeoutHandlerProcess
ca
parents: 9295
diff changeset
  2787
                ] ifFalse:[
432a4a06934f + timeoutHandlerProcess
ca
parents: 9295
diff changeset
  2788
                    "to support pure-events"
432a4a06934f + timeoutHandlerProcess
ca
parents: 9295
diff changeset
  2789
                    block := timeoutActionArray at:index.
432a4a06934f + timeoutHandlerProcess
ca
parents: 9295
diff changeset
  2790
                    block notNil ifTrue:[
432a4a06934f + timeoutHandlerProcess
ca
parents: 9295
diff changeset
  2791
                        blocksToEvaluate isNil ifTrue:[
432a4a06934f + timeoutHandlerProcess
ca
parents: 9295
diff changeset
  2792
                            blocksToEvaluate := OrderedCollection new:10.
432a4a06934f + timeoutHandlerProcess
ca
parents: 9295
diff changeset
  2793
                            processes := OrderedCollection new:10.
432a4a06934f + timeoutHandlerProcess
ca
parents: 9295
diff changeset
  2794
                        ].
432a4a06934f + timeoutHandlerProcess
ca
parents: 9295
diff changeset
  2795
                        blocksToEvaluate add:block.
432a4a06934f + timeoutHandlerProcess
ca
parents: 9295
diff changeset
  2796
                        processes add:(timeoutProcessArray at:index).
432a4a06934f + timeoutHandlerProcess
ca
parents: 9295
diff changeset
  2797
                        timeoutActionArray at:index put:nil.
432a4a06934f + timeoutHandlerProcess
ca
parents: 9295
diff changeset
  2798
                        timeoutProcessArray at:index put:nil.
432a4a06934f + timeoutHandlerProcess
ca
parents: 9295
diff changeset
  2799
                    ]
432a4a06934f + timeoutHandlerProcess
ca
parents: 9295
diff changeset
  2800
                ].
432a4a06934f + timeoutHandlerProcess
ca
parents: 9295
diff changeset
  2801
                timeoutArray at:index put:nil.
432a4a06934f + timeoutHandlerProcess
ca
parents: 9295
diff changeset
  2802
            ] ifTrue:[
432a4a06934f + timeoutHandlerProcess
ca
parents: 9295
diff changeset
  2803
                anyTimeouts := true
432a4a06934f + timeoutHandlerProcess
ca
parents: 9295
diff changeset
  2804
            ]
432a4a06934f + timeoutHandlerProcess
ca
parents: 9295
diff changeset
  2805
        ]
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2806
    ].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2807
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2808
    blocksToEvaluate notNil ifTrue:[
9437
432a4a06934f + timeoutHandlerProcess
ca
parents: 9295
diff changeset
  2809
        blocksToEvaluate keysAndValuesDo:[:index :block |
432a4a06934f + timeoutHandlerProcess
ca
parents: 9295
diff changeset
  2810
            |p|
432a4a06934f + timeoutHandlerProcess
ca
parents: 9295
diff changeset
  2811
432a4a06934f + timeoutHandlerProcess
ca
parents: 9295
diff changeset
  2812
            p := processes at:index.
432a4a06934f + timeoutHandlerProcess
ca
parents: 9295
diff changeset
  2813
            (p isNil or:[p == scheduler or:[PureEventDriven]]) ifTrue:[
432a4a06934f + timeoutHandlerProcess
ca
parents: 9295
diff changeset
  2814
                block value
432a4a06934f + timeoutHandlerProcess
ca
parents: 9295
diff changeset
  2815
            ] ifFalse:[
432a4a06934f + timeoutHandlerProcess
ca
parents: 9295
diff changeset
  2816
                p isDead ifTrue:[
3246
092deb605639 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3245
diff changeset
  2817
                    
9437
432a4a06934f + timeoutHandlerProcess
ca
parents: 9295
diff changeset
  2818
                    "/ a timedBlock for a process which has already terminated
432a4a06934f + timeoutHandlerProcess
ca
parents: 9295
diff changeset
  2819
                    "/ issue a warning and do not execute it.
432a4a06934f + timeoutHandlerProcess
ca
parents: 9295
diff changeset
  2820
                    "/ (exeuting here may be dangerous, since it would run at scheduler priority here,
432a4a06934f + timeoutHandlerProcess
ca
parents: 9295
diff changeset
  2821
                    "/  and thereby could block the whole smalltalk system.
432a4a06934f + timeoutHandlerProcess
ca
parents: 9295
diff changeset
  2822
                    "/  For this reason is it IGNORED here.)
3246
092deb605639 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3245
diff changeset
  2823
                    
9437
432a4a06934f + timeoutHandlerProcess
ca
parents: 9295
diff changeset
  2824
                    ('ProcessorScheduler [warning]: cannot evaluate timedBlock for dead process: ''' , p name , '''') infoPrintCR.
432a4a06934f + timeoutHandlerProcess
ca
parents: 9295
diff changeset
  2825
                    ('ProcessorScheduler [warning]: the timedBlock is: ' , block displayString) infoPrintCR.
432a4a06934f + timeoutHandlerProcess
ca
parents: 9295
diff changeset
  2826
                ] ifFalse:[
432a4a06934f + timeoutHandlerProcess
ca
parents: 9295
diff changeset
  2827
                    p interruptWith:block
432a4a06934f + timeoutHandlerProcess
ca
parents: 9295
diff changeset
  2828
                ]
432a4a06934f + timeoutHandlerProcess
ca
parents: 9295
diff changeset
  2829
            ]
432a4a06934f + timeoutHandlerProcess
ca
parents: 9295
diff changeset
  2830
        ]
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2831
    ]
3245
863c0a09f5a2 issue a warning if a timedBlock is to be evaluated for a dead thread
Claus Gittinger <cg@exept.de>
parents: 3116
diff changeset
  2832
3917
fd02c3beb3d1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3916
diff changeset
  2833
    "Modified: / 9.11.1998 / 21:25:02 / cg"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2834
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2835
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2836
removeTimedBlock:aBlock
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2837
    "remove the argument, aBlock from the list of time-sceduled-blocks."
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2838
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2839
    |index "{ Class: SmallInteger }"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2840
     wasBlocked|
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2841
3916
cec84c84864c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3862
diff changeset
  2842
    aBlock isNil ifTrue:[^ self].
cec84c84864c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3862
diff changeset
  2843
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2844
    wasBlocked := OperatingSystem blockInterrupts.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2845
    index := timeoutActionArray identityIndexOf:aBlock startingAt:1.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2846
    (index ~~ 0) ifTrue:[
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2847
	timeoutArray at:index put:nil.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2848
	timeoutActionArray at:index put:nil. 
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2849
	timeoutSemaphoreArray at:index put:nil.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2850
	timeoutProcessArray at:index put:nil.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2851
    ].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2852
    wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
1676
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  2853
!
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  2854
1680
b90690d9d6c5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1679
diff changeset
  2855
removeTimeoutWithID:anID
1676
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  2856
    "remove the timeOut with anID (as returned by #addTimedBlock)
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  2857
     from the list of time-sceduled-blocks."
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  2858
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  2859
    |index "{ Class: SmallInteger }"
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  2860
     wasBlocked|
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  2861
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  2862
    index := anID.
1680
b90690d9d6c5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1679
diff changeset
  2863
    (index > 0) ifTrue:[
2534
6ac73e757c70 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2499
diff changeset
  2864
	wasBlocked := OperatingSystem blockInterrupts.
6ac73e757c70 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2499
diff changeset
  2865
6ac73e757c70 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2499
diff changeset
  2866
	timeoutArray at:index put:nil.
6ac73e757c70 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2499
diff changeset
  2867
	timeoutActionArray at:index put:nil. 
6ac73e757c70 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2499
diff changeset
  2868
	timeoutSemaphoreArray at:index put:nil.
6ac73e757c70 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2499
diff changeset
  2869
	timeoutProcessArray at:index put:nil.
6ac73e757c70 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2499
diff changeset
  2870
6ac73e757c70 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2499
diff changeset
  2871
	wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
1680
b90690d9d6c5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1679
diff changeset
  2872
    ]
1676
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  2873
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  2874
    "Created: 23.9.1996 / 14:32:33 / cg"
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  2875
    "Modified: 23.9.1996 / 14:35:09 / cg"
9437
432a4a06934f + timeoutHandlerProcess
ca
parents: 9295
diff changeset
  2876
!
432a4a06934f + timeoutHandlerProcess
ca
parents: 9295
diff changeset
  2877
432a4a06934f + timeoutHandlerProcess
ca
parents: 9295
diff changeset
  2878
timeoutHandlerProcess
9452
921f2690dfe6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9450
diff changeset
  2879
    (timeoutHandlerProcess isNil or:[timeoutHandlerProcess isDead]) ifTrue:[
9450
cc3954feef43 timeoutHandler clearing
Claus Gittinger <cg@exept.de>
parents: 9437
diff changeset
  2880
        timeoutHandlerProcess := 
cc3954feef43 timeoutHandler clearing
Claus Gittinger <cg@exept.de>
parents: 9437
diff changeset
  2881
                [ 
cc3954feef43 timeoutHandler clearing
Claus Gittinger <cg@exept.de>
parents: 9437
diff changeset
  2882
                    [
cc3954feef43 timeoutHandler clearing
Claus Gittinger <cg@exept.de>
parents: 9437
diff changeset
  2883
                        [true] whileTrue:[self timeoutHandlerProcessLoop]
cc3954feef43 timeoutHandler clearing
Claus Gittinger <cg@exept.de>
parents: 9437
diff changeset
  2884
                    ] ensure:[ timeoutHandlerProcess := nil ].
cc3954feef43 timeoutHandler clearing
Claus Gittinger <cg@exept.de>
parents: 9437
diff changeset
  2885
                ] newProcess. 
9437
432a4a06934f + timeoutHandlerProcess
ca
parents: 9295
diff changeset
  2886
        timeoutHandlerProcess priority:TimingPriority.
432a4a06934f + timeoutHandlerProcess
ca
parents: 9295
diff changeset
  2887
        timeoutHandlerProcess name:'Timeout handler'.
432a4a06934f + timeoutHandlerProcess
ca
parents: 9295
diff changeset
  2888
        timeoutHandlerProcess resume.
432a4a06934f + timeoutHandlerProcess
ca
parents: 9295
diff changeset
  2889
    ].
432a4a06934f + timeoutHandlerProcess
ca
parents: 9295
diff changeset
  2890
    ^ timeoutHandlerProcess.
9450
cc3954feef43 timeoutHandler clearing
Claus Gittinger <cg@exept.de>
parents: 9437
diff changeset
  2891
9452
921f2690dfe6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9450
diff changeset
  2892
    "Modified: / 20-07-2006 / 09:52:27 / cg"
9437
432a4a06934f + timeoutHandlerProcess
ca
parents: 9295
diff changeset
  2893
!
432a4a06934f + timeoutHandlerProcess
ca
parents: 9295
diff changeset
  2894
432a4a06934f + timeoutHandlerProcess
ca
parents: 9295
diff changeset
  2895
timeoutHandlerProcessLoop
432a4a06934f + timeoutHandlerProcess
ca
parents: 9295
diff changeset
  2896
    Semaphore new wait.
10
claus
parents: 3
diff changeset
  2897
! !
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2898
6619
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
  2899
!ProcessorScheduler methodsFor:'wait hooks'!
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
  2900
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
  2901
addPreWaitAction:aBlock
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
  2902
    "add the argument, aBlock to the list of preWait-actions.
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
  2903
     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
  2904
     (i.e. the OS-wait for next event or timeout).
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
  2905
     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
  2906
     to force unflushed output to be sent out in regular intervals)"
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
  2907
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
  2908
    |wasBlocked|
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
  2909
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
  2910
    wasBlocked := OperatingSystem blockInterrupts.
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
  2911
    preWaitActions isNil ifTrue:[
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
  2912
        preWaitActions := OrderedCollection new
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
  2913
    ].
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
  2914
    preWaitActions add:aBlock.
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
  2915
    wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
  2916
!
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
  2917
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
  2918
removePreWaitAction:aBlock
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
  2919
    "remove the argument, aBlock from the list of preWait-actions."
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
  2920
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
  2921
    |wasBlocked|
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
  2922
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
  2923
    wasBlocked := OperatingSystem blockInterrupts.
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
  2924
    preWaitActions notNil ifTrue:[
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
  2925
       preWaitActions removeIdentical:aBlock ifAbsent:nil
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
  2926
    ].
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
  2927
    wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
  2928
! !
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
  2929
10
claus
parents: 3
diff changeset
  2930
!ProcessorScheduler methodsFor:'waiting'!
claus
parents: 3
diff changeset
  2931
7510
46a848d466b5 select: wake up readFDs if readable only;
Claus Gittinger <cg@exept.de>
parents: 7495
diff changeset
  2932
checkForIOWithTimeout:millis
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2933
    "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
  2934
     hard wait for either input to arrive, or output to be possible
46a848d466b5 select: wake up readFDs if readable only;
Claus Gittinger <cg@exept.de>
parents: 7495
diff changeset
  2935
     or a timeout to occur."
46a848d466b5 select: wake up readFDs if readable only;
Claus Gittinger <cg@exept.de>
parents: 7495
diff changeset
  2936
46a848d466b5 select: wake up readFDs if readable only;
Claus Gittinger <cg@exept.de>
parents: 7495
diff changeset
  2937
    |nReady index sema action wasBlocked err fd readyIndex
46a848d466b5 select: wake up readFDs if readable only;
Claus Gittinger <cg@exept.de>
parents: 7495
diff changeset
  2938
     readableResultFdArray writableResultFdArray newProcessMaybeReady|
2116
1bcb6ee86fca fixed pending sigChild problem;
Claus Gittinger <cg@exept.de>
parents: 2111
diff changeset
  2939
1bcb6ee86fca fixed pending sigChild problem;
Claus Gittinger <cg@exept.de>
parents: 2111
diff changeset
  2940
    "/ must enable interrupts, to be able to get out of a
1bcb6ee86fca fixed pending sigChild problem;
Claus Gittinger <cg@exept.de>
parents: 2111
diff changeset
  2941
    "/ long wait (especially, to handle sigChild in the meantime)
1bcb6ee86fca fixed pending sigChild problem;
Claus Gittinger <cg@exept.de>
parents: 2111
diff changeset
  2942
8504
93b46834c68f #unblockInterrupts returns the prvious blocking state
Stefan Vogel <sv@exept.de>
parents: 8494
diff changeset
  2943
    wasBlocked := OperatingSystem unblockInterrupts.
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2944
7532
7612ff7ef377 oops - Win32OS does not yet support new select interface
Claus Gittinger <cg@exept.de>
parents: 7510
diff changeset
  2945
    OperatingSystem isMSWINDOWSlike ifTrue:[
7612ff7ef377 oops - Win32OS does not yet support new select interface
Claus Gittinger <cg@exept.de>
parents: 7510
diff changeset
  2946
        "/ temporary kludge - until interface below is implemented in Win32OS
7612ff7ef377 oops - Win32OS does not yet support new select interface
Claus Gittinger <cg@exept.de>
parents: 7510
diff changeset
  2947
        fd := OperatingSystem 
7612ff7ef377 oops - Win32OS does not yet support new select interface
Claus Gittinger <cg@exept.de>
parents: 7510
diff changeset
  2948
                  selectOnAnyReadable:readFdArray 
7612ff7ef377 oops - Win32OS does not yet support new select interface
Claus Gittinger <cg@exept.de>
parents: 7510
diff changeset
  2949
                  writable:writeFdArray
7612ff7ef377 oops - Win32OS does not yet support new select interface
Claus Gittinger <cg@exept.de>
parents: 7510
diff changeset
  2950
                  exception:nil 
7612ff7ef377 oops - Win32OS does not yet support new select interface
Claus Gittinger <cg@exept.de>
parents: 7510
diff changeset
  2951
                  withTimeOut:millis.
7612ff7ef377 oops - Win32OS does not yet support new select interface
Claus Gittinger <cg@exept.de>
parents: 7510
diff changeset
  2952
        wasBlocked ifTrue:[
7612ff7ef377 oops - Win32OS does not yet support new select interface
Claus Gittinger <cg@exept.de>
parents: 7510
diff changeset
  2953
            OperatingSystem blockInterrupts.
7612ff7ef377 oops - Win32OS does not yet support new select interface
Claus Gittinger <cg@exept.de>
parents: 7510
diff changeset
  2954
        ].
7612ff7ef377 oops - Win32OS does not yet support new select interface
Claus Gittinger <cg@exept.de>
parents: 7510
diff changeset
  2955
7612ff7ef377 oops - Win32OS does not yet support new select interface
Claus Gittinger <cg@exept.de>
parents: 7510
diff changeset
  2956
        fd isNil ifTrue:[
7612ff7ef377 oops - Win32OS does not yet support new select interface
Claus Gittinger <cg@exept.de>
parents: 7510
diff changeset
  2957
            "/ either still nothing to do,
7612ff7ef377 oops - Win32OS does not yet support new select interface
Claus Gittinger <cg@exept.de>
parents: 7510
diff changeset
  2958
            "/ or error (which should not happen)
7612ff7ef377 oops - Win32OS does not yet support new select interface
Claus Gittinger <cg@exept.de>
parents: 7510
diff changeset
  2959
7612ff7ef377 oops - Win32OS does not yet support new select interface
Claus Gittinger <cg@exept.de>
parents: 7510
diff changeset
  2960
            (err := OperatingSystem lastErrorSymbol) notNil ifTrue:[
7612ff7ef377 oops - Win32OS does not yet support new select interface
Claus Gittinger <cg@exept.de>
parents: 7510
diff changeset
  2961
                err == #EBADF ifTrue:[
7612ff7ef377 oops - Win32OS does not yet support new select interface
Claus Gittinger <cg@exept.de>
parents: 7510
diff changeset
  2962
7612ff7ef377 oops - Win32OS does not yet support new select interface
Claus Gittinger <cg@exept.de>
parents: 7510
diff changeset
  2963
                    "/ mhmh - one of the fd's given to me is corrupt.
7612ff7ef377 oops - Win32OS does not yet support new select interface
Claus Gittinger <cg@exept.de>
parents: 7510
diff changeset
  2964
                    "/ find out which one .... and remove it
7612ff7ef377 oops - Win32OS does not yet support new select interface
Claus Gittinger <cg@exept.de>
parents: 7510
diff changeset
  2965
7612ff7ef377 oops - Win32OS does not yet support new select interface
Claus Gittinger <cg@exept.de>
parents: 7510
diff changeset
  2966
                    'Processor [info]: obsolete FD in select - clearing' infoPrintCR.
7612ff7ef377 oops - Win32OS does not yet support new select interface
Claus Gittinger <cg@exept.de>
parents: 7510
diff changeset
  2967
                    OperatingSystem clearLastErrorNumber.
7612ff7ef377 oops - Win32OS does not yet support new select interface
Claus Gittinger <cg@exept.de>
parents: 7510
diff changeset
  2968
                    self removeCorruptedFds
7612ff7ef377 oops - Win32OS does not yet support new select interface
Claus Gittinger <cg@exept.de>
parents: 7510
diff changeset
  2969
                ] ifFalse:[
7612ff7ef377 oops - Win32OS does not yet support new select interface
Claus Gittinger <cg@exept.de>
parents: 7510
diff changeset
  2970
                    err == #ENOENT ifTrue:[
7612ff7ef377 oops - Win32OS does not yet support new select interface
Claus Gittinger <cg@exept.de>
parents: 7510
diff changeset
  2971
                        'Processor [warning]: ENOENT in select; rd=' infoPrint.
7612ff7ef377 oops - Win32OS does not yet support new select interface
Claus Gittinger <cg@exept.de>
parents: 7510
diff changeset
  2972
                        readFdArray infoPrint.
7612ff7ef377 oops - Win32OS does not yet support new select interface
Claus Gittinger <cg@exept.de>
parents: 7510
diff changeset
  2973
                        ' wr=' infoPrint.
7612ff7ef377 oops - Win32OS does not yet support new select interface
Claus Gittinger <cg@exept.de>
parents: 7510
diff changeset
  2974
                        writeFdArray infoPrintCR.
7612ff7ef377 oops - Win32OS does not yet support new select interface
Claus Gittinger <cg@exept.de>
parents: 7510
diff changeset
  2975
                    ] ifFalse:[
10233
4006fa954217 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9991
diff changeset
  2976
                        "/ 'Processor [warning]: error in select: ' infoPrint. err infoPrintCR.
7532
7612ff7ef377 oops - Win32OS does not yet support new select interface
Claus Gittinger <cg@exept.de>
parents: 7510
diff changeset
  2977
                    ]
7612ff7ef377 oops - Win32OS does not yet support new select interface
Claus Gittinger <cg@exept.de>
parents: 7510
diff changeset
  2978
                ].
7612ff7ef377 oops - Win32OS does not yet support new select interface
Claus Gittinger <cg@exept.de>
parents: 7510
diff changeset
  2979
            ]
7612ff7ef377 oops - Win32OS does not yet support new select interface
Claus Gittinger <cg@exept.de>
parents: 7510
diff changeset
  2980
        ] ifFalse:[
7612ff7ef377 oops - Win32OS does not yet support new select interface
Claus Gittinger <cg@exept.de>
parents: 7510
diff changeset
  2981
            index := readFdArray identityIndexOf:fd.
7612ff7ef377 oops - Win32OS does not yet support new select interface
Claus Gittinger <cg@exept.de>
parents: 7510
diff changeset
  2982
            index ~~ 0 ifTrue:[
7612ff7ef377 oops - Win32OS does not yet support new select interface
Claus Gittinger <cg@exept.de>
parents: 7510
diff changeset
  2983
                sema := readSemaphoreArray at:index.
7612ff7ef377 oops - Win32OS does not yet support new select interface
Claus Gittinger <cg@exept.de>
parents: 7510
diff changeset
  2984
                sema notNil ifTrue:[
7612ff7ef377 oops - Win32OS does not yet support new select interface
Claus Gittinger <cg@exept.de>
parents: 7510
diff changeset
  2985
                    sema signalOnce.
7612ff7ef377 oops - Win32OS does not yet support new select interface
Claus Gittinger <cg@exept.de>
parents: 7510
diff changeset
  2986
                    ^ true
7612ff7ef377 oops - Win32OS does not yet support new select interface
Claus Gittinger <cg@exept.de>
parents: 7510
diff changeset
  2987
                ].
7612ff7ef377 oops - Win32OS does not yet support new select interface
Claus Gittinger <cg@exept.de>
parents: 7510
diff changeset
  2988
                action := readCheckArray at:index.
7612ff7ef377 oops - Win32OS does not yet support new select interface
Claus Gittinger <cg@exept.de>
parents: 7510
diff changeset
  2989
                action notNil ifTrue:[
7612ff7ef377 oops - Win32OS does not yet support new select interface
Claus Gittinger <cg@exept.de>
parents: 7510
diff changeset
  2990
                    action value.
7612ff7ef377 oops - Win32OS does not yet support new select interface
Claus Gittinger <cg@exept.de>
parents: 7510
diff changeset
  2991
                     ^ true
7612ff7ef377 oops - Win32OS does not yet support new select interface
Claus Gittinger <cg@exept.de>
parents: 7510
diff changeset
  2992
                ]
7612ff7ef377 oops - Win32OS does not yet support new select interface
Claus Gittinger <cg@exept.de>
parents: 7510
diff changeset
  2993
            ].
7612ff7ef377 oops - Win32OS does not yet support new select interface
Claus Gittinger <cg@exept.de>
parents: 7510
diff changeset
  2994
            index := writeFdArray identityIndexOf:fd.
7612ff7ef377 oops - Win32OS does not yet support new select interface
Claus Gittinger <cg@exept.de>
parents: 7510
diff changeset
  2995
            index ~~ 0 ifTrue:[
7612ff7ef377 oops - Win32OS does not yet support new select interface
Claus Gittinger <cg@exept.de>
parents: 7510
diff changeset
  2996
                sema := writeSemaphoreArray at:index.
7612ff7ef377 oops - Win32OS does not yet support new select interface
Claus Gittinger <cg@exept.de>
parents: 7510
diff changeset
  2997
                sema notNil ifTrue:[
7612ff7ef377 oops - Win32OS does not yet support new select interface
Claus Gittinger <cg@exept.de>
parents: 7510
diff changeset
  2998
                    sema signalOnce.
7612ff7ef377 oops - Win32OS does not yet support new select interface
Claus Gittinger <cg@exept.de>
parents: 7510
diff changeset
  2999
                     ^ true
7612ff7ef377 oops - Win32OS does not yet support new select interface
Claus Gittinger <cg@exept.de>
parents: 7510
diff changeset
  3000
                ].
7612ff7ef377 oops - Win32OS does not yet support new select interface
Claus Gittinger <cg@exept.de>
parents: 7510
diff changeset
  3001
                action := writeCheckArray at:index.
7612ff7ef377 oops - Win32OS does not yet support new select interface
Claus Gittinger <cg@exept.de>
parents: 7510
diff changeset
  3002
                action notNil ifTrue:[
7612ff7ef377 oops - Win32OS does not yet support new select interface
Claus Gittinger <cg@exept.de>
parents: 7510
diff changeset
  3003
                    action value.
7612ff7ef377 oops - Win32OS does not yet support new select interface
Claus Gittinger <cg@exept.de>
parents: 7510
diff changeset
  3004
                     ^ true
7612ff7ef377 oops - Win32OS does not yet support new select interface
Claus Gittinger <cg@exept.de>
parents: 7510
diff changeset
  3005
                ]
7612ff7ef377 oops - Win32OS does not yet support new select interface
Claus Gittinger <cg@exept.de>
parents: 7510
diff changeset
  3006
            ]
7612ff7ef377 oops - Win32OS does not yet support new select interface
Claus Gittinger <cg@exept.de>
parents: 7510
diff changeset
  3007
        ].
7612ff7ef377 oops - Win32OS does not yet support new select interface
Claus Gittinger <cg@exept.de>
parents: 7510
diff changeset
  3008
        ^ false
7612ff7ef377 oops - Win32OS does not yet support new select interface
Claus Gittinger <cg@exept.de>
parents: 7510
diff changeset
  3009
    ].
7612ff7ef377 oops - Win32OS does not yet support new select interface
Claus Gittinger <cg@exept.de>
parents: 7510
diff changeset
  3010
7493
5c67c45b11cb New select for fair scheduling (not giving low filedescriptors
Stefan Vogel <sv@exept.de>
parents: 7264
diff changeset
  3011
    newProcessMaybeReady := false.
7510
46a848d466b5 select: wake up readFDs if readable only;
Claus Gittinger <cg@exept.de>
parents: 7495
diff changeset
  3012
    readableResultFdArray := Array new:40.
46a848d466b5 select: wake up readFDs if readable only;
Claus Gittinger <cg@exept.de>
parents: 7495
diff changeset
  3013
    writableResultFdArray := Array new:40.
46a848d466b5 select: wake up readFDs if readable only;
Claus Gittinger <cg@exept.de>
parents: 7495
diff changeset
  3014
46a848d466b5 select: wake up readFDs if readable only;
Claus Gittinger <cg@exept.de>
parents: 7495
diff changeset
  3015
    nReady := OperatingSystem
46a848d466b5 select: wake up readFDs if readable only;
Claus Gittinger <cg@exept.de>
parents: 7495
diff changeset
  3016
        selectOnAnyReadable:readFdArray     
46a848d466b5 select: wake up readFDs if readable only;
Claus Gittinger <cg@exept.de>
parents: 7495
diff changeset
  3017
        writable:writeFdArray 
46a848d466b5 select: wake up readFDs if readable only;
Claus Gittinger <cg@exept.de>
parents: 7495
diff changeset
  3018
        exception:nil 
46a848d466b5 select: wake up readFDs if readable only;
Claus Gittinger <cg@exept.de>
parents: 7495
diff changeset
  3019
        readableInto:readableResultFdArray 
46a848d466b5 select: wake up readFDs if readable only;
Claus Gittinger <cg@exept.de>
parents: 7495
diff changeset
  3020
        writableInto:writableResultFdArray 
46a848d466b5 select: wake up readFDs if readable only;
Claus Gittinger <cg@exept.de>
parents: 7495
diff changeset
  3021
        exceptionInto:nil
46a848d466b5 select: wake up readFDs if readable only;
Claus Gittinger <cg@exept.de>
parents: 7495
diff changeset
  3022
        withTimeOut:millis.
1061
61012b7bed9c protect myself against invalid fd's in readFdArray/writeFdArray
Claus Gittinger <cg@exept.de>
parents: 1042
diff changeset
  3023
2116
1bcb6ee86fca fixed pending sigChild problem;
Claus Gittinger <cg@exept.de>
parents: 2111
diff changeset
  3024
    wasBlocked ifTrue:[
7493
5c67c45b11cb New select for fair scheduling (not giving low filedescriptors
Stefan Vogel <sv@exept.de>
parents: 7264
diff changeset
  3025
        OperatingSystem blockInterrupts.
2116
1bcb6ee86fca fixed pending sigChild problem;
Claus Gittinger <cg@exept.de>
parents: 2111
diff changeset
  3026
    ].
1bcb6ee86fca fixed pending sigChild problem;
Claus Gittinger <cg@exept.de>
parents: 2111
diff changeset
  3027
7510
46a848d466b5 select: wake up readFDs if readable only;
Claus Gittinger <cg@exept.de>
parents: 7495
diff changeset
  3028
    nReady == 0 ifTrue:[
7493
5c67c45b11cb New select for fair scheduling (not giving low filedescriptors
Stefan Vogel <sv@exept.de>
parents: 7264
diff changeset
  3029
        "/ either still nothing to do,
5c67c45b11cb New select for fair scheduling (not giving low filedescriptors
Stefan Vogel <sv@exept.de>
parents: 7264
diff changeset
  3030
        "/ or error (which should not happen)
5c67c45b11cb New select for fair scheduling (not giving low filedescriptors
Stefan Vogel <sv@exept.de>
parents: 7264
diff changeset
  3031
5c67c45b11cb New select for fair scheduling (not giving low filedescriptors
Stefan Vogel <sv@exept.de>
parents: 7264
diff changeset
  3032
        (err := OperatingSystem lastErrorSymbol) notNil ifTrue:[
5c67c45b11cb New select for fair scheduling (not giving low filedescriptors
Stefan Vogel <sv@exept.de>
parents: 7264
diff changeset
  3033
            err == #EBADF ifTrue:[
5c67c45b11cb New select for fair scheduling (not giving low filedescriptors
Stefan Vogel <sv@exept.de>
parents: 7264
diff changeset
  3034
5c67c45b11cb New select for fair scheduling (not giving low filedescriptors
Stefan Vogel <sv@exept.de>
parents: 7264
diff changeset
  3035
                "/ mhmh - one of the fd's given to me is corrupt.
5c67c45b11cb New select for fair scheduling (not giving low filedescriptors
Stefan Vogel <sv@exept.de>
parents: 7264
diff changeset
  3036
                "/ find out which one .... and remove it
5c67c45b11cb New select for fair scheduling (not giving low filedescriptors
Stefan Vogel <sv@exept.de>
parents: 7264
diff changeset
  3037
5c67c45b11cb New select for fair scheduling (not giving low filedescriptors
Stefan Vogel <sv@exept.de>
parents: 7264
diff changeset
  3038
                'Processor [info]: obsolete FD in select - clearing' infoPrintCR.
5c67c45b11cb New select for fair scheduling (not giving low filedescriptors
Stefan Vogel <sv@exept.de>
parents: 7264
diff changeset
  3039
                OperatingSystem clearLastErrorNumber.
5c67c45b11cb New select for fair scheduling (not giving low filedescriptors
Stefan Vogel <sv@exept.de>
parents: 7264
diff changeset
  3040
                self removeCorruptedFds
5c67c45b11cb New select for fair scheduling (not giving low filedescriptors
Stefan Vogel <sv@exept.de>
parents: 7264
diff changeset
  3041
            ] ifFalse:[
5c67c45b11cb New select for fair scheduling (not giving low filedescriptors
Stefan Vogel <sv@exept.de>
parents: 7264
diff changeset
  3042
                err == #ENOENT ifTrue:[
5c67c45b11cb New select for fair scheduling (not giving low filedescriptors
Stefan Vogel <sv@exept.de>
parents: 7264
diff changeset
  3043
                    'Processor [warning]: ENOENT in select; rd=' infoPrint.
5c67c45b11cb New select for fair scheduling (not giving low filedescriptors
Stefan Vogel <sv@exept.de>
parents: 7264
diff changeset
  3044
                    readFdArray infoPrint.
5c67c45b11cb New select for fair scheduling (not giving low filedescriptors
Stefan Vogel <sv@exept.de>
parents: 7264
diff changeset
  3045
                    ' wr=' infoPrint.
5c67c45b11cb New select for fair scheduling (not giving low filedescriptors
Stefan Vogel <sv@exept.de>
parents: 7264
diff changeset
  3046
                    writeFdArray infoPrintCR.
5c67c45b11cb New select for fair scheduling (not giving low filedescriptors
Stefan Vogel <sv@exept.de>
parents: 7264
diff changeset
  3047
                ] ifFalse:[
5c67c45b11cb New select for fair scheduling (not giving low filedescriptors
Stefan Vogel <sv@exept.de>
parents: 7264
diff changeset
  3048
                    'Processor [warning]: error in select: ' infoPrint. err infoPrintCR.
5c67c45b11cb New select for fair scheduling (not giving low filedescriptors
Stefan Vogel <sv@exept.de>
parents: 7264
diff changeset
  3049
                ]
5c67c45b11cb New select for fair scheduling (not giving low filedescriptors
Stefan Vogel <sv@exept.de>
parents: 7264
diff changeset
  3050
            ].
5c67c45b11cb New select for fair scheduling (not giving low filedescriptors
Stefan Vogel <sv@exept.de>
parents: 7264
diff changeset
  3051
        ]
1061
61012b7bed9c protect myself against invalid fd's in readFdArray/writeFdArray
Claus Gittinger <cg@exept.de>
parents: 1042
diff changeset
  3052
    ] ifFalse:[
7510
46a848d466b5 select: wake up readFDs if readable only;
Claus Gittinger <cg@exept.de>
parents: 7495
diff changeset
  3053
        readyIndex := 1.
46a848d466b5 select: wake up readFDs if readable only;
Claus Gittinger <cg@exept.de>
parents: 7495
diff changeset
  3054
        [nReady > 0
46a848d466b5 select: wake up readFDs if readable only;
Claus Gittinger <cg@exept.de>
parents: 7495
diff changeset
  3055
             and:[ readyIndex <= readableResultFdArray size
46a848d466b5 select: wake up readFDs if readable only;
Claus Gittinger <cg@exept.de>
parents: 7495
diff changeset
  3056
             and:[ (fd := readableResultFdArray at:readyIndex) notNil ]]]
46a848d466b5 select: wake up readFDs if readable only;
Claus Gittinger <cg@exept.de>
parents: 7495
diff changeset
  3057
        whileTrue:[
7493
5c67c45b11cb New select for fair scheduling (not giving low filedescriptors
Stefan Vogel <sv@exept.de>
parents: 7264
diff changeset
  3058
            index := readFdArray identityIndexOf:fd.
5c67c45b11cb New select for fair scheduling (not giving low filedescriptors
Stefan Vogel <sv@exept.de>
parents: 7264
diff changeset
  3059
            index ~~ 0 ifTrue:[
5c67c45b11cb New select for fair scheduling (not giving low filedescriptors
Stefan Vogel <sv@exept.de>
parents: 7264
diff changeset
  3060
                sema := readSemaphoreArray at:index.
5c67c45b11cb New select for fair scheduling (not giving low filedescriptors
Stefan Vogel <sv@exept.de>
parents: 7264
diff changeset
  3061
                sema notNil ifTrue:[
5c67c45b11cb New select for fair scheduling (not giving low filedescriptors
Stefan Vogel <sv@exept.de>
parents: 7264
diff changeset
  3062
                    sema signalOnce.
5c67c45b11cb New select for fair scheduling (not giving low filedescriptors
Stefan Vogel <sv@exept.de>
parents: 7264
diff changeset
  3063
                    newProcessMaybeReady := true
5c67c45b11cb New select for fair scheduling (not giving low filedescriptors
Stefan Vogel <sv@exept.de>
parents: 7264
diff changeset
  3064
                ].
5c67c45b11cb New select for fair scheduling (not giving low filedescriptors
Stefan Vogel <sv@exept.de>
parents: 7264
diff changeset
  3065
                action := readCheckArray at:index.
5c67c45b11cb New select for fair scheduling (not giving low filedescriptors
Stefan Vogel <sv@exept.de>
parents: 7264
diff changeset
  3066
                action notNil ifTrue:[
5c67c45b11cb New select for fair scheduling (not giving low filedescriptors
Stefan Vogel <sv@exept.de>
parents: 7264
diff changeset
  3067
                    action value.
5c67c45b11cb New select for fair scheduling (not giving low filedescriptors
Stefan Vogel <sv@exept.de>
parents: 7264
diff changeset
  3068
                    newProcessMaybeReady := true
5c67c45b11cb New select for fair scheduling (not giving low filedescriptors
Stefan Vogel <sv@exept.de>
parents: 7264
diff changeset
  3069
                ]
5c67c45b11cb New select for fair scheduling (not giving low filedescriptors
Stefan Vogel <sv@exept.de>
parents: 7264
diff changeset
  3070
            ].
7510
46a848d466b5 select: wake up readFDs if readable only;
Claus Gittinger <cg@exept.de>
parents: 7495
diff changeset
  3071
            nReady := nReady - 1.
46a848d466b5 select: wake up readFDs if readable only;
Claus Gittinger <cg@exept.de>
parents: 7495
diff changeset
  3072
            index := index + 1.
46a848d466b5 select: wake up readFDs if readable only;
Claus Gittinger <cg@exept.de>
parents: 7495
diff changeset
  3073
        ].
46a848d466b5 select: wake up readFDs if readable only;
Claus Gittinger <cg@exept.de>
parents: 7495
diff changeset
  3074
46a848d466b5 select: wake up readFDs if readable only;
Claus Gittinger <cg@exept.de>
parents: 7495
diff changeset
  3075
        readyIndex := 1.
46a848d466b5 select: wake up readFDs if readable only;
Claus Gittinger <cg@exept.de>
parents: 7495
diff changeset
  3076
        [nReady > 0
46a848d466b5 select: wake up readFDs if readable only;
Claus Gittinger <cg@exept.de>
parents: 7495
diff changeset
  3077
             and:[ readyIndex <= writableResultFdArray size
46a848d466b5 select: wake up readFDs if readable only;
Claus Gittinger <cg@exept.de>
parents: 7495
diff changeset
  3078
             and:[ (fd := writableResultFdArray at:readyIndex) notNil ]]]
46a848d466b5 select: wake up readFDs if readable only;
Claus Gittinger <cg@exept.de>
parents: 7495
diff changeset
  3079
        whileTrue:[
7493
5c67c45b11cb New select for fair scheduling (not giving low filedescriptors
Stefan Vogel <sv@exept.de>
parents: 7264
diff changeset
  3080
            index := writeFdArray identityIndexOf:fd.
5c67c45b11cb New select for fair scheduling (not giving low filedescriptors
Stefan Vogel <sv@exept.de>
parents: 7264
diff changeset
  3081
            index ~~ 0 ifTrue:[
5c67c45b11cb New select for fair scheduling (not giving low filedescriptors
Stefan Vogel <sv@exept.de>
parents: 7264
diff changeset
  3082
                sema := writeSemaphoreArray at:index.
5c67c45b11cb New select for fair scheduling (not giving low filedescriptors
Stefan Vogel <sv@exept.de>
parents: 7264
diff changeset
  3083
                sema notNil ifTrue:[
5c67c45b11cb New select for fair scheduling (not giving low filedescriptors
Stefan Vogel <sv@exept.de>
parents: 7264
diff changeset
  3084
                    sema signalOnce.
5c67c45b11cb New select for fair scheduling (not giving low filedescriptors
Stefan Vogel <sv@exept.de>
parents: 7264
diff changeset
  3085
                    newProcessMaybeReady := true
5c67c45b11cb New select for fair scheduling (not giving low filedescriptors
Stefan Vogel <sv@exept.de>
parents: 7264
diff changeset
  3086
                ].
5c67c45b11cb New select for fair scheduling (not giving low filedescriptors
Stefan Vogel <sv@exept.de>
parents: 7264
diff changeset
  3087
                action := writeCheckArray at:index.
5c67c45b11cb New select for fair scheduling (not giving low filedescriptors
Stefan Vogel <sv@exept.de>
parents: 7264
diff changeset
  3088
                action notNil ifTrue:[
5c67c45b11cb New select for fair scheduling (not giving low filedescriptors
Stefan Vogel <sv@exept.de>
parents: 7264
diff changeset
  3089
                    action value.
5c67c45b11cb New select for fair scheduling (not giving low filedescriptors
Stefan Vogel <sv@exept.de>
parents: 7264
diff changeset
  3090
                    newProcessMaybeReady := true
5c67c45b11cb New select for fair scheduling (not giving low filedescriptors
Stefan Vogel <sv@exept.de>
parents: 7264
diff changeset
  3091
                ]
5c67c45b11cb New select for fair scheduling (not giving low filedescriptors
Stefan Vogel <sv@exept.de>
parents: 7264
diff changeset
  3092
            ].
7510
46a848d466b5 select: wake up readFDs if readable only;
Claus Gittinger <cg@exept.de>
parents: 7495
diff changeset
  3093
            nReady := nReady - 1.
46a848d466b5 select: wake up readFDs if readable only;
Claus Gittinger <cg@exept.de>
parents: 7495
diff changeset
  3094
            index := index + 1.
7493
5c67c45b11cb New select for fair scheduling (not giving low filedescriptors
Stefan Vogel <sv@exept.de>
parents: 7264
diff changeset
  3095
        ].
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  3096
    ].
7493
5c67c45b11cb New select for fair scheduling (not giving low filedescriptors
Stefan Vogel <sv@exept.de>
parents: 7264
diff changeset
  3097
    ^ 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
  3098
10233
4006fa954217 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9991
diff changeset
  3099
    "Modified: / 12-04-1996 / 09:31:22 / stefan"
4006fa954217 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9991
diff changeset
  3100
    "Modified: / 06-12-2006 / 18:45:37 / cg"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  3101
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  3102
10
claus
parents: 3
diff changeset
  3103
ioInterrupt
1787
32632b6f969d remember threadSwitch:from: idea for later implementation;
Claus Gittinger <cg@exept.de>
parents: 1783
diff changeset
  3104
    "{ Pragma: +returnable }"
32632b6f969d remember threadSwitch:from: idea for later implementation;
Claus Gittinger <cg@exept.de>
parents: 1783
diff changeset
  3105
159
514c749165c3 *** empty log message ***
claus
parents: 144
diff changeset
  3106
    "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
  3107
     what to do now.
be7402f74d94 hide timerInterrupt & ioInterrupt contexts when switching
Claus Gittinger <cg@exept.de>
parents: 1780
diff changeset
  3108
     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
  3109
     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
  3110
     of whichever process is currently running."
10
claus
parents: 3
diff changeset
  3111
804
264d440a67a0 Fixes when useIOInterrupts == true.
Stefan Vogel <sv@exept.de>
parents: 786
diff changeset
  3112
    gotIOInterrupt := true.
2966
856dfc8a294a lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2962
diff changeset
  3113
    activeProcess ~~ scheduler ifTrue:[
5101
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  3114
	interruptedProcess := activeProcess.
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  3115
	self threadSwitch:scheduler
2966
856dfc8a294a lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2962
diff changeset
  3116
    ]
804
264d440a67a0 Fixes when useIOInterrupts == true.
Stefan Vogel <sv@exept.de>
parents: 786
diff changeset
  3117
264d440a67a0 Fixes when useIOInterrupts == true.
Stefan Vogel <sv@exept.de>
parents: 786
diff changeset
  3118
    "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
  3119
    "Modified: 4.8.1997 / 14:23:08 / cg"
10
claus
parents: 3
diff changeset
  3120
!
claus
parents: 3
diff changeset
  3121
1086
7b0641a2e1ef nicer message
Claus Gittinger <cg@exept.de>
parents: 1061
diff changeset
  3122
removeCorruptedFds
7b0641a2e1ef nicer message
Claus Gittinger <cg@exept.de>
parents: 1061
diff changeset
  3123
    "this is sent when select returns an error due to some invalid 
1606
5f305da05f8b comment
Claus Gittinger <cg@exept.de>
parents: 1576
diff changeset
  3124
     fileDescriptor. May happen, if someone does a readWait/writeWait on a 
5f305da05f8b comment
Claus Gittinger <cg@exept.de>
parents: 1576
diff changeset
  3125
     socket connection, which somehow got corrupted 
2280
aca71c89f32c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2269
diff changeset
  3126
     (shutdown by partner, or closed by another thread, while being in a read/write-wait).
1086
7b0641a2e1ef nicer message
Claus Gittinger <cg@exept.de>
parents: 1061
diff changeset
  3127
     Without special care, all following selects would immediately return with 
7b0641a2e1ef nicer message
Claus Gittinger <cg@exept.de>
parents: 1061
diff changeset
  3128
     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
  3129
     (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
  3130
      readFdArray/writeFdArray in the debugger)"
7b0641a2e1ef nicer message
Claus Gittinger <cg@exept.de>
parents: 1061
diff changeset
  3131
7b0641a2e1ef nicer message
Claus Gittinger <cg@exept.de>
parents: 1061
diff changeset
  3132
    readFdArray keysAndValuesDo:[:idx :fd |
7761
748613a5ed16 removed "removing invalid fd" message
Claus Gittinger <cg@exept.de>
parents: 7532
diff changeset
  3133
        |rslt sema|
748613a5ed16 removed "removing invalid fd" message
Claus Gittinger <cg@exept.de>
parents: 7532
diff changeset
  3134
748613a5ed16 removed "removing invalid fd" message
Claus Gittinger <cg@exept.de>
parents: 7532
diff changeset
  3135
        (fd notNil "and:[fd >= 0]") ifTrue:[
748613a5ed16 removed "removing invalid fd" message
Claus Gittinger <cg@exept.de>
parents: 7532
diff changeset
  3136
            rslt := OperatingSystem
748613a5ed16 removed "removing invalid fd" message
Claus Gittinger <cg@exept.de>
parents: 7532
diff changeset
  3137
                        selectOnAnyReadable:(Array with:fd)
748613a5ed16 removed "removing invalid fd" message
Claus Gittinger <cg@exept.de>
parents: 7532
diff changeset
  3138
                                   writable:nil
748613a5ed16 removed "removing invalid fd" message
Claus Gittinger <cg@exept.de>
parents: 7532
diff changeset
  3139
                                  exception:nil
748613a5ed16 removed "removing invalid fd" message
Claus Gittinger <cg@exept.de>
parents: 7532
diff changeset
  3140
                                withTimeOut:0.
748613a5ed16 removed "removing invalid fd" message
Claus Gittinger <cg@exept.de>
parents: 7532
diff changeset
  3141
748613a5ed16 removed "removing invalid fd" message
Claus Gittinger <cg@exept.de>
parents: 7532
diff changeset
  3142
            (rslt isNil and:[OperatingSystem lastErrorSymbol == #EBADF]) ifTrue:[
748613a5ed16 removed "removing invalid fd" message
Claus Gittinger <cg@exept.de>
parents: 7532
diff changeset
  3143
                "/ ('Processor [info]: removing invalid read-select fileDescriptor: ' , fd printString) infoPrintCR.
748613a5ed16 removed "removing invalid fd" message
Claus Gittinger <cg@exept.de>
parents: 7532
diff changeset
  3144
                readFdArray at:idx put:nil.
748613a5ed16 removed "removing invalid fd" message
Claus Gittinger <cg@exept.de>
parents: 7532
diff changeset
  3145
                readCheckArray at:idx put:nil.
748613a5ed16 removed "removing invalid fd" message
Claus Gittinger <cg@exept.de>
parents: 7532
diff changeset
  3146
                OperatingSystem clearLastErrorNumber.
748613a5ed16 removed "removing invalid fd" message
Claus Gittinger <cg@exept.de>
parents: 7532
diff changeset
  3147
                (sema := readSemaphoreArray at:idx) notNil ifTrue:[
748613a5ed16 removed "removing invalid fd" message
Claus Gittinger <cg@exept.de>
parents: 7532
diff changeset
  3148
                    readSemaphoreArray at:idx put:nil.
748613a5ed16 removed "removing invalid fd" message
Claus Gittinger <cg@exept.de>
parents: 7532
diff changeset
  3149
                    sema signal.
748613a5ed16 removed "removing invalid fd" message
Claus Gittinger <cg@exept.de>
parents: 7532
diff changeset
  3150
                ].
748613a5ed16 removed "removing invalid fd" message
Claus Gittinger <cg@exept.de>
parents: 7532
diff changeset
  3151
            ]
748613a5ed16 removed "removing invalid fd" message
Claus Gittinger <cg@exept.de>
parents: 7532
diff changeset
  3152
        ].
1086
7b0641a2e1ef nicer message
Claus Gittinger <cg@exept.de>
parents: 1061
diff changeset
  3153
    ].
7b0641a2e1ef nicer message
Claus Gittinger <cg@exept.de>
parents: 1061
diff changeset
  3154
7b0641a2e1ef nicer message
Claus Gittinger <cg@exept.de>
parents: 1061
diff changeset
  3155
    writeFdArray keysAndValuesDo:[:idx :fd |
7761
748613a5ed16 removed "removing invalid fd" message
Claus Gittinger <cg@exept.de>
parents: 7532
diff changeset
  3156
        |rslt sema|
748613a5ed16 removed "removing invalid fd" message
Claus Gittinger <cg@exept.de>
parents: 7532
diff changeset
  3157
748613a5ed16 removed "removing invalid fd" message
Claus Gittinger <cg@exept.de>
parents: 7532
diff changeset
  3158
        (fd notNil) ifTrue:[
748613a5ed16 removed "removing invalid fd" message
Claus Gittinger <cg@exept.de>
parents: 7532
diff changeset
  3159
            rslt := OperatingSystem
748613a5ed16 removed "removing invalid fd" message
Claus Gittinger <cg@exept.de>
parents: 7532
diff changeset
  3160
                        selectOnAnyReadable:nil
748613a5ed16 removed "removing invalid fd" message
Claus Gittinger <cg@exept.de>
parents: 7532
diff changeset
  3161
                                   writable:(Array with:fd)
748613a5ed16 removed "removing invalid fd" message
Claus Gittinger <cg@exept.de>
parents: 7532
diff changeset
  3162
                                  exception:nil
748613a5ed16 removed "removing invalid fd" message
Claus Gittinger <cg@exept.de>
parents: 7532
diff changeset
  3163
                                withTimeOut:0.
748613a5ed16 removed "removing invalid fd" message
Claus Gittinger <cg@exept.de>
parents: 7532
diff changeset
  3164
748613a5ed16 removed "removing invalid fd" message
Claus Gittinger <cg@exept.de>
parents: 7532
diff changeset
  3165
            (rslt isNil and:[OperatingSystem lastErrorSymbol == #EBADF]) ifTrue:[
748613a5ed16 removed "removing invalid fd" message
Claus Gittinger <cg@exept.de>
parents: 7532
diff changeset
  3166
                "/ ('Processor [info]: removing invalid write-select fileDescriptor: ' , fd printString) infoPrintCR.
748613a5ed16 removed "removing invalid fd" message
Claus Gittinger <cg@exept.de>
parents: 7532
diff changeset
  3167
                writeFdArray at:idx put:nil.
748613a5ed16 removed "removing invalid fd" message
Claus Gittinger <cg@exept.de>
parents: 7532
diff changeset
  3168
                writeCheckArray at:idx put:nil.
748613a5ed16 removed "removing invalid fd" message
Claus Gittinger <cg@exept.de>
parents: 7532
diff changeset
  3169
                OperatingSystem clearLastErrorNumber.
748613a5ed16 removed "removing invalid fd" message
Claus Gittinger <cg@exept.de>
parents: 7532
diff changeset
  3170
                (sema := writeSemaphoreArray at:idx) notNil ifTrue:[
748613a5ed16 removed "removing invalid fd" message
Claus Gittinger <cg@exept.de>
parents: 7532
diff changeset
  3171
                    writeSemaphoreArray at:idx put:nil.
748613a5ed16 removed "removing invalid fd" message
Claus Gittinger <cg@exept.de>
parents: 7532
diff changeset
  3172
                    sema signal.
748613a5ed16 removed "removing invalid fd" message
Claus Gittinger <cg@exept.de>
parents: 7532
diff changeset
  3173
                ].
748613a5ed16 removed "removing invalid fd" message
Claus Gittinger <cg@exept.de>
parents: 7532
diff changeset
  3174
            ]
748613a5ed16 removed "removing invalid fd" message
Claus Gittinger <cg@exept.de>
parents: 7532
diff changeset
  3175
        ]
1086
7b0641a2e1ef nicer message
Claus Gittinger <cg@exept.de>
parents: 1061
diff changeset
  3176
    ].
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
  3177
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
  3178
    "Modified: 12.4.1996 / 09:32:58 / stefan"
2280
aca71c89f32c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2269
diff changeset
  3179
    "Modified: 27.1.1997 / 20:09:27 / cg"
1086
7b0641a2e1ef nicer message
Claus Gittinger <cg@exept.de>
parents: 1061
diff changeset
  3180
!
7b0641a2e1ef nicer message
Claus Gittinger <cg@exept.de>
parents: 1061
diff changeset
  3181
750
f4ed622893ce added schedulerInterrupt - for soon to come semaSignal primitive function
Claus Gittinger <cg@exept.de>
parents: 699
diff changeset
  3182
schedulerInterrupt
f4ed622893ce added schedulerInterrupt - for soon to come semaSignal primitive function
Claus Gittinger <cg@exept.de>
parents: 699
diff changeset
  3183
    "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
  3184
     what to do now."
f4ed622893ce added schedulerInterrupt - for soon to come semaSignal primitive function
Claus Gittinger <cg@exept.de>
parents: 699
diff changeset
  3185
2966
856dfc8a294a lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2962
diff changeset
  3186
    activeProcess ~~ scheduler ifTrue:[
5101
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  3187
	interruptedProcess := activeProcess.
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  3188
	self threadSwitch:scheduler
2966
856dfc8a294a lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2962
diff changeset
  3189
    ]
750
f4ed622893ce added schedulerInterrupt - for soon to come semaSignal primitive function
Claus Gittinger <cg@exept.de>
parents: 699
diff changeset
  3190
!
f4ed622893ce added schedulerInterrupt - for soon to come semaSignal primitive function
Claus Gittinger <cg@exept.de>
parents: 699
diff changeset
  3191
10
claus
parents: 3
diff changeset
  3192
timeToNextTimeout
claus
parents: 3
diff changeset
  3193
    "return the delta-T (in millis) to next timeout, or nil if
claus
parents: 3
diff changeset
  3194
     there is none"
claus
parents: 3
diff changeset
  3195
231
fd0e55e352f8 cleanup
claus
parents: 217
diff changeset
  3196
    |aTime now delta minDelta n "{ Class: SmallInteger }"|
10
claus
parents: 3
diff changeset
  3197
claus
parents: 3
diff changeset
  3198
    "find next timeout. since there are usually not many, just search.
302
1f76060d58a4 *** empty log message ***
claus
parents: 271
diff changeset
  3199
     If there were many, the list should be kept sorted ... keeping deltas
10
claus
parents: 3
diff changeset
  3200
     to next (as in Unix kernel)"
claus
parents: 3
diff changeset
  3201
231
fd0e55e352f8 cleanup
claus
parents: 217
diff changeset
  3202
    n := timeoutArray size.
10
claus
parents: 3
diff changeset
  3203
    1 to:n do:[:index |
231
fd0e55e352f8 cleanup
claus
parents: 217
diff changeset
  3204
	aTime := timeoutArray at:index.
159
514c749165c3 *** empty log message ***
claus
parents: 144
diff changeset
  3205
	aTime notNil ifTrue:[
231
fd0e55e352f8 cleanup
claus
parents: 217
diff changeset
  3206
	    now isNil ifTrue:[
159
514c749165c3 *** empty log message ***
claus
parents: 144
diff changeset
  3207
		now := OperatingSystem getMillisecondTime.
231
fd0e55e352f8 cleanup
claus
parents: 217
diff changeset
  3208
	    ].
fd0e55e352f8 cleanup
claus
parents: 217
diff changeset
  3209
	    (OperatingSystem millisecondTime:aTime isAfter:now) ifFalse:[^ 0].
fd0e55e352f8 cleanup
claus
parents: 217
diff changeset
  3210
	    delta := OperatingSystem millisecondTimeDeltaBetween:aTime and:now.
fd0e55e352f8 cleanup
claus
parents: 217
diff changeset
  3211
	    minDelta isNil ifTrue:[
fd0e55e352f8 cleanup
claus
parents: 217
diff changeset
  3212
		minDelta := delta
159
514c749165c3 *** empty log message ***
claus
parents: 144
diff changeset
  3213
	    ] ifFalse:[
231
fd0e55e352f8 cleanup
claus
parents: 217
diff changeset
  3214
		minDelta := minDelta min:delta
159
514c749165c3 *** empty log message ***
claus
parents: 144
diff changeset
  3215
	    ]
514c749165c3 *** empty log message ***
claus
parents: 144
diff changeset
  3216
	]
10
claus
parents: 3
diff changeset
  3217
    ].
claus
parents: 3
diff changeset
  3218
claus
parents: 3
diff changeset
  3219
    ^ minDelta
claus
parents: 3
diff changeset
  3220
!
claus
parents: 3
diff changeset
  3221
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  3222
timerInterrupt
1787
32632b6f969d remember threadSwitch:from: idea for later implementation;
Claus Gittinger <cg@exept.de>
parents: 1783
diff changeset
  3223
    "{ Pragma: +returnable }"
32632b6f969d remember threadSwitch:from: idea for later implementation;
Claus Gittinger <cg@exept.de>
parents: 1783
diff changeset
  3224
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  3225
    "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
  3226
     what to do now.
be7402f74d94 hide timerInterrupt & ioInterrupt contexts when switching
Claus Gittinger <cg@exept.de>
parents: 1780
diff changeset
  3227
     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
  3228
     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
  3229
     of whichever process is currently running."
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  3230
2966
856dfc8a294a lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2962
diff changeset
  3231
    activeProcess ~~ scheduler ifTrue:[
5101
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  3232
	interruptedProcess := activeProcess.
901c91d6dd50 support to poll write-fds
Claus Gittinger <cg@exept.de>
parents: 4879
diff changeset
  3233
	self threadSwitch:scheduler
2966
856dfc8a294a lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2962
diff changeset
  3234
    ]
1783
be7402f74d94 hide timerInterrupt & ioInterrupt contexts when switching
Claus Gittinger <cg@exept.de>
parents: 1780
diff changeset
  3235
be7402f74d94 hide timerInterrupt & ioInterrupt contexts when switching
Claus Gittinger <cg@exept.de>
parents: 1780
diff changeset
  3236
    "Modified: 18.10.1996 / 20:35:54 / cg"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  3237
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  3238
10
claus
parents: 3
diff changeset
  3239
waitForEventOrTimeout
44
b262907c93ea *** empty log message ***
claus
parents: 42
diff changeset
  3240
    "entered when no process is runnable - wait for either input on
b262907c93ea *** empty log message ***
claus
parents: 42
diff changeset
  3241
     any file descriptors to arrive or a timeout to happen.
b262907c93ea *** empty log message ***
claus
parents: 42
diff changeset
  3242
     If it makes sense, do some background garbage collection.
b262907c93ea *** empty log message ***
claus
parents: 42
diff changeset
  3243
     The idle actions are a leftover from previous ST/X releases and will
93
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
  3244
     vanish (installing a low-prio process has the same effect)."
44
b262907c93ea *** empty log message ***
claus
parents: 42
diff changeset
  3245
3745
3fd121f2e74e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3740
diff changeset
  3246
    |millis doingGC anySema dT|
10
claus
parents: 3
diff changeset
  3247
claus
parents: 3
diff changeset
  3248
    doingGC := true.
claus
parents: 3
diff changeset
  3249
    [doingGC] whileTrue:[
6619
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
  3250
        anyTimeouts ifTrue:[
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
  3251
            millis := self timeToNextTimeout.
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
  3252
            (millis notNil and:[millis <= 0]) ifTrue:[
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
  3253
                ^ self    "oops - hurry up checking"
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
  3254
            ].
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
  3255
        ].
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
  3256
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
  3257
        "
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
  3258
         if its worth doing, collect a bit of garbage;
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
  3259
         but not, if a backgroundCollector is active
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
  3260
        "
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
  3261
        ObjectMemory backgroundCollectorRunning ifTrue:[
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
  3262
            doingGC := false
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
  3263
        ] ifFalse:[
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
  3264
            doingGC := ObjectMemory gcStepIfUseful.
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
  3265
        ].
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
  3266
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
  3267
        "then do idle actions"
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
  3268
        (idleActions notNil and:[idleActions size ~~ 0]) ifTrue:[
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
  3269
            idleActions do:[:aBlock |
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
  3270
                aBlock value.
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
  3271
            ].
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
  3272
            ^ self   "go back checking"
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
  3273
        ].
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
  3274
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
  3275
        doingGC ifTrue:[
7510
46a848d466b5 select: wake up readFDs if readable only;
Claus Gittinger <cg@exept.de>
parents: 7495
diff changeset
  3276
            (self checkForIOWithTimeout:0) ifTrue:[
6619
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
  3277
                ^ self  "go back checking"
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
  3278
            ]
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
  3279
        ]
10
claus
parents: 3
diff changeset
  3280
    ].
claus
parents: 3
diff changeset
  3281
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
  3282
    exitWhenNoMoreUserProcesses ifTrue:[
6619
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
  3283
        "/ check if there are any processes at all
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
  3284
        "/ stop dispatching if there is none
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
  3285
        "/ (and millis is nil, which means that no timeout blocks are present)
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
  3286
        "/ and no readSemaphores are present (which means that noone is waiting for input)
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
  3287
        "/ and no writeSemaphores are present
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
  3288
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
  3289
        anySema := false.
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
  3290
        anySema := (readSemaphoreArray findFirst:[:sema | sema notNil]) ~~ 0.
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
  3291
        anySema ifFalse:[
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
  3292
            anySema := (writeSemaphoreArray findFirst:[:sema | sema notNil]) ~~ 0.
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
  3293
        ].
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
  3294
        anySema ifFalse:[
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
  3295
            self anyUserProcessAtAll ifFalse:[
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
  3296
                dispatching := false.
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
  3297
                ^ self
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
  3298
            ]
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
  3299
        ].
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
  3300
    ].
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
  3301
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
  3302
    preWaitActions notNil ifTrue:[
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
  3303
        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
  3304
    ].
10
claus
parents: 3
diff changeset
  3305
1627
f95285226059 infoPrint for NT (no select)
Claus Gittinger <cg@exept.de>
parents: 1618
diff changeset
  3306
    "/
f95285226059 infoPrint for NT (no select)
Claus Gittinger <cg@exept.de>
parents: 1618
diff changeset
  3307
    "/ absolutely nothing to do - simply wait
f95285226059 infoPrint for NT (no select)
Claus Gittinger <cg@exept.de>
parents: 1618
diff changeset
  3308
    "/
49
f1c2d75f2eb6 *** empty log message ***
claus
parents: 44
diff changeset
  3309
    OperatingSystem supportsSelect ifFalse:[
6619
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
  3310
        "SCO instant ShitStation has a bug here,
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
  3311
         waiting always 1 sec in the select - therefore we delay a bit and
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
  3312
         return - effectively polling in 50ms cycles
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
  3313
        "
7510
46a848d466b5 select: wake up readFDs if readable only;
Claus Gittinger <cg@exept.de>
parents: 7495
diff changeset
  3314
        (self checkForIOWithTimeout:0) ifTrue:[
6619
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
  3315
            ^ self  "go back checking"
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
  3316
        ].
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
  3317
        OperatingSystem millisecondDelay:EventPollingInterval.
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
  3318
        ^ self
10
claus
parents: 3
diff changeset
  3319
    ].
claus
parents: 3
diff changeset
  3320
6044
f752aac6b456 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5840
diff changeset
  3321
    useIOInterrupts ifTrue:[
6619
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
  3322
        dT := 999999
3745
3fd121f2e74e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3740
diff changeset
  3323
    ] ifFalse:[
6619
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
  3324
        dT := EventPollingInterval
3745
3fd121f2e74e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3740
diff changeset
  3325
    ].
3fd121f2e74e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3740
diff changeset
  3326
10
claus
parents: 3
diff changeset
  3327
    millis isNil ifTrue:[
6619
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
  3328
        millis := dT.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3329
    ] ifFalse:[
6619
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
  3330
        millis := millis rounded min:dT.
10
claus
parents: 3
diff changeset
  3331
    ].
6619
23b5cbfd23dc added preWaitActions
Claus Gittinger <cg@exept.de>
parents: 6607
diff changeset
  3332
7510
46a848d466b5 select: wake up readFDs if readable only;
Claus Gittinger <cg@exept.de>
parents: 7495
diff changeset
  3333
    self checkForIOWithTimeout:millis
768
20434b8239f3 stefans modalBox changes (no more polling)
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  3334
20434b8239f3 stefans modalBox changes (no more polling)
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  3335
    "Modified: 14.12.1995 / 13:37:46 / stefan"
1576
3f6c39471342 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1575
diff changeset
  3336
    "Modified: 18.7.1996 / 20:42:17 / cg"
10
claus
parents: 3
diff changeset
  3337
! !
claus
parents: 3
diff changeset
  3338
1783
be7402f74d94 hide timerInterrupt & ioInterrupt contexts when switching
Claus Gittinger <cg@exept.de>
parents: 1780
diff changeset
  3339
!ProcessorScheduler class methodsFor:'documentation'!
10
claus
parents: 3
diff changeset
  3340
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  3341
version
10233
4006fa954217 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9991
diff changeset
  3342
    ^ '$Header: /cvs/stx/stx/libbasic/ProcessorScheduler.st,v 1.234 2006-12-06 17:45:11 cg Exp $'
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3343
! !
6939
6f6ea7b0a5ab stopping an suspended process fix
Claus Gittinger <cg@exept.de>
parents: 6807
diff changeset
  3344
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  3345
ProcessorScheduler initialize!