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