From d6b8491a3d7086176eabc2680c99df3f21f86590 Mon Sep 17 00:00:00 2001 From: Kresten Krab Thorup Date: Mon, 30 Apr 2012 19:27:13 +0200 Subject: [PATCH] Make step code more explicit This change has no semantic effect, only makes the code easier to read --- src/hanoi_level.erl | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/hanoi_level.erl b/src/hanoi_level.erl index cf6f987..8f2a8c6 100644 --- a/src/hanoi_level.erl +++ b/src/hanoi_level.erl @@ -577,18 +577,23 @@ do_step(StepFrom, HowMuch, State) -> DelegateRef = plain_rpc:send_call(Next, {step, DelegateWork}) end, - if (State#state.merge_pid == undefined) - orelse (WorkToDoHere =< 0) -> - MergeRef = undefined; - true -> + if WorkToDoHere > 0 -> MergePID = State#state.merge_pid, MergeRef = monitor(process, MergePID), - MergePID ! {step, {self(), MergeRef}, WorkToDoHere} + MergePID ! {step, {self(), MergeRef}, WorkToDoHere}; + true -> + MergeRef = undefined end, - if (Next =:= undefined) andalso (MergeRef =:= undefined) -> + if (DelegateRef =:= undefined) andalso (MergeRef =:= undefined) -> %% nothing to do ... just return OK + if (DelegateWork > 0) -> + ?log("undone work: ~p", [DelegateWork]); + true -> + ok + end, + State2 = reply_step_ok(State#state { step_caller = StepFrom }), main_loop(State2); true ->