home
/
code
/
cellular-automata.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
29199e7
)
Why request when I can just broadcast?
author
Siraaj Khandkar
<siraaj@khandkar.net>
Fri, 27 Jul 2012 03:08:24 +0000
(23:08 -0400)
committer
Siraaj Khandkar
<siraaj@khandkar.net>
Fri, 27 Jul 2012 03:14:48 +0000
(23:14 -0400)
001/src/life_cell.erl
patch
|
blob
|
blame
|
history
diff --git
a/001/src/life_cell.erl
b/001/src/life_cell.erl
index
4771064
..
ada70e6
100644
(file)
--- a/
001/src/life_cell.erl
+++ b/
001/src/life_cell.erl
@@
-66,36
+66,27
@@
handle_call(_Msg, _From, State) ->
handle_cast({next_gen, GenID},
handle_cast({next_gen, GenID},
- #state{
name=Nam
e
+ #state{
cell_state=CellStat
e
,neighbors=Neighbors
,num_neighbors=NumNeighbors
}=State) ->
,neighbors=Neighbors
,num_neighbors=NumNeighbors
}=State) ->
- ok = cast_all(Neighbors, {
request_state, GenID, Nam
e}),
+ ok = cast_all(Neighbors, {
state_broadcast, GenID, CellStat
e}),
{noreply, State#state{replies_pending=NumNeighbors, gen_id=GenID}};
{noreply, State#state{replies_pending=NumNeighbors, gen_id=GenID}};
-%% If we receive this before we receive next_gen, throw it back in the queue.
-%% (Took me a while to realize this, but sometimes it is possible. The more
-%% there're cells, the more likely this is to happen.)
-handle_cast({request_state, GenID, _Requester}=Msg,
- #state{gen_id=MyGenID
- ,name=Name
- }=State) when GenID =/= MyGenID->
+%% If we receive 'state_broadcast' before we receive 'next_gen', throw it back
+%% in the queue. (Took me a while to realize this, but sometimes it is
+%% possible. The more there're cells, the more likely this is to happen.)
+handle_cast({state_broadcast, ReceivedGenID, _NeighborState}=Msg,
+ #state{gen_id=GenID, name=Name}=State) when GenID =/= ReceivedGenID->
gen_server:cast(Name, Msg),
{noreply, State};
gen_server:cast(Name, Msg),
{noreply, State};
+
%% Now that we can be sure that this request is for the current generation, we
%% can handle it
%% Now that we can be sure that this request is for the current generation, we
%% can handle it
-handle_cast({request_state, GenID, Requester},
- #state{gen_id=MyGenID
- ,cell_state=CellState
- }=State) when GenID =:= MyGenID->
-
- ok = gen_server:cast(Requester, {response_state, MyGenID, CellState}),
- {noreply, State};
-
-handle_cast({response_state, GenID, NeighborState},
+handle_cast({state_broadcast, GenID, NeighborState},
#state{cell_id=CellID
,gen_id=GenID
,replies_pending=Pending
#state{cell_id=CellID
,gen_id=GenID
,replies_pending=Pending
@@
-124,6
+115,7
@@
handle_cast({response_state, GenID, NeighborState},
{noreply, NewState}
end;
{noreply, NewState}
end;
+
handle_cast(_Msg, State) ->
{noreply, State}.
handle_cast(_Msg, State) ->
{noreply, State}.
This page took
0.028427 seconds
and
4
git commands to generate.