mutex optimisation - #ifTrue:ifFalse versus #ifNil:ifNotNil:

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

mutex optimisation - #ifTrue:ifFalse versus #ifNil:ifNotNil:

Ben Coman
The Mutex primitives return a tri-state value: true, false and nil.

So we would have...

  NewMutex>>critical: mutuallyExcludedBlock ifLocked: alternativeBlock
    ^lock tryAcquire
        ifNil: mutuallyExcludedBlock
        ifNotNil: [:acquired|
            acquired
                ifTrue: [mutuallyExcludedBlock ensure: [lock strictRelease]]
                ifFalse: alternativeBlock ].


  NewMutex>>critical: mutuallyExcludedBlock
    ^lock waitAcquire
        ifNil: mutuallyExcludedBlock
        ifNotNil:[ mutuallyExcludedBlock ensure: [lock strictRelease] ].


So we would have
  NewMutex>>critical: aBlock ifLocked: lockedBlock
    ^lock tryAcquire
        ifNil: mutuallyExcludedBlock
        ifNotNil: [:acquired |
            acquired
                ifTrue: [mutuallyExcludedBlock ensure: [lock strictRelease]]
                ifFalse: alternativeBlock ].


    Mutex>>critical: aBlock ifLocked: lockedBlock
^self primitiveTestAndSetOwnershipOfCriticalSection
ifNil: [lockedBlock value]
ifNotNil:[:alreadyOwner|
alreadyOwner
ifTrue: [aBlock value]
ifFalse: [aBlock ensure: [self primitiveExitCriticalSection]]]

 ifNil:ifNotNil:


Also, I notice several of RBMessageNode>>isInlineXXXX methods contain...
    self receiver isBlock ifTrue: [^ false].
Does this mean that...
   [ true ] ifTrue: [2] ifFalse: [3]
is not inlined?