Statechart Implementation : Optimization Algorithms : Timeout Optimization

Timeout Optimization

The Code Generator performs optimization of data allocated for timeouts. Data allocated for a timeout is reused for another timeout if these timeouts trigger transitions outgoing from exclusive states.

Note: Use the menu selections Options->Settings->Optimization ->Reuse Timeout Variable to set that optimization.

Note the following:

The optimization reuses the same Timeout/Delay variable for other timeouts/delays.

To reduce the number of data allocations for the timeout operation, the algorithm has been changed. The description of the algorithm uses the following terms:

Source state of a timeout— The source state of the transition that the timeout is on, or the state in which its static reaction contains the timeout.
Clutch a timeout— Add the clutched timeout to the list of timeouts for the timeout that represents the data allocation. Tagging the clutched timeout as NOT requires data allocation. In the clutched timeout, the Code Generator keeps a reference to the timeout that represents its data allocation.
Parent— State 1 (S1) is a parent of state 2 (S2) if S1 is an ancestor of S2.

The algorithm merges data allocation for two timeouts if their sources are mutually exclusive. The steps of the algorithm are as follows:

1.
2.
3.

The timeout being tested requires data allocation.

The source state and every timeout in the list are not parents of the source state of the tested timeout, or of any of the source states of the timeouts in the list.

The source state of the tested timeouts and the source state of every timeout in its list are not parents of the source state, or the source state of any timeout in the list.

None of the following are an AndState:

If all four conditions are satisfied, the tested timeout is clutched. The following code sample represents the algorithm:

LIST TimeoutsList = CREATE TimeoutsList.
FOR EACH Timeout (TM) in (TimeoutList) DO
{
State TMSourceState = FIND SOURCE STATE OF (State).
LIST SiblingsStatesList = CREATE SIBLINGS LIST OF (TMSourceState)
FOR EACH State (S) in (SiblingsStatesList) DO
{
LIST CurrSiblingTimeoutsLists = CREATE LIST OF TIMEOUTS UNDER (S)
FOR EACH Timeout (T1) in (CurrSiblingTimeoutsLists) DO
{
if (T1) NOT (Requires Data Allocation) then EXIT FOR LOOP
State SiblingTimeoutSourceState = FIND SOURCE STATE OF (T1)
LIST MySourceStatesList = CREATE LIST OF SOURCE STATES OF
(TMSourceState AND ALL THE TIMEOUTS IN ITS LIST)
FOR EACH (S1) in (MySourceStatesList) DO
{
if (S1) IS PARENT OF (SiblingTimeoutSourceState) OR
(SiblingTimeoutSourceState) IS PARENT OF (S1) then EXIT FOR LOOP
State FirstCommonParentState = FIND FIRST COMMON PARENT OF
(S1, SiblingTimeoutSourceState)
if (FirstCommonParentState) IS AND-STATE then EXIT FOR LOOP
CLUTCH TIMEOUT (T1) TO TIMEOUT (TM).Statechart Implementation
}
}
}
}
 
 

After the algorithm has finished, each timeout is marked with one of the following tags: