/* ----------------------------------------------------------------------------- Copyright 2021-2023 Kevin P. Barry Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ----------------------------------------------------------------------------- */ // Author: Kevin P. Barry [ta0kira@gmail.com] define Routines { @category optional StateTransition dropWeak <- Run:ifElse( test: DecrWeakIsZero.new(), doIf: FreeRef.new(), doElse: empty) @category optional StateTransition sharedThenDrop <- LockRef.new() `Run:then` Run:ifElse( test: IncrRefIsOne.new(), doIf: DecrRef.new() `Run:then` UnlockRef.new() `Run:then` dropWeak, doElse: UnlockRef.new() `Run:then` dropWeak `Run:then` dropShared) @category optional StateTransition dropShared <- LockRef.new() `Run:then` Run:ifElse( test: DecrRefIsZero.new(), doIf: FreeObject.new() `Run:then` UnlockRef.new() `Run:then` dropWeak, doElse: UnlockRef.new()) @category optional StateTransition sharedThenDropBroken <- Run:ifElse( test: PlusLockModLockZero.new(), doIf: MinusLock.new() `Run:then` dropWeak, doElse: MinusLockPlusOne.new() `Run:then` dropWeak `Run:then` dropSharedBroken) @category optional StateTransition dropSharedBroken <- Run:ifElse( test: DecrRefIsZero.new(), doIf: FreeObject.new() `Run:then` dropWeak, doElse: empty) newShared (name, state) { if (state.addStrong() == 1) { \ state.addWeak() } return LabeledStateMachine:new(name, state, dropShared) } newWeak (name, state) { \ state.addWeak() return LabeledStateMachine:new(name, state, sharedThenDrop) } newSharedBroken (name, state) { if (state.addStrong() == 1) { \ state.addWeak() } return LabeledStateMachine:new(name, state, dropSharedBroken) } newWeakBroken (name, state) { \ state.addWeak() return LabeledStateMachine:new(name, state, sharedThenDropBroken) } }