summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Radestock <matthias@rabbitmq.com>2014-04-21 11:56:22 +0100
committerMatthias Radestock <matthias@rabbitmq.com>2014-04-21 11:56:22 +0100
commitb0f878f82811dc0236ee4b85ae5790c2e78b95da (patch)
treed34aac2ede5c36d43ad21baab012f1fc4fb86b73
parentd564c0b221def8caa7c681e63730b00c33f22375 (diff)
downloadrabbitmq-server-b0f878f82811dc0236ee4b85ae5790c2e78b95da.tar.gz
refactor: simplify gm:internal_broadcast
eliminate branching
-rw-r--r--src/gm.erl31
1 files changed, 12 insertions, 19 deletions
diff --git a/src/gm.erl b/src/gm.erl
index 9a51bfc2..1eaf7459 100644
--- a/src/gm.erl
+++ b/src/gm.erl
@@ -581,7 +581,11 @@ handle_call({confirmed_broadcast, Msg}, _From,
ok, State});
handle_call({confirmed_broadcast, Msg}, From, State) ->
- internal_broadcast(Msg, From, 0, State);
+ {Result, State1 = #state { pub_count = PubCount, confirms = Confirms }} =
+ internal_broadcast(Msg, 0, State),
+ Confirms1 = queue:in({PubCount, From}, Confirms),
+ handle_callback_result({Result, flush_broadcast_buffer(
+ State1 #state { confirms = Confirms1 })});
handle_call(info, _From,
State = #state { members_state = undefined }) ->
@@ -657,7 +661,8 @@ handle_cast({broadcast, Msg, _SizeHint},
State});
handle_cast({broadcast, Msg, SizeHint}, State) ->
- internal_broadcast(Msg, none, SizeHint, State);
+ {Result, State1} = internal_broadcast(Msg, SizeHint, State),
+ handle_callback_result({Result, maybe_flush_broadcast_buffer(State1)});
handle_cast(join, State = #state { self = Self,
group_name = GroupName,
@@ -876,30 +881,18 @@ ensure_broadcast_timer(State = #state { broadcast_timer = undefined }) ->
ensure_broadcast_timer(State) ->
State.
-internal_broadcast(Msg, From, SizeHint,
+internal_broadcast(Msg, SizeHint,
State = #state { self = Self,
pub_count = PubCount,
module = Module,
- confirms = Confirms,
callback_args = Args,
broadcast_buffer = Buffer,
broadcast_buffer_sz = BufferSize }) ->
PubCount1 = PubCount + 1,
- Result = Module:handle_msg(Args, get_pid(Self), Msg),
- Buffer1 = [{PubCount1, Msg} | Buffer],
- Confirms1 = case From of
- none -> Confirms;
- _ -> queue:in({PubCount1, From}, Confirms)
- end,
- State1 = State #state { pub_count = PubCount1,
- confirms = Confirms1,
- broadcast_buffer = Buffer1,
- broadcast_buffer_sz = BufferSize + SizeHint},
- handle_callback_result(
- {Result, case From of
- none -> maybe_flush_broadcast_buffer(State1);
- _ -> flush_broadcast_buffer(State1)
- end}).
+ {Module:handle_msg(Args, get_pid(Self), Msg),
+ State #state { pub_count = PubCount1,
+ broadcast_buffer = [{PubCount1, Msg} | Buffer],
+ broadcast_buffer_sz = BufferSize + SizeHint}}.
%% The Erlang distribution mechanism has an interesting quirk - it
%% will kill the VM cold with "Absurdly large distribution output data