ProcSched.st
author Claus Gittinger <cg@exept.de>
Mon, 23 Sep 1996 15:54:30 +0200
changeset 1680 b90690d9d6c5
parent 1679 dbbfbd78b1e4
child 1681 56d8d1d96d95
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
"
a27a279701f8 Initial revision
claus
parents:
diff changeset
    12
1679
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
    13
'From Smalltalk/X, Version:2.10.9 on 23-sep-1996 at 14:25:15'                   !
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
    14
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    15
Object subclass:#ProcessorScheduler
768
20434b8239f3 stefans modalBox changes (no more polling)
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
    16
	instanceVariableNames:'quiescentProcessLists scheduler zombie activeProcess
752
0259dd855289 new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents: 750
diff changeset
    17
		currentPriority readFdArray readSemaphoreArray readCheckArray
0259dd855289 new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents: 750
diff changeset
    18
		writeFdArray writeSemaphoreArray timeoutArray timeoutActionArray
0259dd855289 new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents: 750
diff changeset
    19
		timeoutProcessArray timeoutSemaphoreArray idleActions anyTimeouts
827
3eb3911cb63e Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents: 807
diff changeset
    20
		dispatching interruptedProcess useIOInterrupts gotIOInterrupt
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
    21
		osChildExitActions gotChildSignalInterrupt
1679
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
    22
		exitWhenNoMoreUserProcesses suspendScheduler'
768
20434b8239f3 stefans modalBox changes (no more polling)
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
    23
	classVariableNames:'KnownProcesses KnownProcessIds PureEventDriven
752
0259dd855289 new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents: 750
diff changeset
    24
		UserSchedulingPriority UserInterruptPriority TimingPriority
1679
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
    25
		HighestPriority SchedulingPriority MaxNumberOfProcesses
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
    26
		InvalidProcessSignal'
768
20434b8239f3 stefans modalBox changes (no more polling)
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
    27
	poolDictionaries:''
20434b8239f3 stefans modalBox changes (no more polling)
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
    28
	category:'Kernel-Processes'
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    29
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
    30
1571
8d00e6b97ca7 changed #anyUserProcessAtAll,
Claus Gittinger <cg@exept.de>
parents: 1473
diff changeset
    31
!ProcessorScheduler  class methodsFor:'documentation'!
88
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    32
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    33
copyright
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    34
"
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    35
 COPYRIGHT (c) 1993 by Claus Gittinger
159
514c749165c3 *** empty log message ***
claus
parents: 144
diff changeset
    36
	      All Rights Reserved
88
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    37
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    38
 This software is furnished under a license and may be used
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    39
 only in accordance with the terms of that license and with the
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    40
 inclusion of the above copyright notice.   This software may not
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    41
 be provided or otherwise made available to, or used by, any
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    42
 other person.  No title to or ownership of the software is
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    43
 hereby transferred.
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    44
"
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    45
!
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    46
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    47
documentation
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    48
"
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    49
    This class has only one instance, which is bound to the global
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    50
    'Processor'. It is responsible for scheduling among the smalltalk
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    51
    processes (threads; not to confuse with heavy weight unix processes).
93
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
    52
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
    53
    Scheduling is fully done in smalltalk (the always runnable scheduler-
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
    54
    process, running at highest priority does this).
231
fd0e55e352f8 cleanup
claus
parents: 217
diff changeset
    55
    The main VM primitive to support this is found in threadSwitch, which passes
93
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
    56
    control to another process (usually selected by the scheduler).
159
514c749165c3 *** empty log message ***
claus
parents: 144
diff changeset
    57
    Thus it is possible to modify the schedulers policy and implementation
514c749165c3 *** empty log message ***
claus
parents: 144
diff changeset
    58
    at the smalltalk level.
93
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
    59
    (To answer a frequently asked question:
159
514c749165c3 *** empty log message ***
claus
parents: 144
diff changeset
    60
     dont add preemptive round-robin here; this can be implemented without
93
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
    61
     any need to change the scheduler. See goodies/timeslicing.st for how
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
    62
     this is done in a very elegant way).
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
    63
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
    64
    Notice: Smalltalk/X can (still) be compiled & configured without
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
    65
    process support. This non-process mode is called 'pureEventDriven' mode
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
    66
    and is useful to quickly port ST/X to systems, where these facilities
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
    67
    are either not needed (server applications), or are difficult to
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
    68
    implement (threads require some assembler support functions). 
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
    69
    To allow pureEvent mode, kludges are built into some places in the
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
    70
    system, where either a process is forked, or a timeout is used instead 
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
    71
    (for examples, see ProcessMonitor or MemoryMonitor).
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
    72
335
claus
parents: 326
diff changeset
    73
    This pure-event mode may not be supported in the future 
claus
parents: 326
diff changeset
    74
    (actually, it is no longer maintained in places where was present, so dont
claus
parents: 326
diff changeset
    75
     run the system without Processes).
93
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
    76
369
claus
parents: 362
diff changeset
    77
1273
f8449f53a6a3 commentary
Claus Gittinger <cg@exept.de>
parents: 1177
diff changeset
    78
    [class variables:]
93
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
    79
1679
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
    80
	KnownProcesses          <Collection>    all known processes
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
    81
	KnownProcessIds         <Collection>    and their IDs
241
6f30be88e314 *** empty log message ***
claus
parents: 231
diff changeset
    82
1679
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
    83
	PureEventDriven         <Boolean>       true, if no process support
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
    84
						is available
241
6f30be88e314 *** empty log message ***
claus
parents: 231
diff changeset
    85
1679
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
    86
	UserSchedulingPriority  <Integer>       the priority at which normal
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
    87
						user interfaces run
241
6f30be88e314 *** empty log message ***
claus
parents: 231
diff changeset
    88
1679
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
    89
	UserInterruptPriority                   the priority at which user-
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
    90
						interrupts (Cntl-C) processing
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
    91
						takes place. Processes with
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
    92
						a greater or equal priority are
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
    93
						not interruptable.
241
6f30be88e314 *** empty log message ***
claus
parents: 231
diff changeset
    94
1679
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
    95
	TimingPriority                          the priority used for timing.
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
    96
						Processes with a greater or
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
    97
						equal priority are not interrupted
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
    98
						by timers.
241
6f30be88e314 *** empty log message ***
claus
parents: 231
diff changeset
    99
1679
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   100
	HighestPriority                         The highest allowed prio for processes
241
6f30be88e314 *** empty log message ***
claus
parents: 231
diff changeset
   101
1679
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   102
	SchedulingPriority                      The priority of the scheduler (must
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   103
						me higher than any other).
93
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   104
1679
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   105
	MaxNumberOfProcesses                    if non-nil, no more than this
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   106
						number of processes are allowed
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   107
						(for debugging)
93
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   108
759
908363ce8a32 interest is written with one 'r' (shame on me)
Claus Gittinger <cg@exept.de>
parents: 752
diff changeset
   109
    most interesting methods:
93
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   110
1679
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   111
	Processor>>suspend:                  (see also Process>>suspend)
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   112
	Processor>>resume:                   (see also Process>>resume)
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   113
	Processor>>terminate:                (see also Process>>terminate)
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   114
	Processor>>yield 
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   115
	Processor>>changePriority:for:       (see also Process>>priority:
93
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   116
1679
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   117
	Processor>>signal:afterSeconds:      (see also Delay>>forSeconds:)
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   118
	Processor>>signal:afterMilliseconds: (see also Delay>>forMilliseconds:)
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   119
	Processor>>signal:onInput:           (see also ExternalStream>>readWait)
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   120
	Processor>>signal:onOutput:          (see also ExternalStream>>writeWait)
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   121
	Processor>>disableSemaphore:
1273
f8449f53a6a3 commentary
Claus Gittinger <cg@exept.de>
parents: 1177
diff changeset
   122
f8449f53a6a3 commentary
Claus Gittinger <cg@exept.de>
parents: 1177
diff changeset
   123
f8449f53a6a3 commentary
Claus Gittinger <cg@exept.de>
parents: 1177
diff changeset
   124
    [see also:]
1679
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   125
	Process
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   126
	Delay Semaphore SemaphoreSet SharedQueue
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   127
	WindowGroup
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   128
	(``Working with processes'': programming/processes.html)
1294
e26bbb61f6b2 documentation
Claus Gittinger <cg@exept.de>
parents: 1273
diff changeset
   129
e26bbb61f6b2 documentation
Claus Gittinger <cg@exept.de>
parents: 1273
diff changeset
   130
    [author:]
1679
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   131
	Claus Gittinger
88
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
   132
"
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
   133
! !
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
   134
1571
8d00e6b97ca7 changed #anyUserProcessAtAll,
Claus Gittinger <cg@exept.de>
parents: 1473
diff changeset
   135
!ProcessorScheduler  class methodsFor:'initialization'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   136
a27a279701f8 Initial revision
claus
parents:
diff changeset
   137
initialize
44
b262907c93ea *** empty log message ***
claus
parents: 42
diff changeset
   138
    "class setup: create the one-and-only instance of myself and
b262907c93ea *** empty log message ***
claus
parents: 42
diff changeset
   139
     setup some priority values."
b262907c93ea *** empty log message ***
claus
parents: 42
diff changeset
   140
93
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   141
    UserSchedulingPriority := 8.
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   142
    UserInterruptPriority := 24.
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   143
    TimingPriority := 16.
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   144
    SchedulingPriority := 31.
241
6f30be88e314 *** empty log message ***
claus
parents: 231
diff changeset
   145
    HighestPriority := 30.
93
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   146
1679
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   147
    InvalidProcessSignal isNil ifTrue:[
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   148
        InvalidProcessSignal := ErrorSignal newSignalMayProceed:true.
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   149
        InvalidProcessSignal nameClass:self message:#invalidProcessSignal.
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   150
        InvalidProcessSignal notifierString:'invalid process'.
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   151
    ].
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   152
159
514c749165c3 *** empty log message ***
claus
parents: 144
diff changeset
   153
    Processor isNil ifTrue:[
1086
7b0641a2e1ef nicer message
Claus Gittinger <cg@exept.de>
parents: 1061
diff changeset
   154
        "create the one and only processor"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   155
1086
7b0641a2e1ef nicer message
Claus Gittinger <cg@exept.de>
parents: 1061
diff changeset
   156
        Processor := self basicNew initialize.
10
claus
parents: 3
diff changeset
   157
    ].
77
6c38ca59927f *** empty log message ***
claus
parents: 76
diff changeset
   158
6c38ca59927f *** empty log message ***
claus
parents: 76
diff changeset
   159
    "
6c38ca59927f *** empty log message ***
claus
parents: 76
diff changeset
   160
     allow configurations without processes
6c38ca59927f *** empty log message ***
claus
parents: 76
diff changeset
   161
    "
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   162
    PureEventDriven := self threadsAvailable not.
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   163
    PureEventDriven ifTrue:[
1086
7b0641a2e1ef nicer message
Claus Gittinger <cg@exept.de>
parents: 1061
diff changeset
   164
        'PROCESSOR: no process support - running event driven' errorPrintNL
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   165
    ].
1086
7b0641a2e1ef nicer message
Claus Gittinger <cg@exept.de>
parents: 1061
diff changeset
   166
7b0641a2e1ef nicer message
Claus Gittinger <cg@exept.de>
parents: 1061
diff changeset
   167
    "Modified: 7.3.1996 / 19:22:49 / cg"
1679
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   168
    "Modified: 23.9.1996 / 14:24:50 / stefan"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   169
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   170
1571
8d00e6b97ca7 changed #anyUserProcessAtAll,
Claus Gittinger <cg@exept.de>
parents: 1473
diff changeset
   171
!ProcessorScheduler  class methodsFor:'instance creation'!
10
claus
parents: 3
diff changeset
   172
claus
parents: 3
diff changeset
   173
new
claus
parents: 3
diff changeset
   174
    "there is (currently) only one processor ..."
claus
parents: 3
diff changeset
   175
159
514c749165c3 *** empty log message ***
claus
parents: 144
diff changeset
   176
    self error:'only one processor is allowed in the system'
10
claus
parents: 3
diff changeset
   177
! !
claus
parents: 3
diff changeset
   178
1679
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   179
!ProcessorScheduler  class methodsFor:'Signal constants'!
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   180
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   181
invalidProcessSignal
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   182
    ^ InvalidProcessSignal
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   183
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   184
    "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
   185
! !
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   186
1571
8d00e6b97ca7 changed #anyUserProcessAtAll,
Claus Gittinger <cg@exept.de>
parents: 1473
diff changeset
   187
!ProcessorScheduler  class methodsFor:'instance release'!
10
claus
parents: 3
diff changeset
   188
claus
parents: 3
diff changeset
   189
informDispose
159
514c749165c3 *** empty log message ***
claus
parents: 144
diff changeset
   190
    "some Process has been garbage collected 
335
claus
parents: 326
diff changeset
   191
     - terminate the underlying thread. 
claus
parents: 326
diff changeset
   192
     Usually this does not happen; instead, the process terminates itself 
claus
parents: 326
diff changeset
   193
     by sending #terminate."
10
claus
parents: 3
diff changeset
   194
claus
parents: 3
diff changeset
   195
    |id sz "{ Class: SmallInteger }"|
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   196
10
claus
parents: 3
diff changeset
   197
    sz := KnownProcessIds size.
claus
parents: 3
diff changeset
   198
    1 to:sz do:[:index |
159
514c749165c3 *** empty log message ***
claus
parents: 144
diff changeset
   199
	(KnownProcesses at:index) isNil ifTrue:[
514c749165c3 *** empty log message ***
claus
parents: 144
diff changeset
   200
	    id := KnownProcessIds at:index.
514c749165c3 *** empty log message ***
claus
parents: 144
diff changeset
   201
	    id notNil ifTrue:[
514c749165c3 *** empty log message ***
claus
parents: 144
diff changeset
   202
		'PROCESSOR: terminating thread ' errorPrint.
514c749165c3 *** empty log message ***
claus
parents: 144
diff changeset
   203
		id errorPrint.
514c749165c3 *** empty log message ***
claus
parents: 144
diff changeset
   204
		' (no longer refd)' errorPrintNL.
514c749165c3 *** empty log message ***
claus
parents: 144
diff changeset
   205
514c749165c3 *** empty log message ***
claus
parents: 144
diff changeset
   206
		self threadDestroy:id.
514c749165c3 *** empty log message ***
claus
parents: 144
diff changeset
   207
		KnownProcessIds at:index put:nil.
514c749165c3 *** empty log message ***
claus
parents: 144
diff changeset
   208
	    ]
514c749165c3 *** empty log message ***
claus
parents: 144
diff changeset
   209
	]
10
claus
parents: 3
diff changeset
   210
    ]
claus
parents: 3
diff changeset
   211
! !
claus
parents: 3
diff changeset
   212
1571
8d00e6b97ca7 changed #anyUserProcessAtAll,
Claus Gittinger <cg@exept.de>
parents: 1473
diff changeset
   213
!ProcessorScheduler  class methodsFor:'primitive process primitives'!
10
claus
parents: 3
diff changeset
   214
339
claus
parents: 337
diff changeset
   215
threadCreate:aProcess withId:id
159
514c749165c3 *** empty log message ***
claus
parents: 144
diff changeset
   216
    "physical creation of a process.
10
claus
parents: 3
diff changeset
   217
     (warning: low level entry, no administration done).
339
claus
parents: 337
diff changeset
   218
     This may raise an exception, if a VM process could not be created."
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   219
369
claus
parents: 362
diff changeset
   220
    MaxNumberOfProcesses notNil ifTrue:[
claus
parents: 362
diff changeset
   221
	KnownProcessIds size >= MaxNumberOfProcesses ifTrue:[
claus
parents: 362
diff changeset
   222
	    (KnownProcessIds count:[:el | el notNil]) >= MaxNumberOfProcesses ifTrue:[
claus
parents: 362
diff changeset
   223
		"
claus
parents: 362
diff changeset
   224
		 the number of processes has reached the (soft) limit.
claus
parents: 362
diff changeset
   225
		 This limit prevents runaway programs from creating too many
claus
parents: 362
diff changeset
   226
		 processes. If you continue in the debugger, the process will be
claus
parents: 362
diff changeset
   227
		 created as usual. If you dont want this, abort or terminate.
claus
parents: 362
diff changeset
   228
		"
claus
parents: 362
diff changeset
   229
		self error:'too many processes'.
claus
parents: 362
diff changeset
   230
	    ]
claus
parents: 362
diff changeset
   231
	]
claus
parents: 362
diff changeset
   232
    ].
claus
parents: 362
diff changeset
   233
claus
parents: 362
diff changeset
   234
%{
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   235
    int tid;
a27a279701f8 Initial revision
claus
parents:
diff changeset
   236
    extern int __threadCreate();
a27a279701f8 Initial revision
claus
parents:
diff changeset
   237
339
claus
parents: 337
diff changeset
   238
    tid = __threadCreate(aProcess, 
claus
parents: 337
diff changeset
   239
			 0   /* stackSize: no longer needed */, 
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1092
diff changeset
   240
			 __isSmallInteger(id) ? __intVal(id)     /* assign id */
339
claus
parents: 337
diff changeset
   241
					      : -1              /* let VM assign one */  );
claus
parents: 337
diff changeset
   242
    if (tid) {
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1092
diff changeset
   243
	RETURN ( __MKSMALLINT(tid));
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   244
    }
a27a279701f8 Initial revision
claus
parents:
diff changeset
   245
%}
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   246
.
69
4564b6328136 *** empty log message ***
claus
parents: 59
diff changeset
   247
    "
4564b6328136 *** empty log message ***
claus
parents: 59
diff changeset
   248
     arrive here, if creation of process in VM failed.
159
514c749165c3 *** empty log message ***
claus
parents: 144
diff changeset
   249
     This may happen, if the VM does not support more processes,
514c749165c3 *** empty log message ***
claus
parents: 144
diff changeset
   250
     or if it ran out of memory, when allocating internal data
514c749165c3 *** empty log message ***
claus
parents: 144
diff changeset
   251
     structures.
69
4564b6328136 *** empty log message ***
claus
parents: 59
diff changeset
   252
    "
115
11be294044b6 added changePriority
claus
parents: 93
diff changeset
   253
    ^ ObjectMemory allocationFailureSignal raise.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   254
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   255
a27a279701f8 Initial revision
claus
parents:
diff changeset
   256
threadDestroy:id
a27a279701f8 Initial revision
claus
parents:
diff changeset
   257
    "physical destroy other process ...
a27a279701f8 Initial revision
claus
parents:
diff changeset
   258
     (warning: low level entry, no administration done)"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   259
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   260
%{  /* NOCONTEXT */
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   261
253
30daee717a53 *** empty log message ***
claus
parents: 243
diff changeset
   262
    if (__isSmallInteger(id)) {
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1092
diff changeset
   263
	__threadDestroy(__intVal(id));
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   264
    }
a27a279701f8 Initial revision
claus
parents:
diff changeset
   265
%}
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   266
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   267
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   268
threadInterrupt:id
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   269
    "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
   270
     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
   271
     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
   272
     interrupt (currently, it looks for interruptBlocks to evaluate)."
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   273
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   274
%{  /* NOCONTEXT */
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   275
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   276
    if (__isSmallInteger(id)) {
1133
961f2b095c22 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1092
diff changeset
   277
	__threadInterrupt(__intVal(id));
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   278
    }
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   279
%}
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   280
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   281
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   282
threadsAvailable
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   283
    "return true, if the runtime system supports threads (i.e. processes);
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   284
     false otherwise."
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   285
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   286
%{  /* NOCONTEXT */
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   287
    RETURN (__threadsAvailable());
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   288
%}
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   289
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   290
1571
8d00e6b97ca7 changed #anyUserProcessAtAll,
Claus Gittinger <cg@exept.de>
parents: 1473
diff changeset
   291
!ProcessorScheduler  class methodsFor:'queries'!
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   292
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   293
isPureEventDriven
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   294
    "this is temporary - (maybe not :-).
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   295
     you can run ST/X either with or without processes.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   296
     Without, there is conceptionally a single process handling all
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   297
     outside events and timeouts. This has some negative implications
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   298
     (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
   299
     assembler support - i.e. quick portability.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   300
     The PureEvent flag will automatically be set if the runtime system
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   301
     does not support threads - otherwise, it can be set manually
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   302
     (from rc-file).
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   303
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   304
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   305
    ^ PureEventDriven
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   306
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   307
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   308
knownProcesses
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   309
    "return a collection of all (living) processes in the system"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   310
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   311
    ^ KnownProcesses select:[:p | p notNil]
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   312
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   313
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   314
maxNumberOfProcesses
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   315
    "return the limit on the number of processes;
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   316
     the default is nil (i.e. unlimited)."
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   317
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   318
    ^ MaxNumberOfProcesses
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   319
!
10
claus
parents: 3
diff changeset
   320
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   321
maxNumberOfProcesses:aNumber
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   322
    "set the limit on the number of processes.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   323
     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
   324
     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
   325
     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
   326
     processes is unlimited."
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   327
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   328
    MaxNumberOfProcesses := aNumber
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   329
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   330
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   331
processDriven
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   332
    "turn on process driven mode"
10
claus
parents: 3
diff changeset
   333
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   334
    PureEventDriven := false
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   335
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   336
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   337
pureEventDriven
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   338
    "turn on pure-event driven mode - no processes, single dispatch loop"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   339
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   340
    PureEventDriven := true
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   341
! !
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   342
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   343
!ProcessorScheduler methodsFor:'I/O event actions'!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   344
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   345
disableFd:aFileDescriptor
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   346
    "disable block events on aFileDescriptor.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   347
     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
   348
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   349
    |idx "{Class: SmallInteger }" 
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   350
     wasBlocked|
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   351
93
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   352
    wasBlocked := OperatingSystem blockInterrupts.
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   353
    idx := readFdArray identityIndexOf:aFileDescriptor startingAt:1.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   354
    idx ~~ 0 ifTrue:[
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   355
	readFdArray at:idx put:nil.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   356
	readCheckArray at:idx put:nil.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   357
	readSemaphoreArray at:idx put:nil
93
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   358
    ].
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   359
    wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
24
20cfbafcd0a3 *** empty log message ***
claus
parents: 13
diff changeset
   360
!
20cfbafcd0a3 *** empty log message ***
claus
parents: 13
diff changeset
   361
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   362
enableIOAction:aBlock onInput:aFileDescriptor
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   363
    "half-obsolete event support: arrange for aBlock to be
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   364
     evaluated when input on aFileDescriptor arrives. 
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   365
     This is a leftover support for pure-event systems and may vanish."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   366
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   367
    |idx "{Class: SmallInteger }"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   368
     wasBlocked|
10
claus
parents: 3
diff changeset
   369
93
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   370
    wasBlocked := OperatingSystem blockInterrupts.
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   371
    (readFdArray identityIndexOf:aFileDescriptor startingAt:1) == 0 ifTrue:[
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   372
	idx := readFdArray identityIndexOf:nil startingAt:1.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   373
	idx ~~ 0 ifTrue:[
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   374
	    readFdArray at:idx put:aFileDescriptor.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   375
	    readCheckArray at:idx put:aBlock.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   376
	    readSemaphoreArray at:idx put:nil
159
514c749165c3 *** empty log message ***
claus
parents: 144
diff changeset
   377
	] ifFalse:[
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   378
	    readFdArray := readFdArray copyWith:aFileDescriptor.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   379
	    readCheckArray := readCheckArray copyWith:aBlock.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   380
	    readSemaphoreArray := readSemaphoreArray copyWith:nil.
159
514c749165c3 *** empty log message ***
claus
parents: 144
diff changeset
   381
	]
93
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   382
    ].
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   383
    wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   384
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   385
a27a279701f8 Initial revision
claus
parents:
diff changeset
   386
!ProcessorScheduler methodsFor:'accessing'!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   387
69
4564b6328136 *** empty log message ***
claus
parents: 59
diff changeset
   388
activePriority
4564b6328136 *** empty log message ***
claus
parents: 59
diff changeset
   389
    "return the priority of the currently running process.
159
514c749165c3 *** empty log message ***
claus
parents: 144
diff changeset
   390
     GNU-ST & ST-80 compatibility; this is the same as currentPriority"
69
4564b6328136 *** empty log message ***
claus
parents: 59
diff changeset
   391
4564b6328136 *** empty log message ***
claus
parents: 59
diff changeset
   392
    ^ currentPriority
4564b6328136 *** empty log message ***
claus
parents: 59
diff changeset
   393
!
4564b6328136 *** empty log message ***
claus
parents: 59
diff changeset
   394
25
e34a6267c79b *** empty log message ***
claus
parents: 24
diff changeset
   395
activeProcess
10
claus
parents: 3
diff changeset
   396
    "return the currently running process"
claus
parents: 3
diff changeset
   397
25
e34a6267c79b *** empty log message ***
claus
parents: 24
diff changeset
   398
    ^ activeProcess
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   399
25
e34a6267c79b *** empty log message ***
claus
parents: 24
diff changeset
   400
    "Processor activeProcess"
181
ef3ccf27e2e0 interrupted process now kept for monitor
claus
parents: 161
diff changeset
   401
!
ef3ccf27e2e0 interrupted process now kept for monitor
claus
parents: 161
diff changeset
   402
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   403
currentPriority
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   404
    "return the priority of the currently running process"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   405
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   406
    ^ currentPriority
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
    "Processor currentPriority"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   409
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   410
181
ef3ccf27e2e0 interrupted process now kept for monitor
claus
parents: 161
diff changeset
   411
interruptedProcess
ef3ccf27e2e0 interrupted process now kept for monitor
claus
parents: 161
diff changeset
   412
    "returns the process which was interrupted by the active one"
ef3ccf27e2e0 interrupted process now kept for monitor
claus
parents: 161
diff changeset
   413
ef3ccf27e2e0 interrupted process now kept for monitor
claus
parents: 161
diff changeset
   414
    ^ interruptedProcess
10
claus
parents: 3
diff changeset
   415
! !
claus
parents: 3
diff changeset
   416
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   417
!ProcessorScheduler methodsFor:'background processing'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   418
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   419
addIdleBlock:aBlock
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   420
    "add the argument, aBlock to the list of idle-actions.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   421
     Idle blocks are evaluated whenever no other process is runnable,
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   422
     and no events are pending.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   423
     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
   424
     instead, which has the same effect. Idle blcoks are still included
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   425
     to support background actions in pure-event systems, where no processes 
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   426
     are available.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   427
     Support for idle-blocks may vanish."
10
claus
parents: 3
diff changeset
   428
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   429
    |wasBlocked|
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
    wasBlocked := OperatingSystem blockInterrupts.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   432
    idleActions isNil ifTrue:[
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   433
	idleActions := OrderedCollection new
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   434
    ].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   435
    idleActions add:aBlock.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   436
    wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   437
!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   438
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   439
removeIdleBlock:aBlock
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   440
    "remove the argument, aBlock from the list of idle-blocks.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   441
     Support for idle-blocks may vanish - use low prio processes instead."
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   442
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   443
    |wasBlocked|
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   444
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   445
    wasBlocked := OperatingSystem blockInterrupts.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   446
    idleActions notNil ifTrue:[
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   447
       idleActions remove:aBlock
10
claus
parents: 3
diff changeset
   448
    ].
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   449
    wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
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
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   452
!ProcessorScheduler methodsFor:'constants'!
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
highestPriority
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   455
    "return the highest priority value (normal) processes can have."
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   456
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   457
    "must be below schedulingPriority - 
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   458
     otherwise scheduler could be blocked ...
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
    ^ HighestPriority  
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   461
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   462
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   463
lowIOPriority
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   464
    "not currently used - for ST80 compatibility only"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   465
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   466
    ^ 2 "claus: is this ok ?"
217
a0400fdbc933 *** empty log message ***
claus
parents: 213
diff changeset
   467
!
a0400fdbc933 *** empty log message ***
claus
parents: 213
diff changeset
   468
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   469
lowestPriority
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   470
    "return the lowest priority value"
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
    ^ 1   "do not change this - its not variable"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   473
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   474
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   475
schedulingPriority
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   476
    "return the priority at which the scheduler runs."
241
6f30be88e314 *** empty log message ***
claus
parents: 231
diff changeset
   477
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   478
    "must be above highestPriority - 
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   479
     otherwise scheduler could be blocked ...
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   480
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   481
    ^ SchedulingPriority
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   482
!
241
6f30be88e314 *** empty log message ***
claus
parents: 231
diff changeset
   483
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   484
systemBackgroundPriority
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   485
    "return the priority, at which background system processing
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   486
     should take place.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   487
     Not currently used - for ST80 compatibility only"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   488
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   489
    ^ 4
241
6f30be88e314 *** empty log message ***
claus
parents: 231
diff changeset
   490
!
6f30be88e314 *** empty log message ***
claus
parents: 231
diff changeset
   491
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   492
timingPriority
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   493
    "return the priority, at which all timing takes place (messageTally,
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   494
     delay etc.)"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   495
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   496
    ^ TimingPriority
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   497
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   498
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   499
userBackgroundPriority
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   500
    "return the priority, at which background user (non-interactive) processing
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   501
     should take place.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   502
     Not currently used - for ST80 compatibility only"
217
a0400fdbc933 *** empty log message ***
claus
parents: 213
diff changeset
   503
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   504
    ^ 6
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   505
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   506
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   507
userInterruptPriority
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   508
    "return the priority, at which the event scheduler runs - i.e.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   509
     all processes running at a lower priority are interruptable by Cntl-C
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   510
     or the timer. Processes running at higher prio will not be interrupted."
217
a0400fdbc933 *** empty log message ***
claus
parents: 213
diff changeset
   511
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   512
    ^ UserInterruptPriority
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   513
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   514
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   515
userSchedulingPriority
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   516
    "return the priority, at which all normal user (interactive) processing
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   517
     takes place"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   518
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   519
    ^ UserSchedulingPriority
10
claus
parents: 3
diff changeset
   520
! !
claus
parents: 3
diff changeset
   521
claus
parents: 3
diff changeset
   522
!ProcessorScheduler methodsFor:'dispatching'!
claus
parents: 3
diff changeset
   523
claus
parents: 3
diff changeset
   524
dispatch
93
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   525
     "It handles timeouts and switches to the highest prio runnable process"
44
b262907c93ea *** empty log message ***
claus
parents: 42
diff changeset
   526
829
fc386319f41c removed external function defs (soon no longer allowed)
Claus Gittinger <cg@exept.de>
parents: 827
diff changeset
   527
    |any millis pri p nActions "{ Class: SmallInteger }"
fc386319f41c removed external function defs (soon no longer allowed)
Claus Gittinger <cg@exept.de>
parents: 827
diff changeset
   528
     checkBlock sema|
10
claus
parents: 3
diff changeset
   529
93
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   530
    "
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   531
     handle all timeout actions
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   532
    "
27
d98f9dd437f7 *** empty log message ***
claus
parents: 25
diff changeset
   533
    anyTimeouts ifTrue:[
1679
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   534
	self evaluateTimeouts
10
claus
parents: 3
diff changeset
   535
    ].
claus
parents: 3
diff changeset
   536
231
fd0e55e352f8 cleanup
claus
parents: 217
diff changeset
   537
    "first do a quick check for semaphores using checkActions - this is needed for
302
1f76060d58a4 *** empty log message ***
claus
parents: 271
diff changeset
   538
     devices like the X-connection, where some events might be in the event
1f76060d58a4 *** empty log message ***
claus
parents: 271
diff changeset
   539
     queue. Without these checks, a select might block even though there is work to do
93
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   540
    "
10
claus
parents: 3
diff changeset
   541
    any := false.
231
fd0e55e352f8 cleanup
claus
parents: 217
diff changeset
   542
    nActions := readCheckArray size.
10
claus
parents: 3
diff changeset
   543
    1 to:nActions do:[:index |
1679
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   544
	checkBlock := readCheckArray at:index.
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   545
	(checkBlock notNil and:[checkBlock value]) ifTrue:[
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   546
	    sema := readSemaphoreArray at:index.
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   547
	    sema notNil ifTrue:[
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   548
		sema signalOnce.
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   549
	    ].
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   550
	    any := true.
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   551
	]
10
claus
parents: 3
diff changeset
   552
    ].
claus
parents: 3
diff changeset
   553
231
fd0e55e352f8 cleanup
claus
parents: 217
diff changeset
   554
    "now, someone might be runnable ..."
10
claus
parents: 3
diff changeset
   555
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   556
    p := self highestPriorityRunnableProcess.
10
claus
parents: 3
diff changeset
   557
    p isNil ifTrue:[
1679
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   558
	"/ no one runnable, hard wait for event or timeout
10
claus
parents: 3
diff changeset
   559
1679
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   560
	self waitForEventOrTimeout.
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   561
	^ self
10
claus
parents: 3
diff changeset
   562
    ].
claus
parents: 3
diff changeset
   563
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   564
    pri := p priority.
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   565
302
1f76060d58a4 *** empty log message ***
claus
parents: 271
diff changeset
   566
    "
1f76060d58a4 *** empty log message ***
claus
parents: 271
diff changeset
   567
     want to give control to the process p.
10
claus
parents: 3
diff changeset
   568
     If the switched-to processes priority is lower than the
claus
parents: 3
diff changeset
   569
     userSchedulingPriority, we have to make certain, that the 
claus
parents: 3
diff changeset
   570
     next input or timer will bring us back for a reschedule.
claus
parents: 3
diff changeset
   571
     This is done by enabling ioInterrupts for all file descriptors.
302
1f76060d58a4 *** empty log message ***
claus
parents: 271
diff changeset
   572
     If ioInterrupts are not available (OS does not support them), 
1f76060d58a4 *** empty log message ***
claus
parents: 271
diff changeset
   573
     we schedule a timer interrupt to interrupt us after 1/20s of a second
1f76060d58a4 *** empty log message ***
claus
parents: 271
diff changeset
   574
     - effectively polling the filedescriptors 20 times a second.
1f76060d58a4 *** empty log message ***
claus
parents: 271
diff changeset
   575
     (which is bad, since low prio processes will be hurt in performance)
1f76060d58a4 *** empty log message ***
claus
parents: 271
diff changeset
   576
     Therefore, dont let benchmarks run with low prio ...
1f76060d58a4 *** empty log message ***
claus
parents: 271
diff changeset
   577
231
fd0e55e352f8 cleanup
claus
parents: 217
diff changeset
   578
     Higher prio processes must be suspended, 
302
1f76060d58a4 *** empty log message ***
claus
parents: 271
diff changeset
   579
     same prio ones must yield or suspend to get back control
1f76060d58a4 *** empty log message ***
claus
parents: 271
diff changeset
   580
    "
10
claus
parents: 3
diff changeset
   581
93
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   582
"
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   583
 uncommenting this will make timeouts interrupt the current process
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   584
 (i.e. as if the interrupt runs at TimingPrio); 
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   585
 if left commented, they are handled at UserSchedulingPrio.
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   586
 this will all change, when timeouts are removed and all is process driven
231
fd0e55e352f8 cleanup
claus
parents: 217
diff changeset
   587
 (a future version will have a process running to handle a timeout queue)
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   588
"
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   589
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   590
"
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   591
    pri < TimingPriority ifTrue:[
1679
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   592
	anyTimeouts ifTrue:[
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   593
	    millis := self timeToNextTimeout.
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   594
	    millis == 0 ifTrue:[^ self].
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   595
	]
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   596
    ].
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   597
"
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   598
93
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   599
    "
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   600
     if the process to run has a lower than UserInterruptPriority,
302
1f76060d58a4 *** empty log message ***
claus
parents: 271
diff changeset
   601
     arrange for an interrupt to occur on I/O.
231
fd0e55e352f8 cleanup
claus
parents: 217
diff changeset
   602
     This is done by enabling IO-signals (if the OS supports them)
93
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   603
     or by installing a poll-interrupt after 50ms (if the OS does not).
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   604
    "
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   605
    pri < UserInterruptPriority ifTrue:[
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   606
    
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   607
"comment out this if above is uncommented"
1679
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   608
	anyTimeouts ifTrue:[
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   609
	    millis := self timeToNextTimeout.
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   610
	    millis == 0 ifTrue:[^ self].
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   611
	].
93
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   612
"---"
10
claus
parents: 3
diff changeset
   613
1679
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   614
	useIOInterrupts ifTrue:[
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   615
	    readFdArray do:[:fd |
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   616
		fd notNil ifTrue:[
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   617
		    OperatingSystem enableIOInterruptsOn:fd
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   618
		].
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   619
	    ].
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   620
	] ifFalse:[
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   621
	    millis notNil ifTrue:[
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   622
		millis := millis min:50
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   623
	    ] ifFalse:[
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   624
		millis := 50
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   625
	    ]
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   626
	]
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   627
    ].
10
claus
parents: 3
diff changeset
   628
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   629
    millis notNil ifTrue:[
1679
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   630
	"schedule a clock interrupt after millis milliseconds"
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   631
	OperatingSystem enableTimer:millis rounded.
10
claus
parents: 3
diff changeset
   632
    ].
claus
parents: 3
diff changeset
   633
231
fd0e55e352f8 cleanup
claus
parents: 217
diff changeset
   634
    "
fd0e55e352f8 cleanup
claus
parents: 217
diff changeset
   635
     now let the process run - will come back here by reschedule
fd0e55e352f8 cleanup
claus
parents: 217
diff changeset
   636
     from ioInterrupt or timerInterrupt ... (running at max+1)
fd0e55e352f8 cleanup
claus
parents: 217
diff changeset
   637
    "
10
claus
parents: 3
diff changeset
   638
    self threadSwitch:p.
claus
parents: 3
diff changeset
   639
804
264d440a67a0 Fixes when useIOInterrupts == true.
Stefan Vogel <sv@exept.de>
parents: 786
diff changeset
   640
    "... when we arrive here, we are back on stage.
1679
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   641
	 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
   642
    "
10
claus
parents: 3
diff changeset
   643
claus
parents: 3
diff changeset
   644
    millis notNil ifTrue:[
1679
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   645
	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
   646
    ].
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
   647
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
   648
    "/ 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
   649
    gotChildSignalInterrupt ifTrue:[
1679
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   650
	gotChildSignalInterrupt := false.
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   651
	self handleChildSignalInterrupt
804
264d440a67a0 Fixes when useIOInterrupts == true.
Stefan Vogel <sv@exept.de>
parents: 786
diff changeset
   652
    ].
264d440a67a0 Fixes when useIOInterrupts == true.
Stefan Vogel <sv@exept.de>
parents: 786
diff changeset
   653
264d440a67a0 Fixes when useIOInterrupts == true.
Stefan Vogel <sv@exept.de>
parents: 786
diff changeset
   654
    "/ check for new input
264d440a67a0 Fixes when useIOInterrupts == true.
Stefan Vogel <sv@exept.de>
parents: 786
diff changeset
   655
264d440a67a0 Fixes when useIOInterrupts == true.
Stefan Vogel <sv@exept.de>
parents: 786
diff changeset
   656
    (gotIOInterrupt or:[useIOInterrupts not]) ifTrue:[
1679
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   657
	gotIOInterrupt := false.
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   658
	self checkForInputWithTimeout:0.
10
claus
parents: 3
diff changeset
   659
    ]
768
20434b8239f3 stefans modalBox changes (no more polling)
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
   660
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
   661
    "Modified: 12.4.1996 / 10:14:18 / stefan"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   662
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   663
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   664
dispatchLoop
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   665
    "central dispatch loop; the scheduler process is always staying in
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   666
     this method, looping forever."
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   667
806
409a8c189e01 also handle termination of the scheduler process
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
   668
    |dispatchAction handlerAction ignoredSignals|
786
789e2f20de44 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 780
diff changeset
   669
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   670
    "avoid confusion if entered twice"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   671
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   672
    dispatching == true ifTrue:[^ self].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   673
    dispatching := true.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   674
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
   675
    "/ 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
   676
    "/ 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
   677
    "/ (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
   678
    "/  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
   679
786
789e2f20de44 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 780
diff changeset
   680
    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
   681
806
409a8c189e01 also handle termination of the scheduler process
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
   682
    handlerAction := [:ex |
1679
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   683
                        ('PROCESSOR: ignored signal (', ex signal printString, ')') infoPrintNL.
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   684
                        ex return
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   685
                     ].
806
409a8c189e01 also handle termination of the scheduler process
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
   686
409a8c189e01 also handle termination of the scheduler process
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
   687
    ignoredSignals := SignalSet 
1679
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   688
                        with:(Process terminateSignal)
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   689
                        with:AbortSignal.
786
789e2f20de44 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 780
diff changeset
   690
789e2f20de44 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 780
diff changeset
   691
    "/
789e2f20de44 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 780
diff changeset
   692
    "/ I made this an extra call to dispatch; this allows recompilation
789e2f20de44 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 780
diff changeset
   693
    "/  of the dispatch-handling code in the running system.
789e2f20de44 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 780
diff changeset
   694
    "/
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
   695
    [dispatching] whileTrue:[
1679
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   696
        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
   697
    ].
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
   698
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
   699
    "/ 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
   700
    "/ 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
   701
    "/ 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
   702
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
   703
    'PROCESSOR: finish dispatch (no more processes)' infoPrintNL.
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
   704
827
3eb3911cb63e Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents: 807
diff changeset
   705
    "Modified: 22.12.1995 / 23:12:51 / cg"
1679
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   706
    "Modified: 23.9.1996 / 14:19:56 / stefan"
964
6d87e84d86ac in standAloneMode: exit dispatch if last process dies and no more sema/timer waits are pending
Claus Gittinger <cg@exept.de>
parents: 840
diff changeset
   707
!
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
   708
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
   709
exitWhenNoMoreUserProcesses:aBoolean
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
   710
    exitWhenNoMoreUserProcesses := aBoolean
827
3eb3911cb63e Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents: 807
diff changeset
   711
! !
806
409a8c189e01 also handle termination of the scheduler process
Claus Gittinger <cg@exept.de>
parents: 804
diff changeset
   712
827
3eb3911cb63e Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents: 807
diff changeset
   713
!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
   714
3eb3911cb63e Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents: 807
diff changeset
   715
childSignalInterrupt
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
   716
    "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
   717
     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
   718
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
   719
    gotChildSignalInterrupt := true.
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
   720
    interruptedProcess := activeProcess.
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
   721
    self threadSwitch:scheduler
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
   722
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
   723
    "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
   724
!
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
   725
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
   726
handleChildSignalInterrupt
827
3eb3911cb63e Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents: 807
diff changeset
   727
    "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
   728
     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
   729
523533898acd Reset sigCHLD interrupt handler, when no more processes are being waited for.
Stefan Vogel <sv@exept.de>
parents: 829
diff changeset
   730
    |osProcessStatus blocking wasBlocked|
827
3eb3911cb63e Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents: 807
diff changeset
   731
840
523533898acd Reset sigCHLD interrupt handler, when no more processes are being waited for.
Stefan Vogel <sv@exept.de>
parents: 829
diff changeset
   732
    blocking := OperatingSystem blockingChildProcessWait.
827
3eb3911cb63e Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents: 807
diff changeset
   733
840
523533898acd Reset sigCHLD interrupt handler, when no more processes are being waited for.
Stefan Vogel <sv@exept.de>
parents: 829
diff changeset
   734
    "/ 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
   735
    wasBlocked := OperatingSystem blockInterrupts.
827
3eb3911cb63e Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents: 807
diff changeset
   736
    [
1679
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   737
	[
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   738
	    osProcessStatus := OperatingSystem childProcessWait:blocking.
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   739
	    osProcessStatus notNil ifTrue:[
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   740
		|pid action|
840
523533898acd Reset sigCHLD interrupt handler, when no more processes are being waited for.
Stefan Vogel <sv@exept.de>
parents: 829
diff changeset
   741
1679
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   742
		pid := osProcessStatus pid.
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   743
		osProcessStatus stillAlive ifTrue:[
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   744
		    action := osChildExitActions at:pid ifAbsent:[].
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   745
		] ifFalse:[
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   746
		    action := osChildExitActions removeKey:pid ifAbsent:[].
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   747
		].
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   748
		action notNil ifTrue:[
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   749
		    action value:osProcessStatus
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   750
		].
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   751
	    ].
827
3eb3911cb63e Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents: 807
diff changeset
   752
1679
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   753
	    "/ if pollChildProcesses does block, poll only one status change.
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   754
	    "/ we will get another SIGCHLD for other status changes.
840
523533898acd Reset sigCHLD interrupt handler, when no more processes are being waited for.
Stefan Vogel <sv@exept.de>
parents: 829
diff changeset
   755
1679
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   756
	    osProcessStatus notNil and:[blocking not]
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   757
	] whileTrue.
840
523533898acd Reset sigCHLD interrupt handler, when no more processes are being waited for.
Stefan Vogel <sv@exept.de>
parents: 829
diff changeset
   758
1679
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   759
	"/ if there are no more waiters, disable SIGCHILD handler.
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   760
	"/ this helps us with synchronous waiters (e.g. pclose),
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   761
	"/ But they should block SIGCHLD anyway.
840
523533898acd Reset sigCHLD interrupt handler, when no more processes are being waited for.
Stefan Vogel <sv@exept.de>
parents: 829
diff changeset
   762
1679
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   763
	osChildExitActions isEmpty ifTrue:[
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   764
	    OperatingSystem disableChildSignalInterrupts.
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   765
	].
1032
924c177085f8 care to reenable interrupts
Claus Gittinger <cg@exept.de>
parents: 1001
diff changeset
   766
    ] valueNowOrOnUnwindDo:[
1679
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   767
	wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
1032
924c177085f8 care to reenable interrupts
Claus Gittinger <cg@exept.de>
parents: 1001
diff changeset
   768
    ]
827
3eb3911cb63e Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents: 807
diff changeset
   769
840
523533898acd Reset sigCHLD interrupt handler, when no more processes are being waited for.
Stefan Vogel <sv@exept.de>
parents: 829
diff changeset
   770
    "Modified: 5.1.1996 / 16:56:11 / stefan"
1032
924c177085f8 care to reenable interrupts
Claus Gittinger <cg@exept.de>
parents: 1001
diff changeset
   771
    "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
   772
    "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
   773
!
3eb3911cb63e Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents: 807
diff changeset
   774
3eb3911cb63e Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents: 807
diff changeset
   775
monitorPid:pid action:aBlock
840
523533898acd Reset sigCHLD interrupt handler, when no more processes are being waited for.
Stefan Vogel <sv@exept.de>
parents: 829
diff changeset
   776
    "add a 1-arg-block that is called when the operating system child process
523533898acd Reset sigCHLD interrupt handler, when no more processes are being waited for.
Stefan Vogel <sv@exept.de>
parents: 829
diff changeset
   777
     with pid pid changes state.
523533898acd Reset sigCHLD interrupt handler, when no more processes are being waited for.
Stefan Vogel <sv@exept.de>
parents: 829
diff changeset
   778
     The argument for the block is an OSProcessStatus.
827
3eb3911cb63e Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents: 807
diff changeset
   779
    "
3eb3911cb63e Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents: 807
diff changeset
   780
840
523533898acd Reset sigCHLD interrupt handler, when no more processes are being waited for.
Stefan Vogel <sv@exept.de>
parents: 829
diff changeset
   781
    OperatingSystem sigCHLD ~= 0 ifTrue:[
1679
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   782
	"/ SIGCHLD is supported,
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   783
	"/ aBlock will be evaluated, as soon as a SIGCHLD interrupt for pid has been received.
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   784
	OperatingSystem enableChildSignalInterrupts.
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   785
	osChildExitActions at:pid put:aBlock
840
523533898acd Reset sigCHLD interrupt handler, when no more processes are being waited for.
Stefan Vogel <sv@exept.de>
parents: 829
diff changeset
   786
    ] ifFalse:[
1679
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   787
	|osProcessStatus|
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   788
	"/ SIGCHLD is not supported, wait synchronously for the exit
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   789
	"/ of pid.
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   790
	[
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   791
	    osProcessStatus := OperatingSystem childProcessWait:true.
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   792
	    osProcessStatus notNil ifTrue:[
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   793
		(osProcessStatus pid = pid) ifTrue:[
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   794
		    aBlock value:osProcessStatus.
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   795
		].
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   796
		osProcessStatus stillAlive
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   797
	    ].
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   798
	] whileTrue.
840
523533898acd Reset sigCHLD interrupt handler, when no more processes are being waited for.
Stefan Vogel <sv@exept.de>
parents: 829
diff changeset
   799
    ].
827
3eb3911cb63e Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents: 807
diff changeset
   800
3eb3911cb63e Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents: 807
diff changeset
   801
    "Created: 28.12.1995 / 14:22:10 / stefan"
840
523533898acd Reset sigCHLD interrupt handler, when no more processes are being waited for.
Stefan Vogel <sv@exept.de>
parents: 829
diff changeset
   802
    "Modified: 5.1.1996 / 22:01:06 / stefan"
1166
f5affd8cb289 added #unmonitorPid: - there still is trouble with zombie subchilds, if a process is killed via #killProcess:
Claus Gittinger <cg@exept.de>
parents: 1154
diff changeset
   803
!
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
   804
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
   805
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
   806
    "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
   807
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
   808
    osChildExitActions removeKey:pid ifAbsent:[].
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
   809
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
   810
    "Created: 12.4.1996 / 19:01:59 / cg"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   811
! !
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   812
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   813
!ProcessorScheduler methodsFor:'primitive process primitives'!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   814
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   815
scheduleForInterrupt:aProcess
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   816
    "make aProcess evaluate its pushed interrupt block(s)"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   817
1092
2a8acc60f5b5 added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents: 1086
diff changeset
   818
    self scheduleInterruptActionsOf:aProcess.
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   819
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   820
     and, make the process runnable
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   821
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   822
    aProcess state ~~ #stopped ifTrue:[
1679
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   823
	"
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   824
	 and, make the process runnable
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   825
	"
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   826
	self resume:aProcess
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   827
    ]
1092
2a8acc60f5b5 added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents: 1086
diff changeset
   828
1473
63918b669150 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1347
diff changeset
   829
    "Modified: 17.6.1996 / 14:40:52 / cg"
1092
2a8acc60f5b5 added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents: 1086
diff changeset
   830
!
2a8acc60f5b5 added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents: 1086
diff changeset
   831
2a8acc60f5b5 added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents: 1086
diff changeset
   832
scheduleInterruptActionsOf:aProcess
2a8acc60f5b5 added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents: 1086
diff changeset
   833
    "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
   834
     when resumed."
2a8acc60f5b5 added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents: 1086
diff changeset
   835
2a8acc60f5b5 added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents: 1086
diff changeset
   836
    |id|
2a8acc60f5b5 added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents: 1086
diff changeset
   837
2a8acc60f5b5 added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents: 1086
diff changeset
   838
    aProcess isNil ifTrue:[^ self].
2a8acc60f5b5 added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents: 1086
diff changeset
   839
    aProcess == activeProcess ifTrue:[^ self].
2a8acc60f5b5 added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents: 1086
diff changeset
   840
2a8acc60f5b5 added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents: 1086
diff changeset
   841
    id := aProcess id.
2a8acc60f5b5 added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents: 1086
diff changeset
   842
    self class threadInterrupt:id.
2a8acc60f5b5 added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents: 1086
diff changeset
   843
2a8acc60f5b5 added mechanism for a block to be evaluated onResume
Claus Gittinger <cg@exept.de>
parents: 1086
diff changeset
   844
    "Created: 5.3.1996 / 17:25:55 / cg"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   845
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   846
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   847
threadSwitch:aProcess
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   848
    "continue execution in aProcess.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   849
     (warning: low level entry, no administration is done here)"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   850
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   851
    |id pri ok oldProcess oldPri p singleStep wasBlocked|
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   852
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   853
    (aProcess isNil or:[aProcess == activeProcess]) ifTrue:[^ self].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   854
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   855
    wasBlocked := OperatingSystem blockInterrupts.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   856
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   857
    oldProcess := activeProcess.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   858
    oldPri := currentPriority.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   859
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   860
    id := aProcess id.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   861
    pri := aProcess priority.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   862
    singleStep := aProcess isSingleStepping.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   863
    aProcess state:#active.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   864
    oldProcess setStateTo:#run if:#active.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   865
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   866
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   867
     no interrupts now - activeProcess has already been changed
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   868
     (dont add any message sends here)
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   869
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   870
    activeProcess := aProcess.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   871
    currentPriority := pri.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   872
%{
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   873
    extern OBJ ___threadSwitch();
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   874
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   875
    if (__isSmallInteger(id)) {
1679
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   876
	ok = ___threadSwitch(__context, __intVal(id), (singleStep == true) ? 1 : 0);
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   877
    } else {
1679
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   878
	ok = false;
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   879
    }
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   880
%}.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   881
    "time passes spent in some other process ...
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   882
     ... here again"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   883
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   884
    p := activeProcess.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   885
    activeProcess := oldProcess.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   886
    currentPriority := oldProcess priority.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   887
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   888
    ok ifFalse:[
1679
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   889
	"
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   890
	 switch failed for some reason -
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   891
	 destroy the bad process
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   892
	"
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   893
	p id ~~ 0 ifTrue:[
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   894
	    'PROCESSOR: problem with process ' errorPrint. 
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   895
		p id errorPrint. 
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   896
		p name notNil ifTrue:[
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   897
		    ' (' errorPrint. p name errorPrint. ')' errorPrint.
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   898
		].
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   899
		'; hard-terminate it.' errorPrintNL.
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   900
	    p state:#suspended.
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   901
	    self terminateNoSignal:p.
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   902
	]
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   903
    ].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   904
    zombie notNil ifTrue:[
1679
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   905
	self class threadDestroy:zombie.
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   906
	zombie := nil
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   907
    ].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   908
    wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   909
! !
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   910
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   911
!ProcessorScheduler methodsFor:'private'!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   912
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   913
remember:aProcess
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   914
    "remember aProcess for later disposal (where the underlying
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   915
     system resources have to be freed)."
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   916
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   917
    |newShadow oldId wasBlocked
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   918
     oldSize "{ Class: SmallInteger }"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   919
     index   "{ Class: SmallInteger }"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   920
     sz      "{ Class: SmallInteger }" |
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   921
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   922
    wasBlocked := OperatingSystem blockInterrupts.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   923
    index := 1.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   924
    sz := KnownProcessIds size.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   925
    [index <= sz] whileTrue:[
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   926
	(KnownProcesses at:index) isNil ifTrue:[
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   927
	    oldId := KnownProcessIds at:index.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   928
	    oldId notNil ifTrue:[
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   929
		self class threadDestroy:oldId.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   930
	    ].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   931
	    KnownProcesses at:index put:aProcess.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   932
	    KnownProcessIds at:index put:aProcess id.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   933
	    wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   934
	    ^ self
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   935
	].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   936
	index := index + 1
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   937
    ].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   938
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   939
    KnownProcessIds grow:index.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   940
    KnownProcessIds at:index put:aProcess id.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   941
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   942
    oldSize := KnownProcesses size.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   943
    (index > oldSize) ifTrue:[
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   944
	newShadow := WeakArray new:(oldSize * 2).
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   945
	newShadow watcher:self class.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   946
	newShadow replaceFrom:1 with:KnownProcesses.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   947
	KnownProcesses := newShadow
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   948
    ].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   949
    KnownProcesses at:index put:aProcess.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   950
    wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   951
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   952
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   953
unRemember:aProcess
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   954
    "forget aProcess - dispose processing will not consider this one"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   955
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   956
    |index wasBlocked|
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   957
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   958
    wasBlocked := OperatingSystem blockInterrupts.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   959
    index := KnownProcesses identityIndexOf:aProcess.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   960
    index ~~ 0 ifTrue:[
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   961
	KnownProcessIds at:index put:nil.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   962
	KnownProcesses at:index put:nil.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   963
    ].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   964
    wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   965
! !
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   966
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   967
!ProcessorScheduler methodsFor:'private initializing'!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   968
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   969
initialize
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   970
    "initialize the one-and-only ProcessorScheduler"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   971
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   972
    |nPrios "{ Class: SmallInteger }"
1618
9fb4ee952e89 use nil for empty lists
Claus Gittinger <cg@exept.de>
parents: 1606
diff changeset
   973
     p l|
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   974
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   975
    KnownProcesses isNil ifTrue:[
1679
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   976
	KnownProcesses := WeakArray new:10.
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   977
	KnownProcesses watcher:self class.
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
   978
	KnownProcessIds := OrderedCollection new.
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   979
    ].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   980
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   981
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   982
     create a collection with process lists; accessed using the priority as key
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   983
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   984
    nPrios := SchedulingPriority.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   985
    quiescentProcessLists := Array new:nPrios.
1618
9fb4ee952e89 use nil for empty lists
Claus Gittinger <cg@exept.de>
parents: 1606
diff changeset
   986
"/    1 to:nPrios do:[:pri |
9fb4ee952e89 use nil for empty lists
Claus Gittinger <cg@exept.de>
parents: 1606
diff changeset
   987
"/        quiescentProcessLists at:pri put:(LinkedList new)
9fb4ee952e89 use nil for empty lists
Claus Gittinger <cg@exept.de>
parents: 1606
diff changeset
   988
"/    ].
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   989
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   990
    readFdArray := Array with:nil.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   991
    readCheckArray := Array with:nil.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   992
    readSemaphoreArray := Array with:nil.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   993
    writeFdArray := Array with:nil.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   994
    writeSemaphoreArray := Array with:nil.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   995
    timeoutArray := Array with:nil.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   996
    timeoutSemaphoreArray := Array with:nil.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   997
    timeoutActionArray := Array with:nil.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   998
    timeoutProcessArray := Array with:nil.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
   999
    anyTimeouts := false.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1000
    dispatching := false.
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
  1001
    exitWhenNoMoreUserProcesses := false. "/ mhmh - how about true ?
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1002
    useIOInterrupts := OperatingSystem supportsIOInterrupts.
804
264d440a67a0 Fixes when useIOInterrupts == true.
Stefan Vogel <sv@exept.de>
parents: 786
diff changeset
  1003
    gotIOInterrupt := false.
827
3eb3911cb63e Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents: 807
diff changeset
  1004
    osChildExitActions := Dictionary new.
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
  1005
    gotChildSignalInterrupt := false.
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1006
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1007
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1008
     handcraft the first (dispatcher-) process - this one will never
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1009
     block, but go into a select if there is nothing to do.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1010
     Also, it has a prio of max+1 - thus, it comes first when looking
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1011
     for a runnable process.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1012
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1013
    currentPriority := SchedulingPriority.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1014
    p := Process new.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1015
    p setId:0 state:#run.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1016
    p setPriority:currentPriority.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1017
    p name:'scheduler'.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1018
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1019
    scheduler := activeProcess := p.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1020
1618
9fb4ee952e89 use nil for empty lists
Claus Gittinger <cg@exept.de>
parents: 1606
diff changeset
  1021
    quiescentProcessLists at:currentPriority put:(l := LinkedList new).
9fb4ee952e89 use nil for empty lists
Claus Gittinger <cg@exept.de>
parents: 1606
diff changeset
  1022
    l add:p.
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1023
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1024
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1025
     let me handle IO and timer interrupts
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1026
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1027
    ObjectMemory ioInterruptHandler:self.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1028
    ObjectMemory timerInterruptHandler:self.
827
3eb3911cb63e Support of SIGCHL interrupt handling and OS-independent proces status
Stefan Vogel <sv@exept.de>
parents: 807
diff changeset
  1029
    ObjectMemory childSignalInterruptHandler:self.
804
264d440a67a0 Fixes when useIOInterrupts == true.
Stefan Vogel <sv@exept.de>
parents: 786
diff changeset
  1030
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
  1031
    "Modified: 12.4.1996 / 10:12:56 / stefan"
1618
9fb4ee952e89 use nil for empty lists
Claus Gittinger <cg@exept.de>
parents: 1606
diff changeset
  1032
    "Modified: 29.7.1996 / 12:10:59 / cg"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1033
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1034
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1035
reinitialize
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1036
    "all previous processes (except those marked as restartable) are made dead 
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1037
     - each object should reinstall its process(s) upon restart;
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1038
     especially, windowgroups have to.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1039
     In contrast to ST-80, restartable processes are restarted at the beginning
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1040
     NOT continued where left. This is a consequence of the portable implementation
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1041
     of ST/X, since in order to continue a process, we needed to know the
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1042
     internals of the machines (and C-compilers) stack layout.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1043
     This was not done, favouring portability for process continuation.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1044
     In praxis, this is not much of a problem, since in almost every case,
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1045
     the computation state can be saved in some object, and processing be 
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1046
     restarted from scratch, reinitializing things from this saved state."
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1047
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1048
    |processesToRestart|
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1049
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1050
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1051
     lay all processes to rest, collect restartable ones
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1052
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1053
    processesToRestart := OrderedCollection new.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1054
    KnownProcesses do:[:p |
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1055
	p notNil ifTrue:[
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1056
	    "how, exactly should this be done ?"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1057
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1058
	    p isRestartable == true ifTrue:[
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1059
		p nextLink:nil.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1060
		processesToRestart add:p
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1061
	    ] ifFalse:[
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1062
		p setId:nil state:#dead
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1063
	    ]
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1064
	].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1065
    ].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1066
    scheduler setId:nil state:#dead. 
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1067
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1068
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1069
     now, start from scratch
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1070
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1071
    KnownProcesses := nil.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1072
    self initialize.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1073
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1074
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1075
     ... and restart those that can be.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1076
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1077
    processesToRestart do:[:p |
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1078
"/        'process restart not implemented' errorPrintNL.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1079
	p restart
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1080
    ]
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1081
! !
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1082
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1083
!ProcessorScheduler methodsFor:'process creation'!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1084
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1085
newProcessFor:aProcess
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1086
    "create a physical (VM-) process for aProcess.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1087
     Return true if ok, false if something went wrong.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1088
     The process is not scheduled; to start it running, 
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1089
     it needs a Process>>resume. Once resumed, the process will later 
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1090
     get control in its #start method."
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1091
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1092
    |id|
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1093
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1094
    id := self class threadCreate:aProcess withId:nil.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1095
    id isNil ifTrue:[^ false].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1096
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1097
    aProcess setId:id state:#light.   "meaning: has no stack yet"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1098
    self remember:aProcess.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1099
    ^ true
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1100
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1101
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1102
newProcessFor:aProcess withId:idWant
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1103
    "private entry for Process restart - do not use in your program"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1104
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1105
    (self class threadCreate:aProcess withId:idWant) ~~ idWant ifTrue:[
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1106
	^ false
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1107
    ].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1108
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1109
    aProcess state:#light.   "meaning: has no stack yet"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1110
    self remember:aProcess.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1111
    ^ true
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1112
! !
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1113
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1114
!ProcessorScheduler methodsFor:'queries'!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1115
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1116
activeProcessIsSystemProcess
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1117
    "return true if the active process is a system process,
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1118
     which should not be suspended."
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1119
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1120
    ^ self isSystemProcess:activeProcess
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1121
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1122
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1123
     Processor activeProcessIsSystemProcess
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1124
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1125
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1126
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
  1127
anyUserProcessAtAll
1571
8d00e6b97ca7 changed #anyUserProcessAtAll,
Claus Gittinger <cg@exept.de>
parents: 1473
diff changeset
  1128
    "return true, if there is any process still running with a
8d00e6b97ca7 changed #anyUserProcessAtAll,
Claus Gittinger <cg@exept.de>
parents: 1473
diff changeset
  1129
     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
  1130
     This is used to determine if we should stop scheduling
1571
8d00e6b97ca7 changed #anyUserProcessAtAll,
Claus Gittinger <cg@exept.de>
parents: 1473
diff changeset
  1131
     in standAlone applications."
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
  1132
987
b00ae288b524 removed unused locals
Claus Gittinger <cg@exept.de>
parents: 964
diff changeset
  1133
    |listArray l prio "{ Class: SmallInteger }" |
964
6d87e84d86ac in standAloneMode: exit dispatch if last process dies and no more sema/timer waits are pending
Claus Gittinger <cg@exept.de>
parents: 840
diff changeset
  1134
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
  1135
    prio := HighestPriority.
6d87e84d86ac in standAloneMode: exit dispatch if last process dies and no more sema/timer waits are pending
Claus Gittinger <cg@exept.de>
parents: 840
diff changeset
  1136
    listArray := quiescentProcessLists.
1571
8d00e6b97ca7 changed #anyUserProcessAtAll,
Claus Gittinger <cg@exept.de>
parents: 1473
diff changeset
  1137
8d00e6b97ca7 changed #anyUserProcessAtAll,
Claus Gittinger <cg@exept.de>
parents: 1473
diff changeset
  1138
    [prio >= 1] whileTrue:[
1679
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  1139
	l := listArray at:prio.
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  1140
	l notNil ifTrue:[
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  1141
	    l do:[:aProcess |
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  1142
		aProcess processGroupId ~~ 0 ifTrue:[
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  1143
		    ^ true.
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  1144
		]
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  1145
	    ]
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  1146
	].
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  1147
	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
  1148
    ].
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
  1149
    ^ false
1571
8d00e6b97ca7 changed #anyUserProcessAtAll,
Claus Gittinger <cg@exept.de>
parents: 1473
diff changeset
  1150
8d00e6b97ca7 changed #anyUserProcessAtAll,
Claus Gittinger <cg@exept.de>
parents: 1473
diff changeset
  1151
    "
8d00e6b97ca7 changed #anyUserProcessAtAll,
Claus Gittinger <cg@exept.de>
parents: 1473
diff changeset
  1152
     Processor anyUserProcessAtAll  
8d00e6b97ca7 changed #anyUserProcessAtAll,
Claus Gittinger <cg@exept.de>
parents: 1473
diff changeset
  1153
    "
8d00e6b97ca7 changed #anyUserProcessAtAll,
Claus Gittinger <cg@exept.de>
parents: 1473
diff changeset
  1154
1618
9fb4ee952e89 use nil for empty lists
Claus Gittinger <cg@exept.de>
parents: 1606
diff changeset
  1155
    "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
  1156
!
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
  1157
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1158
highestPriorityRunnableProcess
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1159
    "return the highest prio runnable process"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1160
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1161
    |listArray l p prio "{ Class: SmallInteger }" |
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1162
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1163
    prio := HighestPriority.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1164
    listArray := quiescentProcessLists.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1165
    [prio >= 1] whileTrue:[
1679
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  1166
	l := listArray at:prio.
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  1167
	l notNil ifTrue:[
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  1168
	    l notEmpty ifTrue:[
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  1169
		p := l first.
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  1170
		"
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  1171
		 if it got corrupted somehow ...
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  1172
		"
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  1173
		p id isNil ifTrue:[
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  1174
		    'PROCESSOR: process with nil id removed' errorPrintNL.
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  1175
		    l removeFirst.
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  1176
		    ^ nil.
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  1177
		].
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  1178
		^ p
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  1179
	    ]
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  1180
	].
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  1181
	prio := prio - 1
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1182
    ].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1183
    ^ nil
1086
7b0641a2e1ef nicer message
Claus Gittinger <cg@exept.de>
parents: 1061
diff changeset
  1184
1618
9fb4ee952e89 use nil for empty lists
Claus Gittinger <cg@exept.de>
parents: 1606
diff changeset
  1185
    "Modified: 29.7.1996 / 11:49:47 / cg"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1186
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1187
1177
05f4917ccc4f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1166
diff changeset
  1188
isPureEventDriven
05f4917ccc4f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1166
diff changeset
  1189
    "this is temporary - (maybe not :-).
05f4917ccc4f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1166
diff changeset
  1190
     you can run ST/X either with or without processes.
05f4917ccc4f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1166
diff changeset
  1191
     Without, there is conceptionally a single process handling all
05f4917ccc4f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1166
diff changeset
  1192
     outside events and timeouts. This has some negative implications
05f4917ccc4f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1166
diff changeset
  1193
     (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
  1194
     assembler support - i.e. quick portability.
05f4917ccc4f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1166
diff changeset
  1195
     The PureEvent flag will automatically be set if the runtime system
05f4917ccc4f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1166
diff changeset
  1196
     does not support threads - otherwise, it can be set manually
05f4917ccc4f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1166
diff changeset
  1197
     (from rc-file).
05f4917ccc4f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1166
diff changeset
  1198
    "
05f4917ccc4f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1166
diff changeset
  1199
05f4917ccc4f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1166
diff changeset
  1200
    ^ PureEventDriven
05f4917ccc4f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1166
diff changeset
  1201
05f4917ccc4f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1166
diff changeset
  1202
    "Created: 13.4.1996 / 20:31:31 / cg"
05f4917ccc4f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1166
diff changeset
  1203
!
05f4917ccc4f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1166
diff changeset
  1204
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1205
isSystemProcess:aProcess
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1206
    "return true if aProcess is a system process,
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1207
     which should not be suspended/terminated etc.."
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1208
1177
05f4917ccc4f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1166
diff changeset
  1209
    (PureEventDriven 
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1210
    or:[aProcess id == 0
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1211
    or:[(Display notNil and:[Display dispatchProcess == aProcess])
1679
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  1212
	" nameOrId endsWith:'dispatcher' "
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1213
    ]]) ifTrue:[
1679
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  1214
	^ true
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1215
    ].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1216
    ^ false
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1217
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1218
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1219
     Processor activeProcessIsSystemProcess
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1220
    "
1177
05f4917ccc4f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1166
diff changeset
  1221
05f4917ccc4f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1166
diff changeset
  1222
    "Modified: 13.4.1996 / 20:35:00 / cg"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1223
! !
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1224
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1225
!ProcessorScheduler methodsFor:'scheduling'!
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
changePriority:prio for:aProcess
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1228
    "change the priority of aProcess"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1229
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1230
    |oldList newList oldPrio newPrio wasBlocked|
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1231
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1232
    oldPrio := aProcess priority.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1233
    oldPrio == prio ifTrue:[^ self].
1042
cc49fd1e3c7e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1032
diff changeset
  1234
    aProcess == scheduler ifTrue:[^ self].
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1235
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1236
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1237
     check for valid argument
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1238
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1239
    newPrio := prio.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1240
    newPrio < 1 ifTrue:[
1679
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  1241
	newPrio := 1.
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1242
    ] ifFalse:[
1679
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  1243
	newPrio > HighestPriority ifTrue:[
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  1244
	    newPrio := HighestPriority
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  1245
	]
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1246
    ].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1247
1042
cc49fd1e3c7e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1032
diff changeset
  1248
    [
1679
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  1249
	wasBlocked := OperatingSystem blockInterrupts.
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1250
1679
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  1251
	aProcess setPriority:newPrio.
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1252
1679
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  1253
	oldList := quiescentProcessLists at:oldPrio.
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  1254
	oldList notNil ifTrue:[
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  1255
	    (oldList identityIndexOf:aProcess) ~~ 0 ifTrue:[
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  1256
		oldList remove:aProcess.
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1257
1679
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  1258
		newList := quiescentProcessLists at:newPrio.
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  1259
		newList isNil ifTrue:[
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  1260
		    quiescentProcessLists at:newPrio put:(newList := LinkedList new).
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  1261
		].
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  1262
		newList addLast:aProcess.
1042
cc49fd1e3c7e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1032
diff changeset
  1263
1679
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  1264
		"if its the current process lowering its prio 
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  1265
		 or another one raising, we have to reschedule"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1266
1679
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  1267
		aProcess == activeProcess ifTrue:[
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  1268
		    currentPriority := newPrio.
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  1269
		    newPrio < oldPrio ifTrue:[
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  1270
			self threadSwitch:scheduler.    
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  1271
		    ]
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  1272
		] ifFalse:[
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  1273
		    newPrio > currentPriority ifTrue:[
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  1274
			self threadSwitch:aProcess.
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  1275
		    ]
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  1276
		].
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  1277
	    ].
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  1278
	]
1042
cc49fd1e3c7e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1032
diff changeset
  1279
    ] valueNowOrOnUnwindDo:[
1679
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  1280
	wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
1042
cc49fd1e3c7e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1032
diff changeset
  1281
    ]
1032
924c177085f8 care to reenable interrupts
Claus Gittinger <cg@exept.de>
parents: 1001
diff changeset
  1282
1618
9fb4ee952e89 use nil for empty lists
Claus Gittinger <cg@exept.de>
parents: 1606
diff changeset
  1283
    "Modified: 29.7.1996 / 12:11:57 / cg"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1284
!
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
interruptActive
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1287
    "interrupt the current process"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1288
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1289
    activeProcess interrupt
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1290
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1291
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1292
processTermination
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1293
    "sent by VM if the current process finished its startup block 
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1294
     without proper process termination. Lay him to rest now. 
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1295
     This can only happen, if something went wrong in Block>>newProcess, 
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1296
     since the block defined there always terminates itself."
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1297
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1298
    self terminateNoSignal:activeProcess.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1299
    self threadSwitch:scheduler
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1300
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1301
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1302
reschedule
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1303
    "switch to the highest prio runnable process.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1304
     The scheduler itself is always runnable, so we can do an unconditional switch
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1305
     to that one. This method is a historical left-over and will vanish."
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1306
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1307
    ^ self threadSwitch:scheduler
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1308
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1309
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1310
resume:aProcess
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1311
    "set aProcess runnable - 
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1312
     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
  1313
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1314
    |l pri wasBlocked|
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1315
1679
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  1316
    "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
  1317
    (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
  1318
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1319
1679
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  1320
    aProcess == activeProcess ifTrue:[
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  1321
	"special handling for waiting schedulers"
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  1322
	aProcess == scheduler ifTrue:[
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  1323
	    suspendScheduler := false.
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  1324
	].
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  1325
	^ self
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  1326
    ].
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1327
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1328
    wasBlocked := OperatingSystem blockInterrupts.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1329
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1330
    pri := aProcess priority.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1331
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1332
    l := quiescentProcessLists at:pri.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1333
    "if already running, ignore"
1618
9fb4ee952e89 use nil for empty lists
Claus Gittinger <cg@exept.de>
parents: 1606
diff changeset
  1334
    l notNil ifTrue:[
1679
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  1335
	(l identityIndexOf:aProcess) ~~ 0 ifTrue:[
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  1336
	    wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  1337
	    ^ self
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  1338
	]
1618
9fb4ee952e89 use nil for empty lists
Claus Gittinger <cg@exept.de>
parents: 1606
diff changeset
  1339
    ] ifFalse:[
1679
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  1340
	l := LinkedList new.
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  1341
	quiescentProcessLists at:pri put:l.
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1342
    ].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1343
    l addLast:aProcess.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1344
    wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1345
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1346
    (pri > currentPriority) ifTrue:[
1679
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  1347
	"
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  1348
	 its prio is higher; immediately transfer control to it
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  1349
	"
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  1350
	self threadSwitch:aProcess
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1351
    ] ifFalse:[
1679
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  1352
	"
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  1353
	 its prio is lower; it will have to wait for a while ...
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  1354
	"
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  1355
	aProcess state:#run 
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1356
    ]
1618
9fb4ee952e89 use nil for empty lists
Claus Gittinger <cg@exept.de>
parents: 1606
diff changeset
  1357
9fb4ee952e89 use nil for empty lists
Claus Gittinger <cg@exept.de>
parents: 1606
diff changeset
  1358
    "Modified: 29.7.1996 / 12:07:37 / cg"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1359
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1360
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1361
resumeForSingleSend:aProcess
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1362
    "like resume, but let the process execute a single send only.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1363
     This will be used by the (new, not yet released) debugger 
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1364
     for single stepping."
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1365
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1366
    (aProcess isNil or:[aProcess == activeProcess]) ifTrue:[^ self].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1367
    aProcess singleStep:true.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1368
    self resume:aProcess
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1369
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1370
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1371
suspend:aProcess
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1372
    "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
  1373
     If the process is the current one, reschedule.
0259dd855289 new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents: 750
diff changeset
  1374
     This method should only be called by Process>>suspend"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1375
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1376
    |pri l p wasBlocked|
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1377
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1378
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1379
     some debugging stuff
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1380
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1381
    aProcess isNil ifTrue:[
1679
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  1382
        InvalidProcessSignal raiseWith:aProcess errorString:'PROCESSOR: nil suspend'.
1618
9fb4ee952e89 use nil for empty lists
Claus Gittinger <cg@exept.de>
parents: 1606
diff changeset
  1383
        ^ self
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1384
    ].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1385
    aProcess id isNil ifTrue:[
1679
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  1386
        InvalidProcessSignal raiseWith:aProcess errorString:'PROCESSOR: bad suspend: already dead'.
1618
9fb4ee952e89 use nil for empty lists
Claus Gittinger <cg@exept.de>
parents: 1606
diff changeset
  1387
        self threadSwitch:scheduler.
9fb4ee952e89 use nil for empty lists
Claus Gittinger <cg@exept.de>
parents: 1606
diff changeset
  1388
        ^ self
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1389
    ].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1390
    aProcess == scheduler ifTrue:[
1679
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  1391
        "only scheduler may suspend itself"
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  1392
        activeProcess == scheduler ifTrue:[
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  1393
            suspendScheduler := true.
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  1394
            [suspendScheduler] whileTrue:[
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  1395
                self dispatch.
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  1396
            ].
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  1397
            ^ self
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  1398
        ].
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  1399
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  1400
        InvalidProcessSignal raiseWith:aProcess errorString:'PROCESSOR: scheduler should never be suspended'.
1618
9fb4ee952e89 use nil for empty lists
Claus Gittinger <cg@exept.de>
parents: 1606
diff changeset
  1401
        ^ self
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1402
    ].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1403
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1404
    wasBlocked := OperatingSystem blockInterrupts.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1405
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1406
    pri := aProcess priority.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1407
    l := quiescentProcessLists at:pri.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1408
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1409
    "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
  1410
     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
  1411
    "
1618
9fb4ee952e89 use nil for empty lists
Claus Gittinger <cg@exept.de>
parents: 1606
diff changeset
  1412
    (l isNil or:[(l remove:aProcess ifAbsent:[]) isNil]) ifTrue:[
9fb4ee952e89 use nil for empty lists
Claus Gittinger <cg@exept.de>
parents: 1606
diff changeset
  1413
        wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
9fb4ee952e89 use nil for empty lists
Claus Gittinger <cg@exept.de>
parents: 1606
diff changeset
  1414
        'PROCESSOR: bad suspend: not on run list' errorPrintNL.
9fb4ee952e89 use nil for empty lists
Claus Gittinger <cg@exept.de>
parents: 1606
diff changeset
  1415
        "/ MiniDebugger enterWithMessage:'bad suspend: not on run list'.
9fb4ee952e89 use nil for empty lists
Claus Gittinger <cg@exept.de>
parents: 1606
diff changeset
  1416
        self threadSwitch:scheduler.
9fb4ee952e89 use nil for empty lists
Claus Gittinger <cg@exept.de>
parents: 1606
diff changeset
  1417
        ^ self
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1418
    ].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1419
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1420
    wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1421
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1422
    (aProcess == activeProcess) ifTrue:[
1618
9fb4ee952e89 use nil for empty lists
Claus Gittinger <cg@exept.de>
parents: 1606
diff changeset
  1423
        "we can immediately switch sometimes"
9fb4ee952e89 use nil for empty lists
Claus Gittinger <cg@exept.de>
parents: 1606
diff changeset
  1424
        l notEmpty ifTrue:[
9fb4ee952e89 use nil for empty lists
Claus Gittinger <cg@exept.de>
parents: 1606
diff changeset
  1425
            p := l first
9fb4ee952e89 use nil for empty lists
Claus Gittinger <cg@exept.de>
parents: 1606
diff changeset
  1426
        ] ifFalse:[
9fb4ee952e89 use nil for empty lists
Claus Gittinger <cg@exept.de>
parents: 1606
diff changeset
  1427
            p := scheduler
9fb4ee952e89 use nil for empty lists
Claus Gittinger <cg@exept.de>
parents: 1606
diff changeset
  1428
        ].
9fb4ee952e89 use nil for empty lists
Claus Gittinger <cg@exept.de>
parents: 1606
diff changeset
  1429
        self threadSwitch:p 
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1430
    ].
752
0259dd855289 new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents: 750
diff changeset
  1431
1618
9fb4ee952e89 use nil for empty lists
Claus Gittinger <cg@exept.de>
parents: 1606
diff changeset
  1432
    "Modified: 29.7.1996 / 11:52:16 / cg"
1679
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  1433
    "Modified: 23.9.1996 / 13:49:24 / stefan"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1434
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1435
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1436
terminate:aProcess
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1437
    "terminate aProcess. This is donen by sending aProcess the terminateSignal,
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1438
     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
  1439
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1440
    aProcess terminate
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1441
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1442
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1443
terminateActive
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1444
    "terminate the current process (i.e. the running process kills itself).
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1445
     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
  1446
     unwind blocks and finally do a hard terminate.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1447
     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
  1448
     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
  1449
     continued to grow its stack)"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1450
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1451
    activeProcess terminate
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
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1454
terminateActiveNoSignal
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1455
    "hard terminate the active process, without sending any
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1456
     terminate signal thus no unwind blocks are evaluated."
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1457
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1458
    self terminateNoSignal:activeProcess
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1459
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1460
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1461
terminateNoSignal:aProcess
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1462
    "hard terminate aProcess without sending the terminate signal, thus
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1463
     no unwind blocks or exitAction are performed in the process.. 
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1464
     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
  1465
     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
  1466
     we are sitting on), a switch is forced and the process 
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1467
     will be physically destroyed by the next running process. 
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1468
     (see zombie handling)"
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
    |pri id l wasBlocked|
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1471
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1472
    aProcess isNil ifTrue:[^ self].
807
e51ce11ca948 and dont allow quickTerminate as well.
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
  1473
    aProcess == scheduler ifTrue:[
1679
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  1474
        InvalidProcessSignal raiseWith:aProcess errorString:'PROCESSOR: I will not terminate scheduler'.
1618
9fb4ee952e89 use nil for empty lists
Claus Gittinger <cg@exept.de>
parents: 1606
diff changeset
  1475
        ^ self
807
e51ce11ca948 and dont allow quickTerminate as well.
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
  1476
    ].
e51ce11ca948 and dont allow quickTerminate as well.
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
  1477
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1478
    id := aProcess id.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1479
    id isNil ifTrue:[^ self].   "already dead"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1480
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1481
    aProcess setId:nil state:#dead.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1482
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1483
    wasBlocked := OperatingSystem blockInterrupts.
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
    "remove the process from the runnable list"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1486
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1487
    pri := aProcess priority.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1488
    l := quiescentProcessLists at:pri.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1489
    (l identityIndexOf:aProcess) ~~ 0 ifTrue:[
1618
9fb4ee952e89 use nil for empty lists
Claus Gittinger <cg@exept.de>
parents: 1606
diff changeset
  1490
        l remove:aProcess.
9fb4ee952e89 use nil for empty lists
Claus Gittinger <cg@exept.de>
parents: 1606
diff changeset
  1491
        l isEmpty ifTrue:[
9fb4ee952e89 use nil for empty lists
Claus Gittinger <cg@exept.de>
parents: 1606
diff changeset
  1492
            quiescentProcessLists at:pri put:nil
9fb4ee952e89 use nil for empty lists
Claus Gittinger <cg@exept.de>
parents: 1606
diff changeset
  1493
        ]
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1494
    ].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1495
    wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
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
    aProcess == activeProcess ifTrue:[
1618
9fb4ee952e89 use nil for empty lists
Claus Gittinger <cg@exept.de>
parents: 1606
diff changeset
  1498
        "
9fb4ee952e89 use nil for empty lists
Claus Gittinger <cg@exept.de>
parents: 1606
diff changeset
  1499
         hard case - its the currently running process
9fb4ee952e89 use nil for empty lists
Claus Gittinger <cg@exept.de>
parents: 1606
diff changeset
  1500
         we must have the next active process destroy this one
9fb4ee952e89 use nil for empty lists
Claus Gittinger <cg@exept.de>
parents: 1606
diff changeset
  1501
         (we cannot destroy the chair we are sitting on ... :-)
9fb4ee952e89 use nil for empty lists
Claus Gittinger <cg@exept.de>
parents: 1606
diff changeset
  1502
        "
9fb4ee952e89 use nil for empty lists
Claus Gittinger <cg@exept.de>
parents: 1606
diff changeset
  1503
        zombie := id.
9fb4ee952e89 use nil for empty lists
Claus Gittinger <cg@exept.de>
parents: 1606
diff changeset
  1504
        self unRemember:aProcess.
9fb4ee952e89 use nil for empty lists
Claus Gittinger <cg@exept.de>
parents: 1606
diff changeset
  1505
        self threadSwitch:scheduler.
9fb4ee952e89 use nil for empty lists
Claus Gittinger <cg@exept.de>
parents: 1606
diff changeset
  1506
        "not reached"
9fb4ee952e89 use nil for empty lists
Claus Gittinger <cg@exept.de>
parents: 1606
diff changeset
  1507
        ^ self
699
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
    self class threadDestroy:id.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1510
    self unRemember:aProcess.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1511
    ^ self
1618
9fb4ee952e89 use nil for empty lists
Claus Gittinger <cg@exept.de>
parents: 1606
diff changeset
  1512
9fb4ee952e89 use nil for empty lists
Claus Gittinger <cg@exept.de>
parents: 1606
diff changeset
  1513
    "Modified: 29.7.1996 / 11:56:08 / cg"
1679
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  1514
    "Modified: 23.9.1996 / 13:50:24 / stefan"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1515
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1516
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1517
yield
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1518
    "move the currently running process to the end of the currentList
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1519
     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
  1520
     next same-prio-process."
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1521
1618
9fb4ee952e89 use nil for empty lists
Claus Gittinger <cg@exept.de>
parents: 1606
diff changeset
  1522
    |l sz wasBlocked|
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1523
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1524
    wasBlocked := OperatingSystem blockInterrupts.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1525
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1526
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1527
     debugging consistency check - will be removed later
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
    activeProcess priority ~~ currentPriority ifTrue:[
1679
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  1530
	'PROCESSOR: oops - process changed priority' errorPrintNL.
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  1531
	currentPriority := activeProcess priority.
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1532
    ].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1533
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1534
    l := quiescentProcessLists at:currentPriority.
1618
9fb4ee952e89 use nil for empty lists
Claus Gittinger <cg@exept.de>
parents: 1606
diff changeset
  1535
    sz := l size.
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1536
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1537
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1538
     debugging consistency checks - will be removed later
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1539
    "
1618
9fb4ee952e89 use nil for empty lists
Claus Gittinger <cg@exept.de>
parents: 1606
diff changeset
  1540
    sz == 0 ifTrue:[
1679
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  1541
	wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  1542
	'PROCESSOR: oops - empty runnable list' errorPrintNL.
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  1543
	^ self
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
    "
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1547
     check if the running process is not the only one
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1548
    "
1618
9fb4ee952e89 use nil for empty lists
Claus Gittinger <cg@exept.de>
parents: 1606
diff changeset
  1549
    sz ~~ 1 ifTrue:[
1679
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  1550
	"
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  1551
	 bring running process to the end
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  1552
	"
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  1553
	l removeFirst.
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  1554
	l addLast:activeProcess.
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1555
1679
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  1556
	"
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  1557
	 and switch to first in the list
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  1558
	"
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  1559
	self threadSwitch:(l first).
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1560
    ].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1561
    wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
1086
7b0641a2e1ef nicer message
Claus Gittinger <cg@exept.de>
parents: 1061
diff changeset
  1562
1618
9fb4ee952e89 use nil for empty lists
Claus Gittinger <cg@exept.de>
parents: 1606
diff changeset
  1563
    "Modified: 29.7.1996 / 11:55:53 / cg"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1564
! !
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1565
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1566
!ProcessorScheduler methodsFor:'semaphore signalling'!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1567
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1568
disableSemaphore:aSemaphore
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1569
    "disable triggering of a semaphore"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1570
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1571
    |idx "{ Class: SmallInteger }"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1572
     wasBlocked|
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1573
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1574
    wasBlocked := OperatingSystem blockInterrupts.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1575
    idx := readSemaphoreArray identityIndexOf:aSemaphore startingAt:1.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1576
    [idx ~~ 0] whileTrue:[
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1577
	readFdArray at:idx put:nil.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1578
	readSemaphoreArray at:idx put:nil.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1579
	readCheckArray at:idx put:nil.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1580
	idx := readSemaphoreArray identityIndexOf:aSemaphore startingAt:idx.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1581
    ].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1582
    idx := writeSemaphoreArray identityIndexOf:aSemaphore startingAt:1.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1583
    [idx ~~ 0] whileTrue:[
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1584
	writeFdArray at:idx put:nil.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1585
	writeSemaphoreArray at:idx put:nil.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1586
	idx := writeSemaphoreArray identityIndexOf:aSemaphore startingAt:idx.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1587
    ].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1588
    idx := timeoutSemaphoreArray identityIndexOf:aSemaphore startingAt:1.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1589
    [idx ~~ 0] whileTrue:[
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1590
	timeoutArray at:idx put:nil.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1591
	timeoutSemaphoreArray at:idx put:nil.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1592
	timeoutActionArray at:idx put:nil.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1593
	timeoutProcessArray at:idx put:nil.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1594
	idx := timeoutSemaphoreArray identityIndexOf:aSemaphore startingAt:idx.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1595
    ].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1596
    wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1597
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1598
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1599
signal:aSemaphore afterMilliseconds:millis
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1600
    "arrange for a semaphore to be triggered after some milliseconds"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1601
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1602
    |now then wasBlocked|
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1603
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1604
    wasBlocked := OperatingSystem blockInterrupts.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1605
    now := OperatingSystem getMillisecondTime.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1606
    then := OperatingSystem millisecondTimeAdd:now and:millis rounded.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1607
    self signal:aSemaphore atMilliseconds:then.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1608
    wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1609
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1610
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1611
signal:aSemaphore afterSeconds:seconds
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1612
    "arrange for a semaphore to be triggered after some seconds"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1613
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1614
    self signal:aSemaphore afterMilliseconds:(seconds * 1000)
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1615
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1616
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1617
signal:aSemaphore atMilliseconds:aMillisecondTime
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1618
    "arrange for a semaphore to be triggered at a specific millisecond time.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1619
     If there is already a pending trigger time, the time is changed."
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1620
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1621
    |index "{ Class: SmallInteger }"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1622
     wasBlocked|
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1623
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1624
    wasBlocked := OperatingSystem blockInterrupts.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1625
    index := timeoutSemaphoreArray identityIndexOf:aSemaphore startingAt:1.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1626
    index ~~ 0 ifTrue:[
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1627
	timeoutArray at:index put:aMillisecondTime
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1628
    ] ifFalse:[
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1629
	index := timeoutArray identityIndexOf:nil startingAt:1.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1630
	index ~~ 0 ifTrue:[
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1631
	    timeoutSemaphoreArray at:index put:aSemaphore.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1632
	    timeoutArray at:index put:aMillisecondTime.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1633
	    timeoutActionArray at:index put:nil.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1634
	    timeoutProcessArray at:index put:nil 
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1635
	] ifFalse:[
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1636
	    timeoutSemaphoreArray := timeoutSemaphoreArray copyWith:aSemaphore.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1637
	    timeoutArray := timeoutArray copyWith:aMillisecondTime.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1638
	    timeoutActionArray := timeoutActionArray copyWith:nil.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1639
	    timeoutProcessArray := timeoutProcessArray copyWith:nil 
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1640
	].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1641
    ].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1642
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1643
    anyTimeouts := true.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1644
    wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1645
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1646
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1647
signal:aSemaphore onInput:aFileDescriptor
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1648
    "arrange for a semaphore to be triggered when input on aFileDescriptor
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1649
     arrives."
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1650
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1651
    self signal:aSemaphore onInput:aFileDescriptor orCheck:nil
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1652
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1653
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1654
signal:aSemaphore onInput:aFileDescriptor orCheck:aBlock
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1655
    "arrange for a semaphore to be triggered when input on aFileDescriptor
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1656
     arrives OR checkblock evaluates to true. 
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1657
     (checkBlock is used for buffered input, where a select may not detect 
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1658
      data already read into a buffer - as in Xlib)"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1659
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1660
    |idx "{ Class: SmallInteger }"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1661
     wasBlocked|
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1662
1627
f95285226059 infoPrint for NT (no select)
Claus Gittinger <cg@exept.de>
parents: 1618
diff changeset
  1663
    aFileDescriptor isNil ifTrue:[
f95285226059 infoPrint for NT (no select)
Claus Gittinger <cg@exept.de>
parents: 1618
diff changeset
  1664
	'PROCESSOR: no fd to select on - polling with checkBlock' infoPrintCR
f95285226059 infoPrint for NT (no select)
Claus Gittinger <cg@exept.de>
parents: 1618
diff changeset
  1665
    ].
f95285226059 infoPrint for NT (no select)
Claus Gittinger <cg@exept.de>
parents: 1618
diff changeset
  1666
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1667
    wasBlocked := OperatingSystem blockInterrupts.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1668
    (readFdArray identityIndexOf:aFileDescriptor startingAt:1) == 0 ifTrue:[
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1669
	idx := readFdArray identityIndexOf:nil startingAt:1.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1670
	idx ~~ 0 ifTrue:[
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1671
	    readFdArray at:idx put:aFileDescriptor.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1672
	    readSemaphoreArray at:idx put:aSemaphore.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1673
	    readCheckArray at:idx put:aBlock
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1674
	] ifFalse:[
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1675
	    readFdArray := readFdArray copyWith:aFileDescriptor.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1676
	    readSemaphoreArray := readSemaphoreArray copyWith:aSemaphore.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1677
	    readCheckArray := readCheckArray copyWith:aBlock.
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
    ].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1680
    wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1681
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1682
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1683
signal:aSemaphore onOutput:aFileDescriptor
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1684
    "arrange for a semaphore to be triggered when output on aFileDescriptor
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1685
     is possible. (i.e. can be written without blocking)"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1686
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1687
    |idx "{ Class: SmallInteger }"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1688
     wasBlocked|
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1689
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1690
    wasBlocked := OperatingSystem blockInterrupts.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1691
    (writeFdArray identityIndexOf:aFileDescriptor startingAt:1) == 0 ifTrue:[
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1692
	idx := writeFdArray identityIndexOf:nil startingAt:1.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1693
	idx ~~ 0 ifTrue:[
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1694
	    writeFdArray at:idx put:aFileDescriptor.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1695
	    writeSemaphoreArray at:idx put:aSemaphore.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1696
	] ifFalse:[
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1697
	    writeFdArray := writeFdArray copyWith:aFileDescriptor.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1698
	    writeSemaphoreArray := writeSemaphoreArray copyWith:aSemaphore.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1699
	]
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1700
    ].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1701
    wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1702
! !
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1703
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1704
!ProcessorScheduler methodsFor:'timeout handling'!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1705
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1706
addTimedBlock:aBlock afterMilliseconds:delta
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1707
    "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
  1708
     evaluated after delta milliseconds. The process which installs this timed 
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1709
     block will be interrupted for execution of the block.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1710
     (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
  1711
      executing; if it is suspended, it will be resumed).
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1712
     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
  1713
     (i.e. it will trigger only once).
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  1714
     Returns an ID, which can be used in #removeTimeoutWidthID:"
699
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
    ^ self addTimedBlock:aBlock for:activeProcess afterMilliseconds:delta
1676
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  1717
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  1718
    "Modified: 23.9.1996 / 14:33:59 / cg"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1719
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1720
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1721
addTimedBlock:aBlock afterSeconds:delta
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1722
    "add the argument, aBlock to the list of time-scheduled-blocks.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1723
     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
  1724
     block will be interrupted for execution of the block.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1725
     (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
  1726
      executing; if it is suspended, it will be resumed).
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1727
     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
  1728
     (i.e. it will trigger only once).
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  1729
     Returns an ID, which can be used in #removeTimeoutWidthID:"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1730
1676
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  1731
    ^ self addTimedBlock:aBlock for:activeProcess afterMilliseconds:(delta * 1000) rounded
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  1732
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  1733
    "Modified: 23.9.1996 / 14:34:04 / cg"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1734
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1735
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1736
addTimedBlock:aBlock atMilliseconds:aMillisecondTime
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1737
    "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
  1738
     evaluated when the millisecondClock value passes aMillisecondTime.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1739
     The process which installs this timed block will be interrupted for 
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1740
     execution of the block.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1741
     (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
  1742
      executing; if it is suspended, it will be resumed).
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1743
     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
  1744
     (i.e. it will trigger only once).     
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  1745
     Returns an ID, which can be used in #removeTimeoutWidthID:"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1746
1676
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  1747
    ^ self addTimedBlock:aBlock for:activeProcess atMilliseconds:aMillisecondTime
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  1748
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  1749
    "Modified: 23.9.1996 / 14:34:09 / cg"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1750
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1751
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1752
addTimedBlock:aBlock for:aProcess afterMilliseconds:delta
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1753
    "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
  1754
     evaluated after delta milliseconds. The process specified by the argument,
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1755
     aProcess will be interrupted for execution of the block. 
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1756
     (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
  1757
      executing; if it is suspended, it will be resumed).
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1758
     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
  1759
     (which is dangerous - the block should not raise any error conditions).
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1760
     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
  1761
     (i.e. it will trigger only once).
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  1762
     Returns an ID, which can be used in #removeTimeoutWidthID:"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1763
1676
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  1764
    |now then wasBlocked id|
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1765
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1766
    wasBlocked := OperatingSystem blockInterrupts.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1767
    now := OperatingSystem getMillisecondTime.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1768
    then := OperatingSystem millisecondTimeAdd:now and:delta.
1676
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  1769
    id := self addTimedBlock:aBlock for:aProcess atMilliseconds:then.
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1770
    wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
1676
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  1771
    ^ id
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  1772
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  1773
    "Modified: 23.9.1996 / 14:34:13 / cg"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1774
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1775
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1776
addTimedBlock:aBlock for:aProcess afterSeconds:delta
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1777
    "add the argument, aBlock to the list of time-scheduled-blocks.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1778
     to be evaluated after delta seconds. aProcess will be interrupted for 
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1779
     execution of the block.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1780
     (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
  1781
      executing; if it is suspended, it will be resumed).
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1782
     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
  1783
     (which is dangerous - the block should not raise any error conditions).
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1784
     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
  1785
     (i.e. it will trigger only once).
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  1786
     Returns an ID, which can be used in #removeTimeoutWidthID:"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1787
1676
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  1788
    ^ self addTimedBlock:aBlock for:aProcess afterMilliseconds:(delta * 1000) rounded
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  1789
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  1790
    "Modified: 23.9.1996 / 14:34:18 / cg"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1791
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1792
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1793
addTimedBlock:aBlock for:aProcess atMilliseconds:aMillisecondTime
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1794
    "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
  1795
     evaluated by aProcess when the millisecondClock value passes 
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1796
     aMillisecondTime. 
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1797
     If that block is already in the timeout list, 
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1798
     its trigger-time is changed.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1799
     The process specified by the argument, aProcess will be interrupted 
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1800
     for execution of the block. 
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1801
     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
  1802
     (which is dangerous - the block should not raise any error conditions).
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1803
     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
  1804
     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
  1805
     resumed.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1806
     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
  1807
     (i.e. it will trigger only once).    
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  1808
     Returns an ID, which can be used in #removeTimeoutWidthID:"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1809
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1810
    |index "{ Class: SmallInteger }"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1811
     wasBlocked|
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1812
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1813
    wasBlocked := OperatingSystem blockInterrupts.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1814
    index := timeoutActionArray identityIndexOf:aBlock startingAt:1.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1815
    index ~~ 0 ifTrue:[
1676
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  1816
        timeoutArray at:index put:aMillisecondTime
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1817
    ] ifFalse:[
1676
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  1818
        index := timeoutArray indexOf:nil.
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  1819
        index ~~ 0 ifTrue:[
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  1820
            timeoutArray at:index put:aMillisecondTime.
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  1821
            timeoutActionArray at:index put:aBlock.
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  1822
            timeoutSemaphoreArray at:index put:nil. 
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  1823
            timeoutProcessArray at:index put:aProcess 
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  1824
        ] ifFalse:[
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  1825
            timeoutArray := timeoutArray copyWith:aMillisecondTime.
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  1826
            timeoutActionArray := timeoutActionArray copyWith:aBlock.
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  1827
            timeoutSemaphoreArray := timeoutSemaphoreArray copyWith:nil.
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  1828
            timeoutProcessArray := timeoutProcessArray copyWith:aProcess.
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  1829
            index := timeoutArray size.
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  1830
        ].
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1831
    ].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1832
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1833
    anyTimeouts := true.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1834
    wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
1676
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  1835
    ^ index
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  1836
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  1837
    "Modified: 23.9.1996 / 14:34:23 / cg"
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  1838
!
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  1839
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  1840
addTimeoutFunctionCall:anExternalFunction for:aProcess afterMilliseconds:delta with:argument
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  1841
    "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
  1842
     after some millisecond-Delay.
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  1843
     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
  1844
     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
  1845
     in this processes context.
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  1846
     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
  1847
     (i.e. it will trigger only once).
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  1848
     Returns an ID, which can be used in #removeTimeoutWidthID:"
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  1849
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  1850
    |now then wasBlocked id|
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  1851
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  1852
    wasBlocked := OperatingSystem blockInterrupts.
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  1853
    now := OperatingSystem getMillisecondTime.
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  1854
    then := OperatingSystem millisecondTimeAdd:now and:delta.
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  1855
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  1856
    id := self
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  1857
        addTimeoutFunctionCall:anExternalFunction 
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  1858
        for:aProcess 
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  1859
        atMilliseconds:delta 
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  1860
        with:argument.
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  1861
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  1862
    wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  1863
    ^ id
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  1864
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  1865
    "Created: 23.9.1996 / 14:28:27 / cg"
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  1866
    "Modified: 23.9.1996 / 14:34:42 / cg"
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  1867
!
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  1868
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  1869
addTimeoutFunctionCall:anExternalFunction for:aProcess atMilliseconds:delta with:argument
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  1870
    "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
  1871
     at some millisecond-time.
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  1872
     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
  1873
     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
  1874
     in this processes context.
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  1875
     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
  1876
     (i.e. it will trigger only once).
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  1877
     Returns an ID, which can be used in #removeTimeoutWidthID:"
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  1878
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  1879
    |action|
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  1880
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  1881
    action := [anExternalFunction callWith:argument].
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  1882
    ^ self
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  1883
        addTimedBlock:action 
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  1884
        for:aProcess 
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  1885
        atMilliseconds:delta.
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  1886
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  1887
    "Created: 23.9.1996 / 14:29:30 / cg"
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  1888
    "Modified: 23.9.1996 / 14:34:57 / cg"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1889
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1890
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1891
evaluateTimeouts
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1892
    "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
  1893
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1894
    |sema now aTime block blocksToEvaluate 
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1895
     processes n "{ Class: SmallInteger }"|
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1896
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1897
    anyTimeouts ifFalse:[ ^ self].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1898
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1899
    "have to collect the blocks first, then evaluate them. This avoids
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1900
     problems due to newly inserted blocks."
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1901
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1902
    now := OperatingSystem getMillisecondTime.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1903
    blocksToEvaluate := nil.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1904
    n := timeoutArray size.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1905
    anyTimeouts := false.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1906
    1 to:n do:[:index |
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1907
	aTime := timeoutArray at:index.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1908
	aTime notNil ifTrue:[
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1909
	    (OperatingSystem millisecondTime:aTime isAfter:now) ifFalse:[
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1910
		"this one should be triggered"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1911
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1912
		sema := timeoutSemaphoreArray at:index.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1913
		sema notNil ifTrue:[
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1914
		    sema signalOnce.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1915
		    timeoutSemaphoreArray at:index put:nil
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1916
		] ifFalse:[
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1917
		    "to support pure-events"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1918
		    block := timeoutActionArray at:index.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1919
		    block notNil ifTrue:[
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1920
			blocksToEvaluate isNil ifTrue:[
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1921
			    blocksToEvaluate := OrderedCollection new:10.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1922
			    processes := OrderedCollection new:10.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1923
			].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1924
			blocksToEvaluate add:block.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1925
			processes add:(timeoutProcessArray at:index).
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1926
			timeoutActionArray at:index put:nil.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1927
			timeoutProcessArray at:index put:nil.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1928
		    ]
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1929
		].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1930
		timeoutArray at:index put:nil.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1931
	    ] ifTrue:[
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1932
		anyTimeouts := true
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1933
	    ]
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1934
	]
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1935
    ].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1936
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1937
    blocksToEvaluate notNil ifTrue:[
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1938
	blocksToEvaluate keysAndValuesDo:[:index :block |
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1939
	    |p|
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1940
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1941
	    p := processes at:index.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1942
	    (p isNil or:[p == scheduler or:[PureEventDriven]]) ifTrue:[
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1943
		block value
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1944
	    ] ifFalse:[
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1945
		p interruptWith:block
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1946
	    ]
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1947
	]
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1948
    ]
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1949
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1950
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1951
removeTimedBlock:aBlock
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1952
    "remove the argument, aBlock from the list of time-sceduled-blocks."
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
    |index "{ Class: SmallInteger }"
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1955
     wasBlocked|
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1956
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1957
    wasBlocked := OperatingSystem blockInterrupts.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1958
    index := timeoutActionArray identityIndexOf:aBlock startingAt:1.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1959
    (index ~~ 0) ifTrue:[
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1960
	timeoutArray at:index put:nil.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1961
	timeoutActionArray at:index put:nil. 
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1962
	timeoutSemaphoreArray at:index put:nil.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1963
	timeoutProcessArray at:index put:nil.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1964
    ].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1965
    wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
1676
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  1966
!
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  1967
1680
b90690d9d6c5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1679
diff changeset
  1968
removeTimeoutWithID:anID
1676
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  1969
    "remove the timeOut with anID (as returned by #addTimedBlock)
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  1970
     from the list of time-sceduled-blocks."
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  1971
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  1972
    |index "{ Class: SmallInteger }"
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  1973
     wasBlocked|
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  1974
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  1975
    index := anID.
1680
b90690d9d6c5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1679
diff changeset
  1976
    (index > 0) ifTrue:[
b90690d9d6c5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1679
diff changeset
  1977
        wasBlocked := OperatingSystem blockInterrupts.
b90690d9d6c5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1679
diff changeset
  1978
1676
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  1979
        timeoutArray at:index put:nil.
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  1980
        timeoutActionArray at:index put:nil. 
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  1981
        timeoutSemaphoreArray at:index put:nil.
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  1982
        timeoutProcessArray at:index put:nil.
1680
b90690d9d6c5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1679
diff changeset
  1983
b90690d9d6c5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1679
diff changeset
  1984
        wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
b90690d9d6c5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1679
diff changeset
  1985
    ]
1676
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  1986
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  1987
    "Created: 23.9.1996 / 14:32:33 / cg"
12b3b5dcf68f return an id from #addTimeout:
Claus Gittinger <cg@exept.de>
parents: 1641
diff changeset
  1988
    "Modified: 23.9.1996 / 14:35:09 / cg"
10
claus
parents: 3
diff changeset
  1989
! !
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1990
10
claus
parents: 3
diff changeset
  1991
!ProcessorScheduler methodsFor:'waiting'!
claus
parents: 3
diff changeset
  1992
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1993
checkForInputWithTimeout:millis
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1994
    "this is called, when there is absolutely nothing to do;
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1995
     hard wait for either input to arrive or a timeout to occur."
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1996
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1997
    |fd index sema action|
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1998
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  1999
    fd := OperatingSystem 
1679
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  2000
	      selectOnAnyReadable:readFdArray 
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  2001
			 writable:writeFdArray
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  2002
			exception:nil 
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  2003
		      withTimeOut:millis.
1061
61012b7bed9c protect myself against invalid fd's in readFdArray/writeFdArray
Claus Gittinger <cg@exept.de>
parents: 1042
diff changeset
  2004
61012b7bed9c protect myself against invalid fd's in readFdArray/writeFdArray
Claus Gittinger <cg@exept.de>
parents: 1042
diff changeset
  2005
    fd isNil ifTrue:[
1679
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  2006
	(OperatingSystem lastErrorSymbol == #EBADF) ifTrue:[
1061
61012b7bed9c protect myself against invalid fd's in readFdArray/writeFdArray
Claus Gittinger <cg@exept.de>
parents: 1042
diff changeset
  2007
1679
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  2008
	    "/ mhmh - one of the fd's given to me is corrupt.
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  2009
	    "/ find out which one .... and remove it
1061
61012b7bed9c protect myself against invalid fd's in readFdArray/writeFdArray
Claus Gittinger <cg@exept.de>
parents: 1042
diff changeset
  2010
1679
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  2011
	    OperatingSystem clearLastErrorNumber.
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  2012
	    self removeCorruptedFds
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  2013
	]
1061
61012b7bed9c protect myself against invalid fd's in readFdArray/writeFdArray
Claus Gittinger <cg@exept.de>
parents: 1042
diff changeset
  2014
    ] ifFalse:[
1679
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  2015
	index := readFdArray indexOf:fd.
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  2016
	index ~~ 0 ifTrue:[
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  2017
	    sema := readSemaphoreArray at:index.
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  2018
	    sema notNil ifTrue:[
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  2019
		sema signalOnce.
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  2020
		^ true
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  2021
	    ] ifFalse:[
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  2022
		action := readCheckArray at:index.
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  2023
		action notNil ifTrue:[
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  2024
		    action value.
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  2025
		     ^ true
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  2026
		]
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  2027
	    ]
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  2028
	]
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2029
    ].
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2030
    ^ false
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
  2031
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
  2032
    "Modified: 12.4.1996 / 09:31:22 / stefan"
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2033
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2034
10
claus
parents: 3
diff changeset
  2035
ioInterrupt
159
514c749165c3 *** empty log message ***
claus
parents: 144
diff changeset
  2036
    "data arrived while waiting - switch to scheduler process which will decide 
514c749165c3 *** empty log message ***
claus
parents: 144
diff changeset
  2037
     what to do now."
10
claus
parents: 3
diff changeset
  2038
804
264d440a67a0 Fixes when useIOInterrupts == true.
Stefan Vogel <sv@exept.de>
parents: 786
diff changeset
  2039
    gotIOInterrupt := true.
181
ef3ccf27e2e0 interrupted process now kept for monitor
claus
parents: 161
diff changeset
  2040
    interruptedProcess := activeProcess.
93
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
  2041
    self threadSwitch:scheduler
804
264d440a67a0 Fixes when useIOInterrupts == true.
Stefan Vogel <sv@exept.de>
parents: 786
diff changeset
  2042
264d440a67a0 Fixes when useIOInterrupts == true.
Stefan Vogel <sv@exept.de>
parents: 786
diff changeset
  2043
    "Modified: 21.12.1995 / 16:17:40 / stefan"
10
claus
parents: 3
diff changeset
  2044
!
claus
parents: 3
diff changeset
  2045
1086
7b0641a2e1ef nicer message
Claus Gittinger <cg@exept.de>
parents: 1061
diff changeset
  2046
removeCorruptedFds
7b0641a2e1ef nicer message
Claus Gittinger <cg@exept.de>
parents: 1061
diff changeset
  2047
    "this is sent when select returns an error due to some invalid 
1606
5f305da05f8b comment
Claus Gittinger <cg@exept.de>
parents: 1576
diff changeset
  2048
     fileDescriptor. May happen, if someone does a readWait/writeWait on a 
5f305da05f8b comment
Claus Gittinger <cg@exept.de>
parents: 1576
diff changeset
  2049
     socket connection, which somehow got corrupted 
5f305da05f8b comment
Claus Gittinger <cg@exept.de>
parents: 1576
diff changeset
  2050
     (shutdown by partner, or closed in another thread).
1086
7b0641a2e1ef nicer message
Claus Gittinger <cg@exept.de>
parents: 1061
diff changeset
  2051
     Without special care, all following selects would immediately return with 
7b0641a2e1ef nicer message
Claus Gittinger <cg@exept.de>
parents: 1061
diff changeset
  2052
     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
  2053
     (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
  2054
      readFdArray/writeFdArray in the debugger)"
7b0641a2e1ef nicer message
Claus Gittinger <cg@exept.de>
parents: 1061
diff changeset
  2055
7b0641a2e1ef nicer message
Claus Gittinger <cg@exept.de>
parents: 1061
diff changeset
  2056
    readFdArray keysAndValuesDo:[:idx :fd |
1679
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  2057
	|rslt sema|
1086
7b0641a2e1ef nicer message
Claus Gittinger <cg@exept.de>
parents: 1061
diff changeset
  2058
1679
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  2059
	rslt := OperatingSystem
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  2060
		    selectOnAnyReadable:(Array with:fd)
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  2061
			       writable:nil
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  2062
			      exception:nil
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  2063
			    withTimeOut:0.
1086
7b0641a2e1ef nicer message
Claus Gittinger <cg@exept.de>
parents: 1061
diff changeset
  2064
1679
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  2065
	(rslt isNil and:[OperatingSystem lastErrorSymbol == #EBADF]) ifTrue:[
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  2066
	    ('PROCESSOR: removing invalid read fileDescriptor: ' , fd printString) errorPrintNL.
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  2067
	    readFdArray at:idx put:nil.
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  2068
	    OperatingSystem clearLastErrorNumber.
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  2069
	    (sema := readSemaphoreArray at:idx) notNil ifTrue:[
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  2070
		readSemaphoreArray at:idx put:nil.
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  2071
		sema signal.
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  2072
	    ].
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  2073
	]
1086
7b0641a2e1ef nicer message
Claus Gittinger <cg@exept.de>
parents: 1061
diff changeset
  2074
    ].
7b0641a2e1ef nicer message
Claus Gittinger <cg@exept.de>
parents: 1061
diff changeset
  2075
7b0641a2e1ef nicer message
Claus Gittinger <cg@exept.de>
parents: 1061
diff changeset
  2076
    writeFdArray keysAndValuesDo:[:idx :fd |
1679
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  2077
	|rslt sema|
1086
7b0641a2e1ef nicer message
Claus Gittinger <cg@exept.de>
parents: 1061
diff changeset
  2078
1679
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  2079
	rslt := OperatingSystem
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  2080
		    selectOnAnyReadable:nil
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  2081
			       writable:(Array with:fd)
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  2082
			      exception:nil
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  2083
			    withTimeOut:0.
1086
7b0641a2e1ef nicer message
Claus Gittinger <cg@exept.de>
parents: 1061
diff changeset
  2084
1679
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  2085
	(rslt isNil and:[OperatingSystem lastErrorSymbol == #EBADF]) ifTrue:[
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  2086
	    ('PROCESSOR: removing invalid write fileDescriptor: ' , fd printString) errorPrintNL.
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  2087
	    writeFdArray at:idx put:nil.
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  2088
	    OperatingSystem clearLastErrorNumber.
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  2089
	    (sema := writeSemaphoreArray at:idx) notNil ifTrue:[
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  2090
		writeSemaphoreArray at:idx put:nil.
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  2091
		sema signal.
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  2092
	    ].
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  2093
	]
1086
7b0641a2e1ef nicer message
Claus Gittinger <cg@exept.de>
parents: 1061
diff changeset
  2094
    ].
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
  2095
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
  2096
    "Modified: 12.4.1996 / 09:32:58 / stefan"
1641
4adf4b8dad17 wakup readWaiters in case of errors
Claus Gittinger <cg@exept.de>
parents: 1627
diff changeset
  2097
    "Modified: 29.8.1996 / 22:42:28 / cg"
1086
7b0641a2e1ef nicer message
Claus Gittinger <cg@exept.de>
parents: 1061
diff changeset
  2098
!
7b0641a2e1ef nicer message
Claus Gittinger <cg@exept.de>
parents: 1061
diff changeset
  2099
750
f4ed622893ce added schedulerInterrupt - for soon to come semaSignal primitive function
Claus Gittinger <cg@exept.de>
parents: 699
diff changeset
  2100
schedulerInterrupt
f4ed622893ce added schedulerInterrupt - for soon to come semaSignal primitive function
Claus Gittinger <cg@exept.de>
parents: 699
diff changeset
  2101
    "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
  2102
     what to do now."
f4ed622893ce added schedulerInterrupt - for soon to come semaSignal primitive function
Claus Gittinger <cg@exept.de>
parents: 699
diff changeset
  2103
f4ed622893ce added schedulerInterrupt - for soon to come semaSignal primitive function
Claus Gittinger <cg@exept.de>
parents: 699
diff changeset
  2104
    interruptedProcess := activeProcess.
f4ed622893ce added schedulerInterrupt - for soon to come semaSignal primitive function
Claus Gittinger <cg@exept.de>
parents: 699
diff changeset
  2105
    self threadSwitch:scheduler
f4ed622893ce added schedulerInterrupt - for soon to come semaSignal primitive function
Claus Gittinger <cg@exept.de>
parents: 699
diff changeset
  2106
!
f4ed622893ce added schedulerInterrupt - for soon to come semaSignal primitive function
Claus Gittinger <cg@exept.de>
parents: 699
diff changeset
  2107
10
claus
parents: 3
diff changeset
  2108
timeToNextTimeout
claus
parents: 3
diff changeset
  2109
    "return the delta-T (in millis) to next timeout, or nil if
claus
parents: 3
diff changeset
  2110
     there is none"
claus
parents: 3
diff changeset
  2111
231
fd0e55e352f8 cleanup
claus
parents: 217
diff changeset
  2112
    |aTime now delta minDelta n "{ Class: SmallInteger }"|
10
claus
parents: 3
diff changeset
  2113
claus
parents: 3
diff changeset
  2114
    "find next timeout. since there are usually not many, just search.
302
1f76060d58a4 *** empty log message ***
claus
parents: 271
diff changeset
  2115
     If there were many, the list should be kept sorted ... keeping deltas
10
claus
parents: 3
diff changeset
  2116
     to next (as in Unix kernel)"
claus
parents: 3
diff changeset
  2117
231
fd0e55e352f8 cleanup
claus
parents: 217
diff changeset
  2118
    n := timeoutArray size.
10
claus
parents: 3
diff changeset
  2119
    1 to:n do:[:index |
231
fd0e55e352f8 cleanup
claus
parents: 217
diff changeset
  2120
	aTime := timeoutArray at:index.
159
514c749165c3 *** empty log message ***
claus
parents: 144
diff changeset
  2121
	aTime notNil ifTrue:[
231
fd0e55e352f8 cleanup
claus
parents: 217
diff changeset
  2122
	    now isNil ifTrue:[
159
514c749165c3 *** empty log message ***
claus
parents: 144
diff changeset
  2123
		now := OperatingSystem getMillisecondTime.
231
fd0e55e352f8 cleanup
claus
parents: 217
diff changeset
  2124
	    ].
fd0e55e352f8 cleanup
claus
parents: 217
diff changeset
  2125
	    (OperatingSystem millisecondTime:aTime isAfter:now) ifFalse:[^ 0].
fd0e55e352f8 cleanup
claus
parents: 217
diff changeset
  2126
	    delta := OperatingSystem millisecondTimeDeltaBetween:aTime and:now.
fd0e55e352f8 cleanup
claus
parents: 217
diff changeset
  2127
	    minDelta isNil ifTrue:[
fd0e55e352f8 cleanup
claus
parents: 217
diff changeset
  2128
		minDelta := delta
159
514c749165c3 *** empty log message ***
claus
parents: 144
diff changeset
  2129
	    ] ifFalse:[
231
fd0e55e352f8 cleanup
claus
parents: 217
diff changeset
  2130
		minDelta := minDelta min:delta
159
514c749165c3 *** empty log message ***
claus
parents: 144
diff changeset
  2131
	    ]
514c749165c3 *** empty log message ***
claus
parents: 144
diff changeset
  2132
	]
10
claus
parents: 3
diff changeset
  2133
    ].
claus
parents: 3
diff changeset
  2134
claus
parents: 3
diff changeset
  2135
    ^ minDelta
claus
parents: 3
diff changeset
  2136
!
claus
parents: 3
diff changeset
  2137
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2138
timerInterrupt
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2139
    "timer expired while waiting - switch to scheduler process which will decide 
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2140
     what to do now."
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2141
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2142
    interruptedProcess := activeProcess.
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2143
    self threadSwitch:scheduler
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2144
!
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2145
10
claus
parents: 3
diff changeset
  2146
waitForEventOrTimeout
44
b262907c93ea *** empty log message ***
claus
parents: 42
diff changeset
  2147
    "entered when no process is runnable - wait for either input on
b262907c93ea *** empty log message ***
claus
parents: 42
diff changeset
  2148
     any file descriptors to arrive or a timeout to happen.
b262907c93ea *** empty log message ***
claus
parents: 42
diff changeset
  2149
     If it makes sense, do some background garbage collection.
b262907c93ea *** empty log message ***
claus
parents: 42
diff changeset
  2150
     The idle actions are a leftover from previous ST/X releases and will
93
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
  2151
     vanish (installing a low-prio process has the same effect)."
44
b262907c93ea *** empty log message ***
claus
parents: 42
diff changeset
  2152
1575
72fe308c1ba0 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1574
diff changeset
  2153
    |millis doingGC anySema|
10
claus
parents: 3
diff changeset
  2154
claus
parents: 3
diff changeset
  2155
    doingGC := true.
claus
parents: 3
diff changeset
  2156
    [doingGC] whileTrue:[
1679
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  2157
	anyTimeouts ifTrue:[
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  2158
	    millis := self timeToNextTimeout.
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  2159
	    (millis notNil and:[millis <= 0]) ifTrue:[
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  2160
		^ self    "oops - hurry up checking"
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  2161
	    ].
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  2162
	].
10
claus
parents: 3
diff changeset
  2163
1679
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  2164
	"
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  2165
	 if its worth doing, collect a bit of garbage;
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  2166
	 but not, if a backgroundCollector is active
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  2167
	"
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  2168
	ObjectMemory backgroundCollectorRunning ifTrue:[
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  2169
	    doingGC := false
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  2170
	] ifFalse:[
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  2171
	    doingGC := ObjectMemory gcStepIfUseful.
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  2172
	].
10
claus
parents: 3
diff changeset
  2173
1679
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  2174
	"then do idle actions"
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  2175
	(idleActions notNil and:[idleActions size ~~ 0]) ifTrue:[
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  2176
	    idleActions do:[:aBlock |
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  2177
		aBlock value.
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  2178
	    ].
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  2179
	    ^ self   "go back checking"
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  2180
	].
10
claus
parents: 3
diff changeset
  2181
1679
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  2182
	doingGC ifTrue:[
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  2183
	    (self checkForInputWithTimeout:0) ifTrue:[
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  2184
		^ self  "go back checking"
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  2185
	    ]
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  2186
	]
10
claus
parents: 3
diff changeset
  2187
    ].
claus
parents: 3
diff changeset
  2188
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
  2189
    exitWhenNoMoreUserProcesses ifTrue:[
1679
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  2190
	"/ check if there are any processes at all
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  2191
	"/ stop dispatching if there is none
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  2192
	"/ (and millis is nil, which means that no timeout blocks are present)
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  2193
	"/ and no readSemaphores are present (which means that noone is waiting for input)
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  2194
	"/ and no writeSemaphores are present
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
  2195
1679
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  2196
	anySema := false.
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  2197
	anySema := (readSemaphoreArray findFirst:[:sema | sema notNil]) ~~ 0.
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  2198
	anySema ifFalse:[
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  2199
	    anySema := (writeSemaphoreArray findFirst:[:sema | sema notNil]) ~~ 0.
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  2200
	].
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  2201
	anySema ifFalse:[
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  2202
	    self anyUserProcessAtAll ifFalse:[
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  2203
		dispatching := false.
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  2204
		^ self
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  2205
	    ]
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  2206
	].
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
  2207
    ].
10
claus
parents: 3
diff changeset
  2208
1627
f95285226059 infoPrint for NT (no select)
Claus Gittinger <cg@exept.de>
parents: 1618
diff changeset
  2209
    "/
f95285226059 infoPrint for NT (no select)
Claus Gittinger <cg@exept.de>
parents: 1618
diff changeset
  2210
    "/ absolutely nothing to do - simply wait
f95285226059 infoPrint for NT (no select)
Claus Gittinger <cg@exept.de>
parents: 1618
diff changeset
  2211
    "/
49
f1c2d75f2eb6 *** empty log message ***
claus
parents: 44
diff changeset
  2212
    OperatingSystem supportsSelect ifFalse:[
1679
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  2213
	"SCO instant ShitStation has a bug here,
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  2214
	 waiting always 1 sec in the select - therefore we delay a bit and
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  2215
	 return - effectively polling in 50ms cycles
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  2216
	"
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  2217
	(self checkForInputWithTimeout:0) ifTrue:[
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  2218
	    ^ self  "go back checking"
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  2219
	].
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  2220
	OperatingSystem millisecondDelay:50.
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  2221
	^ self
10
claus
parents: 3
diff changeset
  2222
    ].
claus
parents: 3
diff changeset
  2223
claus
parents: 3
diff changeset
  2224
    millis isNil ifTrue:[
1679
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  2225
	millis := 9999.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2226
    ] ifFalse:[
1679
dbbfbd78b1e4 Allow scheduler to suspend/resume itself. This makes semaphores work
Stefan Vogel <sv@exept.de>
parents: 1676
diff changeset
  2227
	millis := millis rounded
10
claus
parents: 3
diff changeset
  2228
    ].
claus
parents: 3
diff changeset
  2229
    self checkForInputWithTimeout:millis
768
20434b8239f3 stefans modalBox changes (no more polling)
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  2230
20434b8239f3 stefans modalBox changes (no more polling)
Claus Gittinger <cg@exept.de>
parents: 759
diff changeset
  2231
    "Modified: 14.12.1995 / 13:37:46 / stefan"
1576
3f6c39471342 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1575
diff changeset
  2232
    "Modified: 18.7.1996 / 20:42:17 / cg"
10
claus
parents: 3
diff changeset
  2233
! !
claus
parents: 3
diff changeset
  2234
1571
8d00e6b97ca7 changed #anyUserProcessAtAll,
Claus Gittinger <cg@exept.de>
parents: 1473
diff changeset
  2235
!ProcessorScheduler  class methodsFor:'documentation'!
10
claus
parents: 3
diff changeset
  2236
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2237
version
1680
b90690d9d6c5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1679
diff changeset
  2238
    ^ '$Header: /cvs/stx/stx/libbasic/Attic/ProcSched.st,v 1.92 1996-09-23 13:54:30 cg Exp $'
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2239
! !
699
12f456343eea checkin from browser
Claus Gittinger <cg@exept.de>
parents: 645
diff changeset
  2240
ProcessorScheduler initialize!