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