Permalink
Browse files

Fixes a race condition in which slots is called before the module is …

…started
  • Loading branch information...
1 parent 7f87335 commit e5d2384ed8dad8d46a8d84b89fbf3ddefdc086aa @mmzeeman mmzeeman committed Apr 5, 2012
Showing with 15 additions and 12 deletions.
  1. +15 −12 modules/mod_signal/mod_signal.erl
View
27 modules/mod_signal/mod_signal.erl
@@ -107,20 +107,23 @@ slots(Signal, Context) ->
Table = slot_table_name(Context),
SignalType = signal_type(Signal),
- % collect the tags
- Tags = ets:lookup(Table, SignalType),
-
- % Get the list of keys we have to
- Keys = [key(Signal, Tag) || {tags, _S, Tag} <- Tags],
+ case ets:info(Table, size) of
+ undefined -> []; %% No table, no slots.
+ _ ->
+ Tags = ets:lookup(Table, SignalType),
- slots1([], Table, Keys).
+ % Get the list of keys we have to
+ Keys = [key(Signal, Tag) || {tags, _S, Tag} <- Tags],
+
+ slots1([], Table, Keys)
+ end.
- slots1(Slots, _Table, []) ->
- [Slot || {slot, _K, Slot} <- lists:flatten(Slots)];
- slots1(Slots, Table, [undefined|T]) ->
- slots1(Slots, Table, T);
- slots1(Slots, Table, [H|T]) ->
- slots1([ets:lookup(Table, H) | Slots], Table, T).
+slots1(Slots, _Table, []) ->
+ [Slot || {slot, _K, Slot} <- lists:flatten(Slots)];
+slots1(Slots, Table, [undefined|T]) ->
+ slots1(Slots, Table, T);
+slots1(Slots, Table, [H|T]) ->
+ slots1([ets:lookup(Table, H) | Slots], Table, T).
% @doc Return how many items there
%

0 comments on commit e5d2384

Please sign in to comment.