"
COPYRIGHT (c) 1992 by Claus Gittinger
All Rights Reserved
This software is furnished under a license and may be used
only in accordance with the terms of that license and with the
inclusion of the above copyright notice. This software may not
be provided or otherwise made available to, or used by, any
other person. No title to or ownership of the software is
hereby transferred.
"
Link subclass:#Process
instanceVariableNames:'id prio state startBlock name
pushedInterruptActions exitAction'
classVariableNames:''
poolDictionaries:''
category:'Kernel-Processes'
!
Process comment:'
COPYRIGHT (c) 1992 by Claus Gittinger
All Rights Reserved
$Header: /cvs/stx/stx/libbasic/Process.st,v 1.8 1993-12-19 23:40:21 claus Exp $
'!
!Process methodsFor:'accessing'!
state
"return a symbol describing the processes state"
^ state
!
state:aSymbol
"set the state - only to be used from scheduler"
state := aSymbol
!
startBlock:aBlock
startBlock := aBlock
!
priority
"return the receivers priority"
^ prio
!
priority:aNumber
"set my priority"
Processor changePriority:aNumber for:self
!
setPriority:aNumber
"set priority without telling processor - no public use"
prio := aNumber
!
id
"return the processes id"
^ id
!
name
"return the processes name"
^ name
!
name:aString
"set the processes name"
name := aString
!
nameOrId
"return a string to identify the process - either name or id"
name notNil ifTrue:[^ name].
^ id printString
!
exitAction
"return the processes exit action"
^ exitAction
!
exitAction:aBlock
"set the processes exit action"
exitAction := aBlock
!
suspendedContext
"return the processes suspended context"
%{ /* NOCONTEXT */
extern OBJ __threadContext();
if (_isSmallInteger(_INST(id))) {
RETURN (__threadContext(_intVal(_INST(id))));
}
%}
.
^ nil
!
usedStackSize
"for monitoring only: return the processes current stack size.
This method is for monitoring purposes only."
%{ /* NOCONTEXT */
extern __threadUsedStackSize();
if (_isSmallInteger(_INST(id))) {
RETURN( _MKSMALLINT(__threadUsedStackSize(_intVal(_INST(id)))) );
}
%}
.
^ nil
!
totalStackSize
"return the processes maximum used so far stack size.
This method is for monitoring purposes only."
%{ /* NOCONTEXT */
extern __threadTotalStackSize();
if (_isSmallInteger(_INST(id))) {
RETURN( _MKSMALLINT(__threadTotalStackSize(_intVal(_INST(id)))) );
}
%}
.
^ nil
! !
!Process methodsFor:'private scheduler access'!
setId:aNumber
"set the processes id"
id := aNumber
! !
!Process methodsFor:'suspend / resume'!
suspend
"suspend the receiver process - will continue to run when a resume is sent"
Processor suspend:self
!
resume
"resume the receiver process"
Processor resume:self
!
terminate
"terminate the receiver process"
Processor terminate:self
! !
!Process methodsFor:'special'!
interruptWith:aBlock
"interrupt the receiver and make it evaluate aBlock.
If the receiver is currently suspended, the block will be remembered
to be evaluated once the receiver wakes up"
OperatingSystem blockInterrupts.
pushedInterruptActions isNil ifTrue:[
pushedInterruptActions := OrderedCollection with:aBlock.
Processor scheduleForInterrupt:self
] ifFalse:[
pushedInterruptActions addLast:aBlock.
].
OperatingSystem unblockInterrupts.
! !
!Process methodsFor:'printing'!
printString
^ 'a ' , state , ' Process (' , self nameOrId , ')'
! !