use alloc::sync::Arc;
use core::ops::ControlFlow;
use crate::{
BreakReason, Host, Stopper,
continuation_stack::Continuation,
execution::{ExecutionState, finalize_clock_cycle, finalize_clock_cycle_with_continuation},
mast::{JoinNode, MastForest, MastNodeId},
processor::Processor,
tracer::Tracer,
};
#[inline(always)]
pub(super) fn start_join_node<P, H, S, T>(
state: &mut ExecutionState<'_, P, H, S, T>,
join_node: &JoinNode,
node_id: MastNodeId,
current_forest: &Arc<MastForest>,
) -> ControlFlow<BreakReason>
where
P: Processor,
H: Host,
S: Stopper<Processor = P>,
T: Tracer<Processor = P>,
{
state.tracer.start_clock_cycle(
state.processor,
Continuation::StartNode(node_id),
state.continuation_stack,
current_forest,
);
state
.processor
.execute_before_enter_decorators(node_id, current_forest, state.host)?;
state.continuation_stack.push_finish_join(node_id);
state.continuation_stack.push_start_node(join_node.second());
state.continuation_stack.push_start_node(join_node.first());
finalize_clock_cycle(
state.processor,
state.tracer,
state.stopper,
state.continuation_stack,
current_forest,
)
}
#[inline(always)]
pub(super) fn finish_join_node<P, H, S, T>(
state: &mut ExecutionState<'_, P, H, S, T>,
node_id: MastNodeId,
current_forest: &Arc<MastForest>,
) -> ControlFlow<BreakReason>
where
P: Processor,
H: Host,
S: Stopper<Processor = P>,
T: Tracer<Processor = P>,
{
state.tracer.start_clock_cycle(
state.processor,
Continuation::FinishJoin(node_id),
state.continuation_stack,
current_forest,
);
finalize_clock_cycle_with_continuation(
state.processor,
state.tracer,
state.stopper,
state.continuation_stack,
|| Some(Continuation::AfterExitDecorators(node_id)),
current_forest,
)?;
state
.processor
.execute_after_exit_decorators(node_id, current_forest, state.host)
}