.
"
COPYRIGHT (c) 1995 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.
"
'From Smalltalk/X, Version:2.10.5 on 28-apr-1995 at 12:37:45 pm'!
Object subclass:#RecursionLock
instanceVariableNames:'process sema'
classVariableNames:''
poolDictionaries:''
category:'Kernel-Processes'
!
!RecursionLock class methodsFor:'documentation'!
documentation
"
like a Semaphore for mutual exclusion, but avoids the deadlock
if a critical region is reentered by the same process again.
example:
|lock|
lock := RecursionLock new.
lock critical:[
Transcript showCr:'in lock ...'.
lock critical:[
Transcript showCr:'again ...'
]
]
"
!
copyright
"
COPYRIGHT (c) 1995 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.
"
!
version
"
$Header: /cvs/stx/stx/libbasic/RecursionLock.st,v 1.1 1995-05-01 23:03:08 claus Exp $
"
! !
!RecursionLock class methodsFor:'instance creation'!
new
^ self basicNew initialize
! !
!RecursionLock methodsFor:'wait & signal'!
critical:aBlock
"evaluate aBlock as a critical region, but do not block,
if this lock is already held by the current process."
|active|
active := Processor activeProcess.
process == active ifTrue:[
aBlock value
] ifFalse:[
process := active.
[
sema critical:aBlock
] valueNowOrOnUnwindDo:[
process := nil
]
].
! !
!RecursionLock methodsFor:'private initialization'!
initialize
sema := Semaphore forMutualExclusion
! !